@@ -4,6 +4,7 @@ import {Component} from '@angular/core';
44import { ComponentFixture , TestBed } from '@angular/core/testing' ;
55import { ReactiveFormsModule } from '@angular/forms' ;
66import { MatInputModule } from '@angular/material/input' ;
7+ import { getSupportedInputTypes } from '@angular/cdk/platform' ;
78import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
89import { MatInputHarness } from './input-harness' ;
910
@@ -28,7 +29,7 @@ export function runHarnessTests(
2829
2930 it ( 'should load all input harnesses' , async ( ) => {
3031 const inputs = await loader . getAllHarnesses ( inputHarness ) ;
31- expect ( inputs . length ) . toBe ( 5 ) ;
32+ expect ( inputs . length ) . toBe ( 6 ) ;
3233 } ) ;
3334
3435 it ( 'should load input with specific id' , async ( ) => {
@@ -49,7 +50,7 @@ export function runHarnessTests(
4950
5051 it ( 'should be able to get id of input' , async ( ) => {
5152 const inputs = await loader . getAllHarnesses ( inputHarness ) ;
52- expect ( inputs . length ) . toBe ( 5 ) ;
53+ expect ( inputs . length ) . toBe ( 6 ) ;
5354 expect ( await inputs [ 0 ] . getId ( ) ) . toMatch ( / m a t - i n p u t - \d + / ) ;
5455 expect ( await inputs [ 1 ] . getId ( ) ) . toMatch ( / m a t - i n p u t - \d + / ) ;
5556 expect ( await inputs [ 2 ] . getId ( ) ) . toBe ( 'myTextarea' ) ;
@@ -59,7 +60,7 @@ export function runHarnessTests(
5960
6061 it ( 'should be able to get name of input' , async ( ) => {
6162 const inputs = await loader . getAllHarnesses ( inputHarness ) ;
62- expect ( inputs . length ) . toBe ( 5 ) ;
63+ expect ( inputs . length ) . toBe ( 6 ) ;
6364 expect ( await inputs [ 0 ] . getName ( ) ) . toBe ( 'favorite-food' ) ;
6465 expect ( await inputs [ 1 ] . getName ( ) ) . toBe ( '' ) ;
6566 expect ( await inputs [ 2 ] . getName ( ) ) . toBe ( '' ) ;
@@ -69,7 +70,7 @@ export function runHarnessTests(
6970
7071 it ( 'should be able to get value of input' , async ( ) => {
7172 const inputs = await loader . getAllHarnesses ( inputHarness ) ;
72- expect ( inputs . length ) . toBe ( 5 ) ;
73+ expect ( inputs . length ) . toBe ( 6 ) ;
7374 expect ( await inputs [ 0 ] . getValue ( ) ) . toBe ( 'Sushi' ) ;
7475 expect ( await inputs [ 1 ] . getValue ( ) ) . toBe ( '' ) ;
7576 expect ( await inputs [ 2 ] . getValue ( ) ) . toBe ( '' ) ;
@@ -79,7 +80,7 @@ export function runHarnessTests(
7980
8081 it ( 'should be able to set value of input' , async ( ) => {
8182 const inputs = await loader . getAllHarnesses ( inputHarness ) ;
82- expect ( inputs . length ) . toBe ( 5 ) ;
83+ expect ( inputs . length ) . toBe ( 6 ) ;
8384 expect ( await inputs [ 0 ] . getValue ( ) ) . toBe ( 'Sushi' ) ;
8485 expect ( await inputs [ 1 ] . getValue ( ) ) . toBe ( '' ) ;
8586 expect ( await inputs [ 3 ] . getValue ( ) ) . toBe ( '' ) ;
@@ -98,7 +99,7 @@ export function runHarnessTests(
9899
99100 it ( 'should be able to get disabled state' , async ( ) => {
100101 const inputs = await loader . getAllHarnesses ( inputHarness ) ;
101- expect ( inputs . length ) . toBe ( 5 ) ;
102+ expect ( inputs . length ) . toBe ( 6 ) ;
102103
103104 expect ( await inputs [ 0 ] . isDisabled ( ) ) . toBe ( false ) ;
104105 expect ( await inputs [ 1 ] . isDisabled ( ) ) . toBe ( false ) ;
@@ -113,7 +114,7 @@ export function runHarnessTests(
113114
114115 it ( 'should be able to get readonly state' , async ( ) => {
115116 const inputs = await loader . getAllHarnesses ( inputHarness ) ;
116- expect ( inputs . length ) . toBe ( 5 ) ;
117+ expect ( inputs . length ) . toBe ( 6 ) ;
117118
118119 expect ( await inputs [ 0 ] . isReadonly ( ) ) . toBe ( false ) ;
119120 expect ( await inputs [ 1 ] . isReadonly ( ) ) . toBe ( false ) ;
@@ -128,7 +129,7 @@ export function runHarnessTests(
128129
129130 it ( 'should be able to get required state' , async ( ) => {
130131 const inputs = await loader . getAllHarnesses ( inputHarness ) ;
131- expect ( inputs . length ) . toBe ( 5 ) ;
132+ expect ( inputs . length ) . toBe ( 6 ) ;
132133
133134 expect ( await inputs [ 0 ] . isRequired ( ) ) . toBe ( false ) ;
134135 expect ( await inputs [ 1 ] . isRequired ( ) ) . toBe ( false ) ;
@@ -143,7 +144,7 @@ export function runHarnessTests(
143144
144145 it ( 'should be able to get placeholder of input' , async ( ) => {
145146 const inputs = await loader . getAllHarnesses ( inputHarness ) ;
146- expect ( inputs . length ) . toBe ( 5 ) ;
147+ expect ( inputs . length ) . toBe ( 6 ) ;
147148 expect ( await inputs [ 0 ] . getPlaceholder ( ) ) . toBe ( 'Favorite food' ) ;
148149 expect ( await inputs [ 1 ] . getPlaceholder ( ) ) . toBe ( '' ) ;
149150 expect ( await inputs [ 2 ] . getPlaceholder ( ) ) . toBe ( 'Leave a comment' ) ;
@@ -153,7 +154,7 @@ export function runHarnessTests(
153154
154155 it ( 'should be able to get type of input' , async ( ) => {
155156 const inputs = await loader . getAllHarnesses ( inputHarness ) ;
156- expect ( inputs . length ) . toBe ( 5 ) ;
157+ expect ( inputs . length ) . toBe ( 6 ) ;
157158 expect ( await inputs [ 0 ] . getType ( ) ) . toBe ( 'text' ) ;
158159 expect ( await inputs [ 1 ] . getType ( ) ) . toBe ( 'number' ) ;
159160 expect ( await inputs [ 2 ] . getType ( ) ) . toBe ( 'textarea' ) ;
@@ -180,6 +181,18 @@ export function runHarnessTests(
180181 await input . blur ( ) ;
181182 expect ( getActiveElementTagName ( ) ) . not . toBe ( 'input' ) ;
182183 } ) ;
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+ } ) ;
183196}
184197
185198function getActiveElementTagName ( ) {
@@ -220,6 +233,10 @@ function getActiveElementTagName() {
220233 <option value="first">First</option>
221234 </select>
222235 </mat-form-field>
236+
237+ <mat-form-field>
238+ <input matNativeControl placeholder="Color control" id="colorControl" type="color">
239+ </mat-form-field>
223240 `
224241} )
225242class InputHarnessTest {
0 commit comments