@@ -4,6 +4,7 @@ import {Component} from '@angular/core';
4
4
import { ComponentFixture , TestBed } from '@angular/core/testing' ;
5
5
import { ReactiveFormsModule } from '@angular/forms' ;
6
6
import { MatInputModule } from '@angular/material/input' ;
7
+ import { getSupportedInputTypes } from '@angular/cdk/platform' ;
7
8
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
8
9
import { MatInputHarness } from './input-harness' ;
9
10
@@ -28,7 +29,7 @@ export function runHarnessTests(
28
29
29
30
it ( 'should load all input harnesses' , async ( ) => {
30
31
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
31
- expect ( inputs . length ) . toBe ( 5 ) ;
32
+ expect ( inputs . length ) . toBe ( 6 ) ;
32
33
} ) ;
33
34
34
35
it ( 'should load input with specific id' , async ( ) => {
@@ -49,7 +50,7 @@ export function runHarnessTests(
49
50
50
51
it ( 'should be able to get id of input' , async ( ) => {
51
52
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
52
- expect ( inputs . length ) . toBe ( 5 ) ;
53
+ expect ( inputs . length ) . toBe ( 6 ) ;
53
54
expect ( await inputs [ 0 ] . getId ( ) ) . toMatch ( / m a t - i n p u t - \d + / ) ;
54
55
expect ( await inputs [ 1 ] . getId ( ) ) . toMatch ( / m a t - i n p u t - \d + / ) ;
55
56
expect ( await inputs [ 2 ] . getId ( ) ) . toBe ( 'myTextarea' ) ;
@@ -59,7 +60,7 @@ export function runHarnessTests(
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 ( '' ) ;
@@ -69,7 +70,7 @@ export function runHarnessTests(
69
70
70
71
it ( 'should be able to get value of input' , async ( ) => {
71
72
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
72
- expect ( inputs . length ) . toBe ( 5 ) ;
73
+ expect ( inputs . length ) . toBe ( 6 ) ;
73
74
expect ( await inputs [ 0 ] . getValue ( ) ) . toBe ( 'Sushi' ) ;
74
75
expect ( await inputs [ 1 ] . getValue ( ) ) . toBe ( '' ) ;
75
76
expect ( await inputs [ 2 ] . getValue ( ) ) . toBe ( '' ) ;
@@ -79,7 +80,7 @@ export function runHarnessTests(
79
80
80
81
it ( 'should be able to set value of input' , async ( ) => {
81
82
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
82
- expect ( inputs . length ) . toBe ( 5 ) ;
83
+ expect ( inputs . length ) . toBe ( 6 ) ;
83
84
expect ( await inputs [ 0 ] . getValue ( ) ) . toBe ( 'Sushi' ) ;
84
85
expect ( await inputs [ 1 ] . getValue ( ) ) . toBe ( '' ) ;
85
86
expect ( await inputs [ 3 ] . getValue ( ) ) . toBe ( '' ) ;
@@ -98,7 +99,7 @@ export function runHarnessTests(
98
99
99
100
it ( 'should be able to get disabled state' , async ( ) => {
100
101
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
101
- expect ( inputs . length ) . toBe ( 5 ) ;
102
+ expect ( inputs . length ) . toBe ( 6 ) ;
102
103
103
104
expect ( await inputs [ 0 ] . isDisabled ( ) ) . toBe ( false ) ;
104
105
expect ( await inputs [ 1 ] . isDisabled ( ) ) . toBe ( false ) ;
@@ -113,7 +114,7 @@ export function runHarnessTests(
113
114
114
115
it ( 'should be able to get readonly state' , async ( ) => {
115
116
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
116
- expect ( inputs . length ) . toBe ( 5 ) ;
117
+ expect ( inputs . length ) . toBe ( 6 ) ;
117
118
118
119
expect ( await inputs [ 0 ] . isReadonly ( ) ) . toBe ( false ) ;
119
120
expect ( await inputs [ 1 ] . isReadonly ( ) ) . toBe ( false ) ;
@@ -128,7 +129,7 @@ export function runHarnessTests(
128
129
129
130
it ( 'should be able to get required state' , async ( ) => {
130
131
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
131
- expect ( inputs . length ) . toBe ( 5 ) ;
132
+ expect ( inputs . length ) . toBe ( 6 ) ;
132
133
133
134
expect ( await inputs [ 0 ] . isRequired ( ) ) . toBe ( false ) ;
134
135
expect ( await inputs [ 1 ] . isRequired ( ) ) . toBe ( false ) ;
@@ -143,7 +144,7 @@ export function runHarnessTests(
143
144
144
145
it ( 'should be able to get placeholder of input' , async ( ) => {
145
146
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
146
- expect ( inputs . length ) . toBe ( 5 ) ;
147
+ expect ( inputs . length ) . toBe ( 6 ) ;
147
148
expect ( await inputs [ 0 ] . getPlaceholder ( ) ) . toBe ( 'Favorite food' ) ;
148
149
expect ( await inputs [ 1 ] . getPlaceholder ( ) ) . toBe ( '' ) ;
149
150
expect ( await inputs [ 2 ] . getPlaceholder ( ) ) . toBe ( 'Leave a comment' ) ;
@@ -153,7 +154,7 @@ export function runHarnessTests(
153
154
154
155
it ( 'should be able to get type of input' , async ( ) => {
155
156
const inputs = await loader . getAllHarnesses ( inputHarness ) ;
156
- expect ( inputs . length ) . toBe ( 5 ) ;
157
+ expect ( inputs . length ) . toBe ( 6 ) ;
157
158
expect ( await inputs [ 0 ] . getType ( ) ) . toBe ( 'text' ) ;
158
159
expect ( await inputs [ 1 ] . getType ( ) ) . toBe ( 'number' ) ;
159
160
expect ( await inputs [ 2 ] . getType ( ) ) . toBe ( 'textarea' ) ;
@@ -180,6 +181,18 @@ export function runHarnessTests(
180
181
await input . blur ( ) ;
181
182
expect ( getActiveElementTagName ( ) ) . not . toBe ( 'input' ) ;
182
183
} ) ;
184
+
185
+ it ( 'should be able to set the value of a control that cannot be typed in' , async ( ) => {
186
+ // We can't test this against browsers that don't support color inputs.
187
+ if ( ! getSupportedInputTypes ( ) . has ( 'color' ) ) {
188
+ return ;
189
+ }
190
+
191
+ const input = await loader . getHarness ( inputHarness . with ( { selector : '#colorControl' } ) ) ;
192
+ expect ( await input . getValue ( ) ) . toBe ( '#000000' ) ; // Color inputs default to black.
193
+ await input . setValue ( '#00ff00' ) ;
194
+ expect ( ( await input . getValue ( ) ) . toLowerCase ( ) ) . toBe ( '#00ff00' ) ;
195
+ } ) ;
183
196
}
184
197
185
198
function getActiveElementTagName ( ) {
@@ -220,6 +233,10 @@ function getActiveElementTagName() {
220
233
<option value="first">First</option>
221
234
</select>
222
235
</mat-form-field>
236
+
237
+ <mat-form-field>
238
+ <input matNativeControl placeholder="Color control" id="colorControl" type="color">
239
+ </mat-form-field>
223
240
`
224
241
} )
225
242
class InputHarnessTest {
0 commit comments