@@ -470,6 +470,55 @@ describe('DatePicker', function () {
470
470
expect ( getTextValue ( combobox ) ) . toBe ( '2/4/2019, 9:45 AM' ) ;
471
471
} ) ;
472
472
473
+ it ( 'should not throw error when deleting values from time field when CalendarDateTime value is used' , function ( ) {
474
+ let onChange = jest . fn ( ) ;
475
+ let { getByRole, getAllByRole, getAllByLabelText} = render (
476
+ < Provider theme = { theme } >
477
+ < DatePicker label = "Date" defaultValue = { new CalendarDateTime ( 2019 , 2 , 3 , 10 , 45 ) } onChange = { onChange } />
478
+ </ Provider >
479
+ ) ;
480
+
481
+ let combobox = getAllByRole ( 'group' ) [ 0 ] ;
482
+ expect ( getTextValue ( combobox ) ) . toBe ( '2/3/2019, 10:45 AM' ) ;
483
+
484
+ let button = getByRole ( 'button' ) ;
485
+ triggerPress ( button ) ;
486
+
487
+ let dialog = getByRole ( 'dialog' ) ;
488
+ expect ( dialog ) . toBeVisible ( ) ;
489
+
490
+ let cells = getAllByRole ( 'gridcell' ) ;
491
+ let selected = cells . find ( cell => cell . getAttribute ( 'aria-selected' ) === 'true' ) ;
492
+ expect ( selected . children [ 0 ] ) . toHaveAttribute ( 'aria-label' , 'Sunday, February 3, 2019 selected' ) ;
493
+
494
+ let timeField = getAllByLabelText ( 'Time' ) [ 0 ] ;
495
+ expect ( getTextValue ( timeField ) ) . toBe ( '10:45 AM' ) ;
496
+
497
+ // selecting a date should not close the popover
498
+ triggerPress ( selected . nextSibling . children [ 0 ] ) ;
499
+
500
+ expect ( dialog ) . toBeVisible ( ) ;
501
+ expect ( onChange ) . toHaveBeenCalledTimes ( 1 ) ;
502
+ expect ( onChange ) . toHaveBeenCalledWith ( new CalendarDateTime ( 2019 , 2 , 4 , 10 , 45 ) ) ;
503
+ expect ( getTextValue ( combobox ) ) . toBe ( '2/4/2019, 10:45 AM' ) ;
504
+
505
+ let hour = within ( timeField ) . getByLabelText ( 'hour,' ) ;
506
+ expect ( hour ) . toHaveAttribute ( 'role' , 'spinbutton' ) ;
507
+ expect ( hour ) . toHaveAttribute ( 'aria-valuetext' , '10 AM' ) ;
508
+
509
+ act ( ( ) => hour . focus ( ) ) ;
510
+ fireEvent . keyDown ( hour , { key : 'Backspace' } ) ;
511
+ expect ( hour ) . toHaveAttribute ( 'aria-valuetext' , '1 AM' ) ;
512
+
513
+ fireEvent . keyDown ( hour , { key : 'Backspace' } ) ;
514
+ expect ( hour ) . toHaveAttribute ( 'aria-valuetext' , '1 AM' ) ;
515
+
516
+ expect ( dialog ) . toBeVisible ( ) ;
517
+ expect ( onChange ) . toHaveBeenCalledTimes ( 2 ) ;
518
+ expect ( onChange ) . toHaveBeenCalledWith ( new CalendarDateTime ( 2019 , 2 , 4 , 1 , 45 ) ) ;
519
+ expect ( getTextValue ( combobox ) ) . toBe ( '2/4/2019, 1:45 AM' ) ;
520
+ } ) ;
521
+
473
522
it ( 'should not fire onChange until both date and time are selected' , function ( ) {
474
523
let onChange = jest . fn ( ) ;
475
524
let { getByRole, getAllByRole, getAllByLabelText} = render (
0 commit comments