@@ -52,6 +52,20 @@ describe('Month Selector utils', () => {
52
52
const result2 = keyLeftFunction ( previous2 ) ;
53
53
expect ( result2 ) . toBe ( previous2 - 1 ) ;
54
54
} ) ;
55
+ it ( 'keyLeftMove - maxDate and minDate in same year - should move to the left when left arrow key is pressed' , ( ) => {
56
+ const maxDate = new Date ( 2023 , 8 , 15 ) ;
57
+ const currentDate = new Date ( 2023 , 8 , 22 ) ;
58
+ const minDate = new Date ( 2023 , 4 , 15 ) ;
59
+
60
+ const keyLeftFunction = keyLeftMove ( { currentDate, maxDate, minDate } ) ;
61
+
62
+ const previous1 = minDate . getMonth ( ) ;
63
+ const previous2 = minDate . getMonth ( ) + 1 ;
64
+ const result1 = keyLeftFunction ( previous1 ) ;
65
+ expect ( result1 ) . toBe ( maxDate . getMonth ( ) ) ;
66
+ const result2 = keyLeftFunction ( previous2 ) ;
67
+ expect ( result2 ) . toBe ( previous2 - 1 ) ;
68
+ } ) ;
55
69
it ( 'keyRightMove - maxDate and currentDate in same year - should move to the right when right arrow key is pressed' , ( ) => {
56
70
const maxDate = new Date ( 2023 , 8 , 15 ) ;
57
71
const currentDate = new Date ( 2023 , 8 , 22 ) ;
@@ -94,6 +108,21 @@ describe('Month Selector utils', () => {
94
108
const result2 = keyRightFunction ( previous2 ) ;
95
109
expect ( result2 ) . toBe ( previous2 + 1 ) ;
96
110
} ) ;
111
+
112
+ it ( 'keyRightMove - maxDate and minDate in same year - should move to the right when right arrow key is pressed' , ( ) => {
113
+ const maxDate = new Date ( 2023 , 8 , 15 ) ;
114
+ const currentDate = new Date ( 2023 , 8 , 22 ) ;
115
+ const minDate = new Date ( 2023 , 4 , 15 ) ;
116
+
117
+ const keyRightFunction = keyRightMove ( { currentDate, maxDate, minDate } ) ;
118
+
119
+ const previous1 = maxDate . getMonth ( ) ;
120
+ const previous2 = maxDate . getMonth ( ) - 1 ;
121
+ const result1 = keyRightFunction ( previous1 ) ;
122
+ expect ( result1 ) . toBe ( minDate . getMonth ( ) ) ;
123
+ const result2 = keyRightFunction ( previous2 ) ;
124
+ expect ( result2 ) . toBe ( previous2 + 1 ) ;
125
+ } ) ;
97
126
it ( 'keyUpMove - maxDate and currentDate in same year - should move up when up arrow key is pressed' , ( ) => {
98
127
const maxDate = new Date ( 2023 , 8 , 15 ) ;
99
128
const currentDate = new Date ( 2023 , 8 , 22 ) ;
@@ -145,7 +174,24 @@ describe('Month Selector utils', () => {
145
174
const result3 = keyUpFunction ( previous3 ) ;
146
175
expect ( result3 ) . toBe ( firstMonth ) ;
147
176
} ) ;
148
- it ( 'keyDownMove - maxDate and currentDate in same year - should move up when up arrow key is pressed' , ( ) => {
177
+ it ( 'keyUpMove - maxDate and minDate in same year - should move up when up arrow key is pressed' , ( ) => {
178
+ const maxDate = new Date ( 2023 , 8 , 15 ) ;
179
+ const currentDate = new Date ( 2023 , 8 , 22 ) ;
180
+ const minDate = new Date ( 2023 , 0 , 15 ) ;
181
+
182
+ const keyUpFunction = keyUpMove ( { currentDate, maxDate, minDate } ) ;
183
+
184
+ const previous1 = minDate . getMonth ( ) ;
185
+ const previous2 = minDate . getMonth ( ) + 3 ;
186
+ const previous3 = minDate . getMonth ( ) + 2 ;
187
+ const result1 = keyUpFunction ( previous1 ) ;
188
+ expect ( result1 ) . toBe ( maxDate . getMonth ( ) ) ;
189
+ const result2 = keyUpFunction ( previous2 ) ;
190
+ expect ( result2 ) . toBe ( previous2 - 3 ) ;
191
+ const result3 = keyUpFunction ( previous3 ) ;
192
+ expect ( result3 ) . toBe ( minDate . getMonth ( ) ) ;
193
+ } ) ;
194
+ it ( 'keyDownMove - maxDate and currentDate in same year - should move down when down arrow key is pressed' , ( ) => {
149
195
const maxDate = new Date ( 2023 , 8 , 15 ) ;
150
196
const currentDate = new Date ( 2023 , 8 , 22 ) ;
151
197
const minDate = new Date ( 2000 , 0 , 15 ) ;
@@ -162,7 +208,7 @@ describe('Month Selector utils', () => {
162
208
const result3 = keyDownFunction ( previous3 ) ;
163
209
expect ( result3 ) . toBe ( maxDate . getMonth ( ) ) ;
164
210
} ) ;
165
- it ( 'keyDownMove - minDate and currentDate in same year - should move up when up arrow key is pressed' , ( ) => {
211
+ it ( 'keyDownMove - minDate and currentDate in same year - should move down when down arrow key is pressed' , ( ) => {
166
212
const maxDate = new Date ( 2025 , 8 , 15 ) ;
167
213
const currentDate = new Date ( 2023 , 8 , 22 ) ;
168
214
const minDate = new Date ( 2023 , 0 , 15 ) ;
@@ -179,7 +225,7 @@ describe('Month Selector utils', () => {
179
225
const result3 = keyDownFunction ( previous3 ) ;
180
226
expect ( result3 ) . toBe ( previous3 + 3 ) ;
181
227
} ) ;
182
- it ( 'keyDownMove - currentDate year is different than minDate and maxDate - should move up when up arrow key is pressed' , ( ) => {
228
+ it ( 'keyDownMove - currentDate year is different than minDate and maxDate - should move down when down arrow key is pressed' , ( ) => {
183
229
const maxDate = new Date ( 2025 , 8 , 15 ) ;
184
230
const currentDate = new Date ( 2023 , 8 , 22 ) ;
185
231
const minDate = new Date ( 2000 , 0 , 15 ) ;
@@ -196,6 +242,23 @@ describe('Month Selector utils', () => {
196
242
const result3 = keyDownFunction ( previous3 ) ;
197
243
expect ( result3 ) . toBe ( previous3 + 3 ) ;
198
244
} ) ;
245
+ it ( 'keyDownMove - maxDate and minDate in same year - should move down when down arrow key is pressed' , ( ) => {
246
+ const maxDate = new Date ( 2023 , 8 , 15 ) ;
247
+ const currentDate = new Date ( 2023 , 8 , 22 ) ;
248
+ const minDate = new Date ( 2023 , 0 , 15 ) ;
249
+
250
+ const keyDownFunction = keyDownMove ( { currentDate, maxDate, minDate } ) ;
251
+
252
+ const previous1 = maxDate . getMonth ( ) ;
253
+ const previous2 = 1 ;
254
+ const previous3 = maxDate . getMonth ( ) + 3 ;
255
+ const result1 = keyDownFunction ( previous1 ) ;
256
+ expect ( result1 ) . toBe ( firstMonth ) ;
257
+ const result2 = keyDownFunction ( previous2 ) ;
258
+ expect ( result2 ) . toBe ( previous2 + 3 ) ;
259
+ const result3 = keyDownFunction ( previous3 ) ;
260
+ expect ( result3 ) . toBe ( maxDate . getMonth ( ) ) ;
261
+ } ) ;
199
262
it ( 'keyTabMove - should return previous' , ( ) => {
200
263
const previous = 5 ;
201
264
const result = keyTabMove ( previous ) ;
0 commit comments