@@ -516,6 +516,8 @@ describe('Date range picker', () => {
516516 ) as any ;
517517 expect ( separator ?. innerText ) . to . equal ( 'Separator - localized' ) ;
518518 } ) ;
519+ // TODO
520+ it ( 'should set the default placeholder of the single input to the input format (like dd/MM/yyyy - dd/MM/yyyy)' , async ( ) => { } ) ;
519521 } ) ;
520522 describe ( 'Methods' , ( ) => {
521523 it ( 'should open/close the picker on invoking show/hide/toggle and not emit events' , async ( ) => {
@@ -607,8 +609,37 @@ describe('Date range picker', () => {
607609 expect ( popover ?. hasAttribute ( 'open' ) ) . to . equal ( false ) ;
608610 } ) ;
609611
610- // TODO
611- it ( 'should swap the selected dates if the end is earlier than the start' , async ( ) => { } ) ;
612+ it ( 'should swap the selected dates after input if the end is earlier than the start' , async ( ) => {
613+ const eventSpy = spy ( picker , 'emitEvent' ) ;
614+ const aMonthAgo = today . add ( 'month' , - 1 ) ;
615+ picker . value = null ;
616+ await elementUpdated ( picker ) ;
617+
618+ dateTimeInputs [ 0 ] . focus ( ) ;
619+ await elementUpdated ( dateTimeInputs [ 0 ] ) ;
620+ expect ( isFocused ( dateTimeInputs [ 0 ] ) ) . to . be . true ;
621+
622+ simulateKeyboard ( dateTimeInputs [ 0 ] , arrowUp ) ;
623+ await elementUpdated ( picker ) ;
624+
625+ expect ( eventSpy ) . calledWith ( 'igcInput' ) ;
626+ eventSpy . resetHistory ( ) ;
627+
628+ dateTimeInputs [ 1 ] . focus ( ) ;
629+ // first arrow sets today, second sets aMonthAgo
630+ simulateKeyboard ( dateTimeInputs [ 1 ] , arrowDown ) ;
631+ simulateKeyboard ( dateTimeInputs [ 1 ] , arrowDown ) ;
632+ await elementUpdated ( picker ) ;
633+
634+ dateTimeInputs [ 1 ] . blur ( ) ;
635+ await elementUpdated ( picker ) ;
636+
637+ expect ( eventSpy ) . calledWith ( 'igcChange' ) ;
638+ checkSelectedRange ( picker , {
639+ start : aMonthAgo . native ,
640+ end : today . native ,
641+ } ) ;
642+ } ) ;
612643
613644 it ( 'should select a range of dates in dialog mode and emit igcChange when done is clicked' , async ( ) => {
614645 const eventSpy = spy ( picker , 'emitEvent' ) ;
@@ -1070,8 +1101,7 @@ describe('Date range picker', () => {
10701101 expect ( picker . open ) . to . be . true ;
10711102 } ) ;
10721103
1073- it ( 'should not open the picker in dropdown mode when clicking the clear icon' , async ( ) => {
1074- // TODO -elaborate test scenario?
1104+ it ( 'should clear the inputs on clicking the clear icon - two inputs' , async ( ) => {
10751105 picker . value = { start : today . native , end : tomorrow . native } ;
10761106 await elementUpdated ( picker ) ;
10771107
@@ -1080,25 +1110,42 @@ describe('Date range picker', () => {
10801110
10811111 expect ( picker . open ) . to . be . false ;
10821112 expect ( picker . value ) . to . deep . equal ( { start : null , end : null } ) ;
1113+ expect ( dateTimeInputs [ 0 ] . value ) . to . be . null ;
1114+ expect ( dateTimeInputs [ 1 ] . value ) . to . be . null ;
10831115 } ) ;
10841116
1085- it ( 'should not open the picker in dialog mode when clicking the clear icon' , async ( ) => {
1086- // TODO -elaborate test scenario?
1087- picker . mode = 'dialog' ;
1117+ it ( 'should clear the inputs on clicking the clear icon - single input' , async ( ) => {
1118+ picker . useTwoInputs = false ;
10881119 picker . value = { start : today . native , end : tomorrow . native } ;
10891120 await elementUpdated ( picker ) ;
10901121
10911122 simulateClick ( getIcon ( picker , clearIcon ) ) ;
10921123 await elementUpdated ( picker ) ;
10931124
10941125 expect ( picker . open ) . to . be . false ;
1095- picker . value = { start : null , end : null } ;
1126+ expect ( picker . value ) . to . deep . equal ( { start : null , end : null } ) ;
1127+ const input = picker . renderRoot ! . querySelector (
1128+ IgcInputComponent . tagName
1129+ ) ! ;
1130+ expect ( input . value ) . to . equal ( '' ) ;
10961131 } ) ;
10971132
1098- // TODO
1099- it ( 'should emit igcInput and igcChange on input value change' , async ( ) => { } ) ;
1133+ it ( 'should emit igcInput and igcChange on input value change' , async ( ) => {
1134+ const eventSpy = spy ( picker , 'emitEvent' ) ;
1135+
1136+ dateTimeInputs [ 0 ] . focus ( ) ;
1137+ await elementUpdated ( dateTimeInputs [ 0 ] ) ;
1138+ expect ( isFocused ( dateTimeInputs [ 0 ] ) ) . to . be . true ;
1139+
1140+ simulateKeyboard ( dateTimeInputs [ 0 ] , arrowUp ) ;
1141+ await elementUpdated ( picker ) ;
1142+
1143+ expect ( eventSpy ) . calledWith ( 'igcInput' ) ;
1144+ eventSpy . resetHistory ( ) ;
11001145
1101- it ( 'should not swap the dates while typing' , async ( ) => { } ) ;
1146+ simulateKeyboard ( dateTimeInputs [ 0 ] , arrowDown ) ;
1147+ await elementUpdated ( picker ) ;
1148+ } ) ;
11021149
11031150 it ( 'should set the calendar active date to the start of the range while typing' , async ( ) => { } ) ;
11041151 } ) ;
@@ -1751,9 +1798,12 @@ const checkSelectedRange = (
17511798 IgcCalendarComponent . tagName
17521799 ) ! ;
17531800
1754- checkDatesEqual ( picker . value ?. start ! , expectedValue ?. start ! ) ;
1755- checkDatesEqual ( picker . value ?. end ! , expectedValue ?. end ! ) ;
1756-
1801+ if ( expectedValue ?. start ) {
1802+ checkDatesEqual ( picker . value ?. start ! , expectedValue . start ) ;
1803+ }
1804+ if ( expectedValue ?. end ) {
1805+ checkDatesEqual ( picker . value ?. end ! , expectedValue . end ) ;
1806+ }
17571807 if ( ! useTwoInputs ) {
17581808 const input = picker . renderRoot . querySelector ( IgcInputComponent . tagName ) ! ;
17591809 const start = expectedValue ?. start
@@ -1775,8 +1825,12 @@ const checkSelectedRange = (
17751825 const inputs = picker . renderRoot . querySelectorAll (
17761826 IgcDateTimeInputComponent . tagName
17771827 ) ;
1778- checkDatesEqual ( inputs [ 0 ] . value ! , expectedValue ?. start ! ) ;
1779- checkDatesEqual ( inputs [ 1 ] . value ! , expectedValue ?. end ! ) ;
1828+ if ( expectedValue ?. start ) {
1829+ checkDatesEqual ( inputs [ 0 ] . value ! , expectedValue . start ) ;
1830+ }
1831+ if ( expectedValue ?. end ) {
1832+ checkDatesEqual ( inputs [ 1 ] . value ! , expectedValue . end ) ;
1833+ }
17801834 }
17811835
17821836 if ( expectedValue ?. start ) {
0 commit comments