@@ -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' ;
@@ -18,7 +18,7 @@ export function runInputHarnessTests(
18
18
19
19
beforeEach ( async ( ) => {
20
20
await TestBed . configureTestingModule ( {
21
- imports : [ NoopAnimationsModule , inputModule , ReactiveFormsModule ] ,
21
+ imports : [ NoopAnimationsModule , inputModule , FormsModule ] ,
22
22
declarations : [ InputHarnessTest ] ,
23
23
} ) . compileComponents ( ) ;
24
24
@@ -29,7 +29,7 @@ export function runInputHarnessTests(
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 ( ) => {
@@ -68,37 +68,40 @@ export function runInputHarnessTests(
68
68
69
69
it ( 'should be able to get id of input' , async ( ) => {
70
70
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
71
- expect ( inputs . length ) . toBe ( 6 ) ;
71
+ expect ( inputs . length ) . toBe ( 7 ) ;
72
72
expect ( await inputs [ 0 ] . getId ( ) ) . toMatch ( / m a t - i n p u t - \d + / ) ;
73
73
expect ( await inputs [ 1 ] . getId ( ) ) . toMatch ( / m a t - i n p u t - \d + / ) ;
74
74
expect ( await inputs [ 2 ] . getId ( ) ) . toBe ( 'myTextarea' ) ;
75
75
expect ( await inputs [ 3 ] . getId ( ) ) . toBe ( 'nativeControl' ) ;
76
76
expect ( await inputs [ 4 ] . getId ( ) ) . toMatch ( / m a t - i n p u t - \d + / ) ;
77
+ expect ( await inputs [ 5 ] . getId ( ) ) . toBe ( 'has-ng-model' ) ;
77
78
} ) ;
78
79
79
80
it ( 'should be able to get name of input' , async ( ) => {
80
81
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
81
- expect ( inputs . length ) . toBe ( 6 ) ;
82
+ expect ( inputs . length ) . toBe ( 7 ) ;
82
83
expect ( await inputs [ 0 ] . getName ( ) ) . toBe ( 'favorite-food' ) ;
83
84
expect ( await inputs [ 1 ] . getName ( ) ) . toBe ( '' ) ;
84
85
expect ( await inputs [ 2 ] . getName ( ) ) . toBe ( '' ) ;
85
86
expect ( await inputs [ 3 ] . getName ( ) ) . toBe ( '' ) ;
86
87
expect ( await inputs [ 4 ] . getName ( ) ) . toBe ( '' ) ;
88
+ expect ( await inputs [ 5 ] . getName ( ) ) . toBe ( 'has-ng-model' ) ;
87
89
} ) ;
88
90
89
91
it ( 'should be able to get value of input' , async ( ) => {
90
92
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
91
- expect ( inputs . length ) . toBe ( 6 ) ;
93
+ expect ( inputs . length ) . toBe ( 7 ) ;
92
94
expect ( await inputs [ 0 ] . getValue ( ) ) . toBe ( 'Sushi' ) ;
93
95
expect ( await inputs [ 1 ] . getValue ( ) ) . toBe ( '' ) ;
94
96
expect ( await inputs [ 2 ] . getValue ( ) ) . toBe ( '' ) ;
95
97
expect ( await inputs [ 3 ] . getValue ( ) ) . toBe ( '' ) ;
96
98
expect ( await inputs [ 4 ] . getValue ( ) ) . toBe ( '' ) ;
99
+ expect ( await inputs [ 5 ] . getValue ( ) ) . toBe ( '' ) ;
97
100
} ) ;
98
101
99
102
it ( 'should be able to set value of input' , async ( ) => {
100
103
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
101
- expect ( inputs . length ) . toBe ( 6 ) ;
104
+ expect ( inputs . length ) . toBe ( 7 ) ;
102
105
expect ( await inputs [ 0 ] . getValue ( ) ) . toBe ( 'Sushi' ) ;
103
106
expect ( await inputs [ 1 ] . getValue ( ) ) . toBe ( '' ) ;
104
107
expect ( await inputs [ 3 ] . getValue ( ) ) . toBe ( '' ) ;
@@ -117,13 +120,14 @@ export function runInputHarnessTests(
117
120
118
121
it ( 'should be able to get disabled state' , async ( ) => {
119
122
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
120
- expect ( inputs . length ) . toBe ( 6 ) ;
123
+ expect ( inputs . length ) . toBe ( 7 ) ;
121
124
122
125
expect ( await inputs [ 0 ] . isDisabled ( ) ) . toBe ( false ) ;
123
126
expect ( await inputs [ 1 ] . isDisabled ( ) ) . toBe ( false ) ;
124
127
expect ( await inputs [ 2 ] . isDisabled ( ) ) . toBe ( false ) ;
125
128
expect ( await inputs [ 3 ] . isDisabled ( ) ) . toBe ( false ) ;
126
129
expect ( await inputs [ 4 ] . isDisabled ( ) ) . toBe ( false ) ;
130
+ expect ( await inputs [ 5 ] . isDisabled ( ) ) . toBe ( false ) ;
127
131
128
132
fixture . componentInstance . disabled = true ;
129
133
@@ -132,13 +136,14 @@ export function runInputHarnessTests(
132
136
133
137
it ( 'should be able to get readonly state' , async ( ) => {
134
138
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
135
- expect ( inputs . length ) . toBe ( 6 ) ;
139
+ expect ( inputs . length ) . toBe ( 7 ) ;
136
140
137
141
expect ( await inputs [ 0 ] . isReadonly ( ) ) . toBe ( false ) ;
138
142
expect ( await inputs [ 1 ] . isReadonly ( ) ) . toBe ( false ) ;
139
143
expect ( await inputs [ 2 ] . isReadonly ( ) ) . toBe ( false ) ;
140
144
expect ( await inputs [ 3 ] . isReadonly ( ) ) . toBe ( false ) ;
141
145
expect ( await inputs [ 4 ] . isReadonly ( ) ) . toBe ( false ) ;
146
+ expect ( await inputs [ 5 ] . isReadonly ( ) ) . toBe ( false ) ;
142
147
143
148
fixture . componentInstance . readonly = true ;
144
149
@@ -147,13 +152,14 @@ export function runInputHarnessTests(
147
152
148
153
it ( 'should be able to get required state' , async ( ) => {
149
154
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
150
- expect ( inputs . length ) . toBe ( 6 ) ;
155
+ expect ( inputs . length ) . toBe ( 7 ) ;
151
156
152
157
expect ( await inputs [ 0 ] . isRequired ( ) ) . toBe ( false ) ;
153
158
expect ( await inputs [ 1 ] . isRequired ( ) ) . toBe ( false ) ;
154
159
expect ( await inputs [ 2 ] . isRequired ( ) ) . toBe ( false ) ;
155
160
expect ( await inputs [ 3 ] . isRequired ( ) ) . toBe ( false ) ;
156
161
expect ( await inputs [ 4 ] . isRequired ( ) ) . toBe ( false ) ;
162
+ expect ( await inputs [ 5 ] . isRequired ( ) ) . toBe ( false ) ;
157
163
158
164
fixture . componentInstance . required = true ;
159
165
@@ -162,22 +168,24 @@ export function runInputHarnessTests(
162
168
163
169
it ( 'should be able to get placeholder of input' , async ( ) => {
164
170
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
165
- expect ( inputs . length ) . toBe ( 6 ) ;
171
+ expect ( inputs . length ) . toBe ( 7 ) ;
166
172
expect ( await inputs [ 0 ] . getPlaceholder ( ) ) . toBe ( 'Favorite food' ) ;
167
173
expect ( await inputs [ 1 ] . getPlaceholder ( ) ) . toBe ( '' ) ;
168
174
expect ( await inputs [ 2 ] . getPlaceholder ( ) ) . toBe ( 'Leave a comment' ) ;
169
175
expect ( await inputs [ 3 ] . getPlaceholder ( ) ) . toBe ( 'Native control' ) ;
170
176
expect ( await inputs [ 4 ] . getPlaceholder ( ) ) . toBe ( '' ) ;
177
+ expect ( await inputs [ 5 ] . getPlaceholder ( ) ) . toBe ( '' ) ;
171
178
} ) ;
172
179
173
180
it ( 'should be able to get type of input' , async ( ) => {
174
181
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
175
- expect ( inputs . length ) . toBe ( 6 ) ;
182
+ expect ( inputs . length ) . toBe ( 7 ) ;
176
183
expect ( await inputs [ 0 ] . getType ( ) ) . toBe ( 'text' ) ;
177
184
expect ( await inputs [ 1 ] . getType ( ) ) . toBe ( 'number' ) ;
178
185
expect ( await inputs [ 2 ] . getType ( ) ) . toBe ( 'textarea' ) ;
179
186
expect ( await inputs [ 3 ] . getType ( ) ) . toBe ( 'text' ) ;
180
187
expect ( await inputs [ 4 ] . getType ( ) ) . toBe ( 'textarea' ) ;
188
+ expect ( await inputs [ 5 ] . getType ( ) ) . toBe ( 'text' ) ;
181
189
182
190
fixture . componentInstance . inputType = 'text' ;
183
191
@@ -248,6 +256,10 @@ export function runInputHarnessTests(
248
256
</select>
249
257
</mat-form-field>
250
258
259
+ <mat-form-field>
260
+ <input [(ngModel)]="ngModelValue" [name]="ngModelName" id="has-ng-model" matNativeControl>
261
+ </mat-form-field>
262
+
251
263
<mat-form-field>
252
264
<input matNativeControl placeholder="Color control" id="colorControl" type="color">
253
265
</mat-form-field>
@@ -258,4 +270,6 @@ class InputHarnessTest {
258
270
readonly = false ;
259
271
disabled = false ;
260
272
required = false ;
273
+ ngModelValue = '' ;
274
+ ngModelName = 'has-ng-model' ;
261
275
}
0 commit comments