@@ -7,8 +7,10 @@ import {
77 createFormAssociatedTestBed ,
88 runValidationContainerTests ,
99 simulateClick ,
10+ simulateInput ,
1011} from '../common/utils.spec.js' ;
1112import IgcDateTimeInputComponent from '../date-time-input/date-time-input.js' ;
13+ import IgcInputComponent from '../input/input.js' ;
1214import IgcDateRangePickerComponent , {
1315 type DateRangeValue ,
1416} from './date-range-picker.js' ;
@@ -26,6 +28,7 @@ describe('Date Range Picker Two Inputs - Form integration', () => {
2628
2729 const today = CalendarDay . today ;
2830 const tomorrow = today . add ( 'day' , 1 ) ;
31+ const yesterday = today . add ( 'day' , - 1 ) ;
2932
3033 const spec = createFormAssociatedTestBed < IgcDateRangePickerComponent > (
3134 html `< igc-date-range-picker
@@ -428,8 +431,6 @@ describe('Date Range Picker Two Inputs - Form integration', () => {
428431 describe ( 'Validation message slots' , ( ) => {
429432 it ( '' , ( ) => {
430433 const now = CalendarDay . today ;
431- const tomorrow = now . add ( 'day' , 1 ) ;
432- const yesterday = now . add ( 'day' , - 1 ) ;
433434
434435 const testParameters : ValidationContainerTestsParams < IgcDateRangePickerComponent > [ ] =
435436 [
@@ -467,4 +468,57 @@ describe('Date Range Picker Two Inputs - Form integration', () => {
467468 runValidationContainerTests ( IgcDateRangePickerComponent , testParameters ) ;
468469 } ) ;
469470 } ) ;
471+ it ( 'is correctly validated on switching between two and single inputs' , async ( ) => {
472+ spec . setProperties ( { useTwoInputs : false } ) ;
473+ await elementUpdated ( spec . element ) ;
474+
475+ spec . setProperties ( { value : null } ) ;
476+ spec . setProperties ( { required : true } ) ;
477+ await elementUpdated ( spec . element ) ;
478+
479+ let singleInput = spec . element . renderRoot . querySelector (
480+ IgcInputComponent . tagName
481+ ) ! ;
482+ expect ( singleInput . invalid ) . to . be . true ;
483+
484+ spec . setProperties ( { useTwoInputs : true } ) ;
485+ await elementUpdated ( spec . element ) ;
486+
487+ const dti = spec . element . renderRoot . querySelectorAll (
488+ IgcDateTimeInputComponent . tagName
489+ ) ;
490+ const input = dti [ 0 ] ! . shadowRoot ! . querySelector (
491+ 'input'
492+ ) as HTMLInputElement ;
493+ simulateInput ( input , { value : '01/01/2025' , inputType : 'insertText' } ) ;
494+ // expect both inputs to be invalid as the date range is not complete
495+ expect ( dti [ 0 ] ! . invalid ) . to . be . true ;
496+ expect ( dti [ 1 ] ! . invalid ) . to . be . true ;
497+
498+ spec . setProperties ( { useTwoInputs : false } ) ;
499+ await elementUpdated ( spec . element ) ;
500+
501+ spec . setProperties ( {
502+ disabledDates : [
503+ {
504+ type : DateRangeType . Between ,
505+ dateRange : [ today . native , tomorrow . native ] ,
506+ } ,
507+ ] ,
508+ } ) ;
509+ await elementUpdated ( spec . element ) ;
510+
511+ spec . setProperties ( {
512+ value : {
513+ start : today . add ( 'day' , - 2 ) . native ,
514+ end : tomorrow . add ( 'day' , 2 ) . native ,
515+ } ,
516+ } ) ;
517+ await elementUpdated ( spec . element ) ;
518+
519+ singleInput = spec . element . renderRoot . querySelector (
520+ IgcInputComponent . tagName
521+ ) ! ;
522+ expect ( singleInput . invalid ) . to . be . true ;
523+ } ) ;
470524} ) ;
0 commit comments