@@ -2,7 +2,7 @@ import {HarnessLoader} from '@angular/cdk/testing';
2
2
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed' ;
3
3
import { Component } from '@angular/core' ;
4
4
import { ComponentFixture , TestBed } from '@angular/core/testing' ;
5
- import { ReactiveFormsModule } from '@angular/forms' ;
5
+ import { FormsModule } from '@angular/forms' ;
6
6
import { MatInputModule } from '@angular/material/input' ;
7
7
import { getSupportedInputTypes } from '@angular/cdk/platform' ;
8
8
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
@@ -17,7 +17,7 @@ export function runHarnessTests(
17
17
beforeEach ( async ( ) => {
18
18
await TestBed
19
19
. configureTestingModule ( {
20
- imports : [ NoopAnimationsModule , inputModule , ReactiveFormsModule ] ,
20
+ imports : [ NoopAnimationsModule , inputModule , FormsModule ] ,
21
21
declarations : [ InputHarnessTest ] ,
22
22
} )
23
23
. compileComponents ( ) ;
@@ -29,7 +29,7 @@ export function runHarnessTests(
29
29
30
30
it ( 'should load all input harnesses' , async ( ) => {
31
31
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
32
- expect ( inputs . length ) . toBe ( 6 ) ;
32
+ expect ( inputs . length ) . toBe ( 7 ) ;
33
33
} ) ;
34
34
35
35
it ( 'should load input with specific id' , async ( ) => {
@@ -50,37 +50,40 @@ export function runHarnessTests(
50
50
51
51
it ( 'should be able to get id of input' , async ( ) => {
52
52
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
53
- expect ( inputs . length ) . toBe ( 6 ) ;
53
+ expect ( inputs . length ) . toBe ( 7 ) ;
54
54
expect ( await inputs [ 0 ] . getId ( ) ) . toMatch ( / m a t - i n p u t - \d + / ) ;
55
55
expect ( await inputs [ 1 ] . getId ( ) ) . toMatch ( / m a t - i n p u t - \d + / ) ;
56
56
expect ( await inputs [ 2 ] . getId ( ) ) . toBe ( 'myTextarea' ) ;
57
57
expect ( await inputs [ 3 ] . getId ( ) ) . toBe ( 'nativeControl' ) ;
58
58
expect ( await inputs [ 4 ] . getId ( ) ) . toMatch ( / m a t - i n p u t - \d + / ) ;
59
+ expect ( await inputs [ 5 ] . getId ( ) ) . toBe ( 'has-ng-model' ) ;
59
60
} ) ;
60
61
61
62
it ( 'should be able to get name of input' , async ( ) => {
62
63
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
63
- expect ( inputs . length ) . toBe ( 6 ) ;
64
+ expect ( inputs . length ) . toBe ( 7 ) ;
64
65
expect ( await inputs [ 0 ] . getName ( ) ) . toBe ( 'favorite-food' ) ;
65
66
expect ( await inputs [ 1 ] . getName ( ) ) . toBe ( '' ) ;
66
67
expect ( await inputs [ 2 ] . getName ( ) ) . toBe ( '' ) ;
67
68
expect ( await inputs [ 3 ] . getName ( ) ) . toBe ( '' ) ;
68
69
expect ( await inputs [ 4 ] . getName ( ) ) . toBe ( '' ) ;
70
+ expect ( await inputs [ 5 ] . getName ( ) ) . toBe ( 'has-ng-model' ) ;
69
71
} ) ;
70
72
71
73
it ( 'should be able to get value of input' , async ( ) => {
72
74
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
73
- expect ( inputs . length ) . toBe ( 6 ) ;
75
+ expect ( inputs . length ) . toBe ( 7 ) ;
74
76
expect ( await inputs [ 0 ] . getValue ( ) ) . toBe ( 'Sushi' ) ;
75
77
expect ( await inputs [ 1 ] . getValue ( ) ) . toBe ( '' ) ;
76
78
expect ( await inputs [ 2 ] . getValue ( ) ) . toBe ( '' ) ;
77
79
expect ( await inputs [ 3 ] . getValue ( ) ) . toBe ( '' ) ;
78
80
expect ( await inputs [ 4 ] . getValue ( ) ) . toBe ( '' ) ;
81
+ expect ( await inputs [ 5 ] . getValue ( ) ) . toBe ( '' ) ;
79
82
} ) ;
80
83
81
84
it ( 'should be able to set value of input' , async ( ) => {
82
85
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
83
- expect ( inputs . length ) . toBe ( 6 ) ;
86
+ expect ( inputs . length ) . toBe ( 7 ) ;
84
87
expect ( await inputs [ 0 ] . getValue ( ) ) . toBe ( 'Sushi' ) ;
85
88
expect ( await inputs [ 1 ] . getValue ( ) ) . toBe ( '' ) ;
86
89
expect ( await inputs [ 3 ] . getValue ( ) ) . toBe ( '' ) ;
@@ -99,13 +102,14 @@ export function runHarnessTests(
99
102
100
103
it ( 'should be able to get disabled state' , async ( ) => {
101
104
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
102
- expect ( inputs . length ) . toBe ( 6 ) ;
105
+ expect ( inputs . length ) . toBe ( 7 ) ;
103
106
104
107
expect ( await inputs [ 0 ] . isDisabled ( ) ) . toBe ( false ) ;
105
108
expect ( await inputs [ 1 ] . isDisabled ( ) ) . toBe ( false ) ;
106
109
expect ( await inputs [ 2 ] . isDisabled ( ) ) . toBe ( false ) ;
107
110
expect ( await inputs [ 3 ] . isDisabled ( ) ) . toBe ( false ) ;
108
111
expect ( await inputs [ 4 ] . isDisabled ( ) ) . toBe ( false ) ;
112
+ expect ( await inputs [ 5 ] . isDisabled ( ) ) . toBe ( false ) ;
109
113
110
114
fixture . componentInstance . disabled = true ;
111
115
@@ -114,13 +118,14 @@ export function runHarnessTests(
114
118
115
119
it ( 'should be able to get readonly state' , async ( ) => {
116
120
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
117
- expect ( inputs . length ) . toBe ( 6 ) ;
121
+ expect ( inputs . length ) . toBe ( 7 ) ;
118
122
119
123
expect ( await inputs [ 0 ] . isReadonly ( ) ) . toBe ( false ) ;
120
124
expect ( await inputs [ 1 ] . isReadonly ( ) ) . toBe ( false ) ;
121
125
expect ( await inputs [ 2 ] . isReadonly ( ) ) . toBe ( false ) ;
122
126
expect ( await inputs [ 3 ] . isReadonly ( ) ) . toBe ( false ) ;
123
127
expect ( await inputs [ 4 ] . isReadonly ( ) ) . toBe ( false ) ;
128
+ expect ( await inputs [ 5 ] . isReadonly ( ) ) . toBe ( false ) ;
124
129
125
130
fixture . componentInstance . readonly = true ;
126
131
@@ -129,13 +134,14 @@ export function runHarnessTests(
129
134
130
135
it ( 'should be able to get required state' , async ( ) => {
131
136
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
132
- expect ( inputs . length ) . toBe ( 6 ) ;
137
+ expect ( inputs . length ) . toBe ( 7 ) ;
133
138
134
139
expect ( await inputs [ 0 ] . isRequired ( ) ) . toBe ( false ) ;
135
140
expect ( await inputs [ 1 ] . isRequired ( ) ) . toBe ( false ) ;
136
141
expect ( await inputs [ 2 ] . isRequired ( ) ) . toBe ( false ) ;
137
142
expect ( await inputs [ 3 ] . isRequired ( ) ) . toBe ( false ) ;
138
143
expect ( await inputs [ 4 ] . isRequired ( ) ) . toBe ( false ) ;
144
+ expect ( await inputs [ 5 ] . isRequired ( ) ) . toBe ( false ) ;
139
145
140
146
fixture . componentInstance . required = true ;
141
147
@@ -144,22 +150,24 @@ export function runHarnessTests(
144
150
145
151
it ( 'should be able to get placeholder of input' , async ( ) => {
146
152
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
147
- expect ( inputs . length ) . toBe ( 6 ) ;
153
+ expect ( inputs . length ) . toBe ( 7 ) ;
148
154
expect ( await inputs [ 0 ] . getPlaceholder ( ) ) . toBe ( 'Favorite food' ) ;
149
155
expect ( await inputs [ 1 ] . getPlaceholder ( ) ) . toBe ( '' ) ;
150
156
expect ( await inputs [ 2 ] . getPlaceholder ( ) ) . toBe ( 'Leave a comment' ) ;
151
157
expect ( await inputs [ 3 ] . getPlaceholder ( ) ) . toBe ( 'Native control' ) ;
152
158
expect ( await inputs [ 4 ] . getPlaceholder ( ) ) . toBe ( '' ) ;
159
+ expect ( await inputs [ 5 ] . getPlaceholder ( ) ) . toBe ( '' ) ;
153
160
} ) ;
154
161
155
162
it ( 'should be able to get type of input' , async ( ) => {
156
163
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
157
- expect ( inputs . length ) . toBe ( 6 ) ;
164
+ expect ( inputs . length ) . toBe ( 7 ) ;
158
165
expect ( await inputs [ 0 ] . getType ( ) ) . toBe ( 'text' ) ;
159
166
expect ( await inputs [ 1 ] . getType ( ) ) . toBe ( 'number' ) ;
160
167
expect ( await inputs [ 2 ] . getType ( ) ) . toBe ( 'textarea' ) ;
161
168
expect ( await inputs [ 3 ] . getType ( ) ) . toBe ( 'text' ) ;
162
169
expect ( await inputs [ 4 ] . getType ( ) ) . toBe ( 'textarea' ) ;
170
+ expect ( await inputs [ 5 ] . getType ( ) ) . toBe ( 'text' ) ;
163
171
164
172
fixture . componentInstance . inputType = 'text' ;
165
173
@@ -234,6 +242,10 @@ function getActiveElementTagName() {
234
242
</select>
235
243
</mat-form-field>
236
244
245
+ <mat-form-field>
246
+ <input [(ngModel)]="ngModelValue" [name]="ngModelName" id="has-ng-model" matNativeControl>
247
+ </mat-form-field>
248
+
237
249
<mat-form-field>
238
250
<input matNativeControl placeholder="Color control" id="colorControl" type="color">
239
251
</mat-form-field>
@@ -244,4 +256,6 @@ class InputHarnessTest {
244
256
readonly = false ;
245
257
disabled = false ;
246
258
required = false ;
259
+ ngModelValue = '' ;
260
+ ngModelName = 'has-ng-model' ;
247
261
}
0 commit comments