@@ -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 ( 3 ) ;
31
+ expect ( inputs . length ) . toBe ( 5 ) ;
32
32
} ) ;
33
33
34
34
it ( 'should load input with specific id' , async ( ) => {
@@ -49,48 +49,62 @@ 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 ( 3 ) ;
52
+ expect ( inputs . length ) . toBe ( 5 ) ;
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
+ expect ( await inputs [ 3 ] . getId ( ) ) . toBe ( 'nativeControl' ) ;
57
+ expect ( await inputs [ 4 ] . getId ( ) ) . toMatch ( / m a t - i n p u t - \d + / ) ;
56
58
} ) ;
57
59
58
60
it ( 'should be able to get name of input' , async ( ) => {
59
61
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
60
- expect ( inputs . length ) . toBe ( 3 ) ;
62
+ expect ( inputs . length ) . toBe ( 5 ) ;
61
63
expect ( await inputs [ 0 ] . getName ( ) ) . toBe ( 'favorite-food' ) ;
62
64
expect ( await inputs [ 1 ] . getName ( ) ) . toBe ( '' ) ;
63
65
expect ( await inputs [ 2 ] . getName ( ) ) . toBe ( '' ) ;
66
+ expect ( await inputs [ 3 ] . getName ( ) ) . toBe ( '' ) ;
67
+ expect ( await inputs [ 4 ] . getName ( ) ) . toBe ( '' ) ;
64
68
} ) ;
65
69
66
70
it ( 'should be able to get value of input' , async ( ) => {
67
71
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
68
- expect ( inputs . length ) . toBe ( 3 ) ;
72
+ expect ( inputs . length ) . toBe ( 5 ) ;
69
73
expect ( await inputs [ 0 ] . getValue ( ) ) . toBe ( 'Sushi' ) ;
70
74
expect ( await inputs [ 1 ] . getValue ( ) ) . toBe ( '' ) ;
71
75
expect ( await inputs [ 2 ] . getValue ( ) ) . toBe ( '' ) ;
76
+ expect ( await inputs [ 3 ] . getValue ( ) ) . toBe ( '' ) ;
77
+ expect ( await inputs [ 4 ] . getValue ( ) ) . toBe ( '' ) ;
72
78
} ) ;
73
79
74
80
it ( 'should be able to set value of input' , async ( ) => {
75
81
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
76
- expect ( inputs . length ) . toBe ( 3 ) ;
82
+ expect ( inputs . length ) . toBe ( 5 ) ;
77
83
expect ( await inputs [ 0 ] . getValue ( ) ) . toBe ( 'Sushi' ) ;
78
84
expect ( await inputs [ 1 ] . getValue ( ) ) . toBe ( '' ) ;
85
+ expect ( await inputs [ 3 ] . getValue ( ) ) . toBe ( '' ) ;
86
+ expect ( await inputs [ 4 ] . getValue ( ) ) . toBe ( '' ) ;
79
87
80
88
await inputs [ 0 ] . setValue ( '' ) ;
81
89
await inputs [ 2 ] . setValue ( 'new-value' ) ;
90
+ await inputs [ 3 ] . setValue ( 'new-value' ) ;
91
+ await inputs [ 4 ] . setValue ( 'new-value' ) ;
82
92
83
93
expect ( await inputs [ 0 ] . getValue ( ) ) . toBe ( '' ) ;
84
94
expect ( await inputs [ 2 ] . getValue ( ) ) . toBe ( 'new-value' ) ;
95
+ expect ( await inputs [ 3 ] . getValue ( ) ) . toBe ( 'new-value' ) ;
96
+ expect ( await inputs [ 4 ] . getValue ( ) ) . toBe ( 'new-value' ) ;
85
97
} ) ;
86
98
87
99
it ( 'should be able to get disabled state' , async ( ) => {
88
100
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
89
- expect ( inputs . length ) . toBe ( 3 ) ;
101
+ expect ( inputs . length ) . toBe ( 5 ) ;
90
102
91
103
expect ( await inputs [ 0 ] . isDisabled ( ) ) . toBe ( false ) ;
92
104
expect ( await inputs [ 1 ] . isDisabled ( ) ) . toBe ( false ) ;
93
105
expect ( await inputs [ 2 ] . isDisabled ( ) ) . toBe ( false ) ;
106
+ expect ( await inputs [ 3 ] . isDisabled ( ) ) . toBe ( false ) ;
107
+ expect ( await inputs [ 4 ] . isDisabled ( ) ) . toBe ( false ) ;
94
108
95
109
fixture . componentInstance . disabled = true ;
96
110
@@ -99,11 +113,13 @@ export function runHarnessTests(
99
113
100
114
it ( 'should be able to get readonly state' , async ( ) => {
101
115
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
102
- expect ( inputs . length ) . toBe ( 3 ) ;
116
+ expect ( inputs . length ) . toBe ( 5 ) ;
103
117
104
118
expect ( await inputs [ 0 ] . isReadonly ( ) ) . toBe ( false ) ;
105
119
expect ( await inputs [ 1 ] . isReadonly ( ) ) . toBe ( false ) ;
106
120
expect ( await inputs [ 2 ] . isReadonly ( ) ) . toBe ( false ) ;
121
+ expect ( await inputs [ 3 ] . isReadonly ( ) ) . toBe ( false ) ;
122
+ expect ( await inputs [ 4 ] . isReadonly ( ) ) . toBe ( false ) ;
107
123
108
124
fixture . componentInstance . readonly = true ;
109
125
@@ -112,11 +128,13 @@ export function runHarnessTests(
112
128
113
129
it ( 'should be able to get required state' , async ( ) => {
114
130
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
115
- expect ( inputs . length ) . toBe ( 3 ) ;
131
+ expect ( inputs . length ) . toBe ( 5 ) ;
116
132
117
133
expect ( await inputs [ 0 ] . isRequired ( ) ) . toBe ( false ) ;
118
134
expect ( await inputs [ 1 ] . isRequired ( ) ) . toBe ( false ) ;
119
135
expect ( await inputs [ 2 ] . isRequired ( ) ) . toBe ( false ) ;
136
+ expect ( await inputs [ 3 ] . isRequired ( ) ) . toBe ( false ) ;
137
+ expect ( await inputs [ 4 ] . isRequired ( ) ) . toBe ( false ) ;
120
138
121
139
fixture . componentInstance . required = true ;
122
140
@@ -125,18 +143,22 @@ export function runHarnessTests(
125
143
126
144
it ( 'should be able to get placeholder of input' , async ( ) => {
127
145
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
128
- expect ( inputs . length ) . toBe ( 3 ) ;
146
+ expect ( inputs . length ) . toBe ( 5 ) ;
129
147
expect ( await inputs [ 0 ] . getPlaceholder ( ) ) . toBe ( 'Favorite food' ) ;
130
148
expect ( await inputs [ 1 ] . getPlaceholder ( ) ) . toBe ( '' ) ;
131
149
expect ( await inputs [ 2 ] . getPlaceholder ( ) ) . toBe ( 'Leave a comment' ) ;
150
+ expect ( await inputs [ 3 ] . getPlaceholder ( ) ) . toBe ( 'Native control' ) ;
151
+ expect ( await inputs [ 4 ] . getPlaceholder ( ) ) . toBe ( '' ) ;
132
152
} ) ;
133
153
134
154
it ( 'should be able to get type of input' , async ( ) => {
135
155
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
136
- expect ( inputs . length ) . toBe ( 3 ) ;
156
+ expect ( inputs . length ) . toBe ( 5 ) ;
137
157
expect ( await inputs [ 0 ] . getType ( ) ) . toBe ( 'text' ) ;
138
158
expect ( await inputs [ 1 ] . getType ( ) ) . toBe ( 'number' ) ;
139
159
expect ( await inputs [ 2 ] . getType ( ) ) . toBe ( 'textarea' ) ;
160
+ expect ( await inputs [ 3 ] . getType ( ) ) . toBe ( 'text' ) ;
161
+ expect ( await inputs [ 4 ] . getType ( ) ) . toBe ( 'textarea' ) ;
140
162
141
163
fixture . componentInstance . inputType = 'text' ;
142
164
@@ -180,6 +202,24 @@ function getActiveElementTagName() {
180
202
<mat-form-field>
181
203
<textarea id="myTextarea" matInput placeholder="Leave a comment"></textarea>
182
204
</mat-form-field>
205
+
206
+ <mat-form-field>
207
+ <input matNativeControl placeholder="Native control" id="nativeControl">
208
+ </mat-form-field>
209
+
210
+ <mat-form-field>
211
+ <textarea matNativeControl></textarea>
212
+ </mat-form-field>
213
+
214
+ <mat-form-field>
215
+ <!--
216
+ Select native controls should not be handled as part of the input harness. We add this
217
+ to assert that the harness does not accidentally match it.
218
+ -->
219
+ <select matNativeControl>
220
+ <option value="first">First</option>
221
+ </select>
222
+ </mat-form-field>
183
223
`
184
224
} )
185
225
class InputHarnessTest {
0 commit comments