Skip to content

Commit 16b292b

Browse files
committed
Add tests for year transitions when navigating months in CalendarPicker
1 parent f62edfe commit 16b292b

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

tests/unit/CalendarPickerTest.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,42 @@ describe('CalendarPicker', () => {
388388
expect(within(screen.getByTestId('currentMonthText')).getByText(monthNames.at(3) ?? '')).toBeTruthy();
389389
});
390390

391+
test('clicking next month arrow in December should update year to next year', () => {
392+
const minDate = new Date('2020-01-01');
393+
const maxDate = new Date('2030-12-31');
394+
const value = '2025-12-15';
395+
render(
396+
<CalendarPicker
397+
value={value}
398+
minDate={minDate}
399+
maxDate={maxDate}
400+
/>,
401+
);
402+
403+
fireEvent.press(screen.getByTestId('next-month-arrow'));
404+
405+
expect(within(screen.getByTestId('currentYearText')).getByText('2026')).toBeTruthy();
406+
expect(screen.getByText(monthNames.at(0) ?? '')).toBeTruthy();
407+
});
408+
409+
test('clicking previous month arrow in January should update year to previous year', () => {
410+
const minDate = new Date('2020-01-01');
411+
const maxDate = new Date('2030-12-31');
412+
const value = '2025-01-15';
413+
render(
414+
<CalendarPicker
415+
value={value}
416+
minDate={minDate}
417+
maxDate={maxDate}
418+
/>,
419+
);
420+
421+
fireEvent.press(screen.getByTestId('prev-month-arrow'));
422+
423+
expect(within(screen.getByTestId('currentYearText')).getByText('2024')).toBeTruthy();
424+
expect(screen.getByText(monthNames.at(11) ?? '')).toBeTruthy();
425+
});
426+
391427
test('month picker filtering should exclude months before minDate', () => {
392428
const currentYear = 2023;
393429
const minDate = new Date('2023-06-01');

0 commit comments

Comments
 (0)