Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NOQA] fix unit tests for CalendarPicker #56229

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions tests/unit/CalendarPickerTest.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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');

Expand All @@ -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(
<CalendarPicker
maxDate={maxDate}
Expand All @@ -152,10 +153,11 @@ describe('CalendarPicker', () => {
);

// 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();
});

Expand Down