From 5bfc60871e734497fb6b39377ad284541d6b4030 Mon Sep 17 00:00:00 2001 From: Github Date: Mon, 3 Feb 2025 10:13:29 +0100 Subject: [PATCH] fix unit tests for CalendarPicker --- tests/unit/CalendarPickerTest.tsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/unit/CalendarPickerTest.tsx b/tests/unit/CalendarPickerTest.tsx index 5e6dbaf26ce0..f7bee25e366f 100644 --- a/tests/unit/CalendarPickerTest.tsx +++ b/tests/unit/CalendarPickerTest.tsx @@ -1,5 +1,5 @@ import type ReactNavigationNative from '@react-navigation/native'; -import {fireEvent, render, screen, within} from '@testing-library/react-native'; +import {fireEvent, render, screen, userEvent, within} from '@testing-library/react-native'; import {addMonths, addYears, subMonths, subYears} from 'date-fns'; import type {ComponentType} from 'react'; import CalendarPicker from '@components/DatePicker/CalendarPicker'; @@ -121,7 +121,7 @@ describe('CalendarPicker', () => { expect(onSelectedMock).toHaveBeenCalledWith('2022-02-15'); }); - test('should block the back arrow when there is no available dates in the previous month', () => { + test('should block the back arrow when there is no available dates in the previous month', async () => { const minDate = new Date('2003-02-01'); const value = new Date('2003-02-17'); @@ -134,16 +134,17 @@ describe('CalendarPicker', () => { ); // When the previous month arrow is pressed - fireEvent.press(screen.getByTestId('prev-month-arrow')); + const user = userEvent.setup(); + await user.press(screen.getByTestId('prev-month-arrow')); // Then the previous month should not be called as the previous month button is disabled - const prevMonth = subMonths(new Date(), 1).getMonth(); + const prevMonth = subMonths(value, 1).getMonth(); expect(screen.queryByText(monthNames.at(prevMonth) ?? '')).not.toBeOnTheScreen(); }); - test('should block the next arrow when there is no available dates in the next month', () => { + test('should block the next arrow when there is no available dates in the next month', async () => { const maxDate = new Date('2003-02-24'); - const value = '2003-02-17'; + const value = new Date('2003-02-17'); render( { ); // When the next month arrow is pressed - fireEvent.press(screen.getByTestId('next-month-arrow')); + const user = userEvent.setup(); + await user.press(screen.getByTestId('next-month-arrow')); // Then the next month should not be called as the next month button is disabled - const nextMonth = addMonths(new Date(), 1).getMonth(); + const nextMonth = addMonths(value, 1).getMonth(); expect(screen.queryByText(monthNames.at(nextMonth) ?? '')).not.toBeOnTheScreen(); });