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