@@ -898,7 +898,7 @@ describe("Day", () => {
898898 } ) ;
899899
900900 describe ( "for a date picker with selectsRange and swapRange prop" , ( ) => {
901- it ( "should select range from startDate to selectingDate if selectingDate more than startDate" , ( ) => {
901+ it ( "should select range from startDate to selectingDate if selectingDate is after startDate" , ( ) => {
902902 const startDate = newDate ( ) ;
903903 const dayInRange = addDays ( startDate , 1 ) ;
904904 const selectingDate = addDays ( startDate , 2 ) ;
@@ -916,7 +916,7 @@ describe("Day", () => {
916916 ) . toBe ( true ) ;
917917 } )
918918
919- it ( "should select range from selectingDate to startDate if selectingDate less than startDate" , ( ) => {
919+ it ( "should select range from selectingDate to startDate if selectingDate is before startDate" , ( ) => {
920920 const startDate = newDate ( ) ;
921921 const dayInRange = subDays ( startDate , 1 ) ;
922922 const selectingDate = subDays ( startDate , 2 ) ;
@@ -950,6 +950,97 @@ describe("Day", () => {
950950 ?. classList . contains ( rangeDayClassName ) ,
951951 ) . toBe ( true ) ;
952952 } ) ;
953+
954+ it ( "should set selectingDate as the start of range and startDate as the end of range if selectingDate is before startDate" , ( ) => {
955+ const startDate = newDate ( ) ;
956+ const selectingDate = subDays ( startDate , 1 ) ;
957+
958+ const containerStartDay = renderDay ( selectingDate , {
959+ startDate,
960+ selectingDate,
961+ selectsRange : true ,
962+ swapRange : true ,
963+ } ) ;
964+ expect (
965+ containerStartDay
966+ . querySelector ( ".react-datepicker__day" )
967+ ?. classList . contains ( rangeDayStartClassName ) ,
968+ ) . toBe ( true ) ;
969+
970+
971+ const containerEndDay = renderDay ( startDate , {
972+ startDate,
973+ selectingDate,
974+ selectsRange : true ,
975+ swapRange : true ,
976+ } ) ;
977+
978+ expect (
979+ containerEndDay
980+ . querySelector ( ".react-datepicker__day" )
981+ ?. classList . contains ( rangeDayEndClassName ) ,
982+ ) . toBe ( true ) ;
983+ } )
984+
985+ it ( "should set selectingDate as the end of range and startDate as the start of range if selectingDate is after startDate" , ( ) => {
986+ const startDate = newDate ( ) ;
987+ const selectingDate = addDays ( startDate , 1 ) ;
988+
989+ const containerStartDay = renderDay ( startDate , {
990+ startDate,
991+ selectingDate,
992+ selectsRange : true ,
993+ swapRange : true ,
994+ } ) ;
995+ expect (
996+ containerStartDay
997+ . querySelector ( ".react-datepicker__day" )
998+ ?. classList . contains ( rangeDayStartClassName ) ,
999+ ) . toBe ( true ) ;
1000+
1001+ const containerEndDay = renderDay ( selectingDate , {
1002+ startDate,
1003+ selectingDate,
1004+ selectsRange : true ,
1005+ swapRange : true ,
1006+ } ) ;
1007+
1008+ expect (
1009+ containerEndDay
1010+ . querySelector ( ".react-datepicker__day" )
1011+ ?. classList . contains ( rangeDayEndClassName ) ,
1012+ ) . toBe ( true ) ;
1013+ } )
1014+
1015+ it ( 'should set startDate as the end and start range if selectionDate equal startDate' , ( ) => {
1016+ const startDate = newDate ( ) ;
1017+ const selectingDate = startDate ;
1018+
1019+ const containerStartDay = renderDay ( startDate , {
1020+ startDate,
1021+ selectingDate,
1022+ selectsRange : true ,
1023+ swapRange : true ,
1024+ } ) ;
1025+ expect (
1026+ containerStartDay
1027+ . querySelector ( ".react-datepicker__day" )
1028+ ?. classList . contains ( rangeDayStartClassName ) ,
1029+ ) . toBe ( true ) ;
1030+
1031+ const containerEndDay = renderDay ( selectingDate , {
1032+ startDate,
1033+ selectingDate,
1034+ selectsRange : true ,
1035+ swapRange : true ,
1036+ } ) ;
1037+
1038+ expect (
1039+ containerEndDay
1040+ . querySelector ( ".react-datepicker__day" )
1041+ ?. classList . contains ( rangeDayEndClassName ) ,
1042+ ) . toBe ( true ) ;
1043+ } ) ;
9531044 } )
9541045 } ) ;
9551046
0 commit comments