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