Skip to content

Commit

Permalink
add change date ranges and save tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jiji14 committed Jun 6, 2024
1 parent 4e8101a commit ae6fc3f
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions www/__tests__/DateSelect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { render, screen, fireEvent, waitFor } from '@testing-library/react-nativ
import DateSelect from '../js/diary/list/DateSelect';
import { DateTime } from 'luxon';
import TimelineContext from '../js/TimelineContext';
import initializedI18next from '../js/i18nextInit';
window['i18next'] = initializedI18next;

jest.mock('react-native-safe-area-context', () => ({
useSafeAreaInsets: () => ({ bottom: 30, left: 0, right: 0, top: 30 }),
Expand All @@ -17,20 +19,24 @@ jest.mock('react', () => ({
describe('DateSelect', () => {
const pipelineRangeMock = {
start_ts: DateTime.local().set({ month: 5, day: 20 }).startOf('day').toSeconds(),
end_ts: DateTime.local().set({ month: 5, day: 30 }).endOf('day').toSeconds(),
end_ts: DateTime.local()
.set({ month: 5, day: 30 })
.endOf('day')
.set({ millisecond: 0 })
.toSeconds(),
};

const queriedDateRangeMock = [
DateTime.local().set({ month: 5, day: 20 }).startOf('day').toISO(),
DateTime.local().set({ month: 5, day: 30 }).endOf('day').toISO(),
DateTime.local().set({ month: 5, day: 30 }).endOf('day').set({ millisecond: 0 }).toISO(),
];

const contextValue = {
pipelineRange: pipelineRangeMock,
queriedDateRange: queriedDateRangeMock,
};

it('renders correctly DatePickerModal after clicking the button', async () => {
it('renders correctly DatePickerModal after clicking the button and save date correctly', async () => {
const onChooseMock = jest.fn();
render(
<TimelineContext.Provider value={contextValue}>
Expand All @@ -49,5 +55,27 @@ describe('DateSelect', () => {
expect(screen.getByTestId('react-native-paper-dates-close')).toBeTruthy();
expect(screen.getByTestId('react-native-paper-dates-save-text')).toBeTruthy();
});

// check if date changes corretly
// Start Date : 05/20/24 -> 05/25/2024
fireEvent.changeText(screen.getAllByTestId('text-input-flat')[0], '05/25/2024');
expect(screen.queryByDisplayValue('May 20')).toBeNull();
expect(screen.getByText('May 25')).toBeTruthy();
// End Date : 05/30/24 -> 05/28/2024
fireEvent.changeText(screen.getAllByTestId('text-input-flat')[1], '05/28/2024');
expect(screen.queryByDisplayValue('May 30')).toBeNull();
expect(screen.getByText('May 28')).toBeTruthy();

// check if onChoose function gets called with changed dates after clicking 'save' button.
fireEvent.press(screen.getByTestId('react-native-paper-dates-save-text'));
const expectedParams = {
startDate: DateTime.local().set({ month: 5, day: 25 }).startOf('day').toJSDate(),
endDate: DateTime.local()
.set({ month: 5, day: 28 })
.endOf('day')
.set({ millisecond: 0 })
.toJSDate(),
};
expect(onChooseMock).toHaveBeenCalledWith(expectedParams);
});
});

0 comments on commit ae6fc3f

Please sign in to comment.