@@ -7,87 +7,96 @@ import { getPrefetchMonthCount } from "./getPrefetchMonthCount";
77describe ( "getPrefetchMonthCount" , ( ) => {
88 describe ( "COLUMN_VIEW layout" , ( ) => {
99 it ( "should return 2 when months are different" , ( ) => {
10- const result = getPrefetchMonthCount ( BookerLayouts . COLUMN_VIEW , "selecting_date" , 1 , 2 ) ;
10+ const result = getPrefetchMonthCount ( BookerLayouts . COLUMN_VIEW , "selecting_date" , 1 , 2 , false ) ;
1111 expect ( result ) . toBe ( 2 ) ;
1212 } ) ;
1313
1414 it ( "should return undefined when months are the same" , ( ) => {
15- const result = getPrefetchMonthCount ( BookerLayouts . COLUMN_VIEW , "selecting_date" , 5 , 5 ) ;
15+ const result = getPrefetchMonthCount ( BookerLayouts . COLUMN_VIEW , "selecting_date" , 5 , 5 , false ) ;
1616 expect ( result ) . toBe ( undefined ) ;
1717 } ) ;
1818
1919 it ( "should return 2 regardless of bookerState when months are different" , ( ) => {
20- expect ( getPrefetchMonthCount ( BookerLayouts . COLUMN_VIEW , "selecting_time" , 3 , 4 ) ) . toBe ( 2 ) ;
21- expect ( getPrefetchMonthCount ( BookerLayouts . COLUMN_VIEW , "booking" , 7 , 8 ) ) . toBe ( 2 ) ;
20+ expect ( getPrefetchMonthCount ( BookerLayouts . COLUMN_VIEW , "selecting_time" , 3 , 4 , false ) ) . toBe ( 2 ) ;
21+ expect ( getPrefetchMonthCount ( BookerLayouts . COLUMN_VIEW , "booking" , 7 , 8 , false ) ) . toBe ( 2 ) ;
22+ } ) ;
23+
24+ it ( "should return 2 even when prefetchNextMonth is true" , ( ) => {
25+ expect ( getPrefetchMonthCount ( BookerLayouts . COLUMN_VIEW , "selecting_time" , 3 , 4 , true ) ) . toBe ( 2 ) ;
2226 } ) ;
2327 } ) ;
2428
2529 describe ( "WEEK_VIEW layout" , ( ) => {
2630 it ( "should return undefined when state is selecting_time" , ( ) => {
27- const result = getPrefetchMonthCount ( BookerLayouts . WEEK_VIEW , "selecting_time" , 1 , 2 ) ;
31+ const result = getPrefetchMonthCount ( BookerLayouts . WEEK_VIEW , "selecting_time" , 1 , 2 , false ) ;
2832 expect ( result ) . toBe ( undefined ) ;
2933 } ) ;
3034
3135 it ( "should return undefined when state is not selecting_time" , ( ) => {
32- const result = getPrefetchMonthCount ( BookerLayouts . WEEK_VIEW , "selecting_date" , 1 , 2 ) ;
36+ const result = getPrefetchMonthCount ( BookerLayouts . WEEK_VIEW , "selecting_date" , 1 , 2 , false ) ;
3337 expect ( result ) . toBe ( undefined ) ;
3438 } ) ;
3539
3640 it ( "should return undefined even with different months" , ( ) => {
37- const result = getPrefetchMonthCount ( BookerLayouts . WEEK_VIEW , "booking" , 0 , 11 ) ;
41+ const result = getPrefetchMonthCount ( BookerLayouts . WEEK_VIEW , "booking" , 0 , 11 , false ) ;
3842 expect ( result ) . toBe ( undefined ) ;
3943 } ) ;
4044 } ) ;
4145
4246 describe ( "MONTH_VIEW layout with selecting_time state" , ( ) => {
43- it ( "should return 2 when months are different" , ( ) => {
44- const result = getPrefetchMonthCount ( BookerLayouts . MONTH_VIEW , "selecting_time" , 3 , 4 ) ;
47+ it ( "should return 2 when months are different and NOT prefetching " , ( ) => {
48+ const result = getPrefetchMonthCount ( BookerLayouts . MONTH_VIEW , "selecting_time" , 3 , 4 , false ) ;
4549 expect ( result ) . toBe ( 2 ) ;
4650 } ) ;
4751
52+ it ( "should return undefined when months are different but ALREADY prefetching" , ( ) => {
53+ const result = getPrefetchMonthCount ( BookerLayouts . MONTH_VIEW , "selecting_time" , 3 , 4 , true ) ;
54+ expect ( result ) . toBe ( undefined ) ;
55+ } ) ;
56+
4857 it ( "should return undefined when months are the same" , ( ) => {
49- const result = getPrefetchMonthCount ( BookerLayouts . MONTH_VIEW , "selecting_time" , 6 , 6 ) ;
58+ const result = getPrefetchMonthCount ( BookerLayouts . MONTH_VIEW , "selecting_time" , 6 , 6 , false ) ;
5059 expect ( result ) . toBe ( undefined ) ;
5160 } ) ;
5261 } ) ;
5362
5463 describe ( "MONTH_VIEW layout with other states" , ( ) => {
5564 it ( "should return undefined when state is selecting_date" , ( ) => {
56- const result = getPrefetchMonthCount ( BookerLayouts . MONTH_VIEW , "selecting_date" , 1 , 2 ) ;
65+ const result = getPrefetchMonthCount ( BookerLayouts . MONTH_VIEW , "selecting_date" , 1 , 2 , false ) ;
5766 expect ( result ) . toBe ( undefined ) ;
5867 } ) ;
5968
6069 it ( "should return undefined when state is booking" , ( ) => {
61- const result = getPrefetchMonthCount ( BookerLayouts . MONTH_VIEW , "booking" , 1 , 2 ) ;
70+ const result = getPrefetchMonthCount ( BookerLayouts . MONTH_VIEW , "booking" , 1 , 2 , false ) ;
6271 expect ( result ) . toBe ( undefined ) ;
6372 } ) ;
6473 } ) ;
6574
6675 describe ( "invalid month inputs" , ( ) => {
6776 it ( "should return undefined when first month is NaN" , ( ) => {
68- const result = getPrefetchMonthCount ( BookerLayouts . COLUMN_VIEW , "selecting_date" , NaN , 5 ) ;
77+ const result = getPrefetchMonthCount ( BookerLayouts . COLUMN_VIEW , "selecting_date" , NaN , 5 , false ) ;
6978 expect ( result ) . toBe ( undefined ) ;
7079 } ) ;
7180
7281 it ( "should return undefined when second month is NaN" , ( ) => {
73- const result = getPrefetchMonthCount ( BookerLayouts . COLUMN_VIEW , "selecting_date" , 5 , NaN ) ;
82+ const result = getPrefetchMonthCount ( BookerLayouts . COLUMN_VIEW , "selecting_date" , 5 , NaN , false ) ;
7483 expect ( result ) . toBe ( undefined ) ;
7584 } ) ;
7685
7786 it ( "should return undefined when both months are invalid" , ( ) => {
78- const result = getPrefetchMonthCount ( BookerLayouts . COLUMN_VIEW , "selecting_time" , Infinity , - Infinity ) ;
87+ const result = getPrefetchMonthCount ( BookerLayouts . COLUMN_VIEW , "selecting_time" , Infinity , - Infinity , false ) ;
7988 expect ( result ) . toBe ( undefined ) ;
8089 } ) ;
8190 } ) ;
8291
8392 describe ( "edge cases" , ( ) => {
8493 it ( "should handle month transitions (11 to 0)" , ( ) => {
85- const result = getPrefetchMonthCount ( BookerLayouts . COLUMN_VIEW , "selecting_date" , 11 , 0 ) ;
94+ const result = getPrefetchMonthCount ( BookerLayouts . COLUMN_VIEW , "selecting_date" , 11 , 0 , false ) ;
8695 expect ( result ) . toBe ( 2 ) ;
8796 } ) ;
8897
8998 it ( "should handle negative month numbers if they are different" , ( ) => {
90- const result = getPrefetchMonthCount ( BookerLayouts . COLUMN_VIEW , "selecting_date" , - 1 , 5 ) ;
99+ const result = getPrefetchMonthCount ( BookerLayouts . COLUMN_VIEW , "selecting_date" , - 1 , 5 , false ) ;
91100 expect ( result ) . toBe ( 2 ) ;
92101 } ) ;
93102 } ) ;
0 commit comments