@@ -374,17 +374,45 @@ describe('ColorField', function () {
374
374
expect ( onChangeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
375
375
} ) ;
376
376
377
- it ( 'should support the channel prop' , async function ( ) {
378
- let onChange = jest . fn ( ) ;
379
- let { getByRole} = renderComponent ( { label : null , value : '#abc' , colorSpace : 'hsl' , channel : 'hue' , onChange} ) ;
380
- let colorField = getByRole ( 'textbox' ) ;
381
- expect ( colorField . value ) . toBe ( '210°' ) ;
382
- expect ( colorField ) . toHaveAttribute ( 'aria-label' , 'Hue' ) ;
377
+ describe ( 'channel' , function ( ) {
378
+ it ( 'should support the channel prop' , async function ( ) {
379
+ let onChange = jest . fn ( ) ;
380
+ let { getByRole} = renderComponent ( { label : null , value : '#abc' , colorSpace : 'hsl' , channel : 'hue' , onChange} ) ;
381
+ let colorField = getByRole ( 'textbox' ) ;
382
+ expect ( colorField . value ) . toBe ( '210°' ) ;
383
+ expect ( colorField ) . toHaveAttribute ( 'aria-label' , 'Hue' ) ;
384
+
385
+ await user . tab ( ) ;
386
+ await user . keyboard ( '100' ) ;
387
+ await user . tab ( ) ;
388
+ expect ( onChange ) . toHaveBeenCalledWith ( parseColor ( 'hsl(100, 25%, 73.33%)' ) ) ;
389
+ } ) ;
383
390
384
- await user . tab ( ) ;
385
- await user . keyboard ( '100' ) ;
386
- await user . tab ( ) ;
387
- expect ( onChange ) . toHaveBeenCalledWith ( parseColor ( 'hsl(100, 25%, 73.33%)' ) ) ;
391
+ it ( 'should default to empty' , function ( ) {
392
+ let { getByRole} = renderComponent ( { label : null , colorSpace : 'hsl' , channel : 'hue' } ) ;
393
+ let colorField = getByRole ( 'textbox' ) ;
394
+ expect ( colorField ) . toHaveValue ( '' ) ;
395
+ } ) ;
396
+
397
+ it ( 'should support null value' , function ( ) {
398
+ let { getByRole} = renderComponent ( { label : null , value : null , colorSpace : 'hsl' , channel : 'hue' } ) ;
399
+ let colorField = getByRole ( 'textbox' ) ;
400
+ expect ( colorField ) . toHaveValue ( '' ) ;
401
+ } ) ;
402
+
403
+ it ( 'should support clearing value' , async function ( ) {
404
+ let onChange = jest . fn ( ) ;
405
+ let { getByRole} = renderComponent ( { label : null , defaultValue : '#abc' , colorSpace : 'hsl' , channel : 'hue' , onChange} ) ;
406
+ let colorField = getByRole ( 'textbox' ) ;
407
+ expect ( colorField ) . toHaveValue ( '210°' ) ;
408
+
409
+ await user . tab ( ) ;
410
+ await user . keyboard ( '{Backspace}' ) ;
411
+ await user . tab ( ) ;
412
+
413
+ expect ( colorField ) . toHaveValue ( '' ) ;
414
+ expect ( onChange ) . toHaveBeenCalledWith ( null ) ;
415
+ } ) ;
388
416
} ) ;
389
417
390
418
describe ( 'validation' , ( ) => {
0 commit comments