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

Improve Code Coverage in src\components\RecurrenceOptions\CustomRecurrenceModal.tsx #3510

Merged
Merged
Show file tree
Hide file tree
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
75 changes: 75 additions & 0 deletions src/components/RecurrenceOptions/CustomRecurrence.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,81 @@ describe('Testing the creaction of recurring events with custom recurrence patte
});
});

test('Selecting invalid/null as date value for End date option ', async () => {
// When an invalid date or null value is pushed to the data picker, no state should be changed
// Covers the else path at line 380

render(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<Provider store={store}>
<LocalizationProvider dateAdapter={AdapterDayjs}>
<ThemeProvider theme={theme}>
<I18nextProvider i18n={i18nForTest}>
<OrganizationEvents />
</I18nextProvider>
</ThemeProvider>
</LocalizationProvider>
</Provider>
</BrowserRouter>
</MockedProvider>,
);

await wait();

await waitFor(() => {
expect(screen.getByTestId('createEventModalBtn')).toBeInTheDocument();
});

userEvent.click(screen.getByTestId('createEventModalBtn'));

await waitFor(() => {
expect(screen.getByTestId('recurringCheck')).toBeInTheDocument();
});

expect(screen.queryByTestId('recurrenceOptions')).not.toBeInTheDocument();

userEvent.click(screen.getByTestId('recurringCheck'));

await waitFor(() => {
expect(screen.getByTestId('recurrenceOptions')).toBeInTheDocument();
});

userEvent.click(screen.getByTestId('recurrenceOptions'));

await waitFor(() => {
expect(screen.getByTestId('customRecurrence')).toBeInTheDocument();
});

userEvent.click(screen.getByTestId('customRecurrence'));

await waitFor(() => {
expect(screen.getByTestId('never')).toBeInTheDocument();
});

userEvent.click(screen.getByTestId('on'));

await waitFor(() => {
expect(screen.getByTestId('on')).toBeChecked();
});

await waitFor(() => {
expect(screen.getAllByLabelText('End Date')[1]).toBeEnabled();
});

const recurrenceEndDatePicker = screen.getAllByLabelText('End Date')[1];
fireEvent.change(recurrenceEndDatePicker, {
target: { value: null },
});

userEvent.click(screen.getByTestId('customRecurrenceSubmitBtn'));
await waitFor(() => {
expect(
screen.queryByTestId('customRecurrenceSubmitBtn'),
).not.toBeInTheDocument();
});
});

test('Selecting the "Ends on" option for specifying the end of recurrence', async () => {
// i.e. when would the recurring event end: never, on a certain date, or after a certain number of occurences
render(
Expand Down
3 changes: 1 addition & 2 deletions src/components/RecurrenceOptions/CustomRecurrenceModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const CustomRecurrenceModal: React.FC<InterfaceCustomRecurrenceModalProps> = ({
} else {
setRecurrenceRuleState({
...recurrenceRuleState,
weekDays: [...(weekDays ?? []), day],
weekDays: [...weekDays, day],
weekDayOccurenceInMonth: undefined,
});
}
Expand Down Expand Up @@ -376,7 +376,6 @@ const CustomRecurrenceModal: React.FC<InterfaceCustomRecurrenceModalProps> = ({
recurrenceEndDate ?? dayjs().add(1, 'month'),
)}
onChange={(date: Dayjs | null): void => {
/* istanbul ignore next */
if (date) {
setRecurrenceRuleState({
...recurrenceRuleState,
Expand Down