Skip to content

Commit

Permalink
added test cases in src/components/EventRegistrantsModal/AddOnSpotAtt…
Browse files Browse the repository at this point in the history
…endee.tsx (#3145)
  • Loading branch information
syedali237 authored Jan 4, 2025
1 parent 9fa14a6 commit 99648a9
Showing 1 changed file with 77 additions and 11 deletions.
88 changes: 77 additions & 11 deletions src/components/EventRegistrantsModal/AddOnSpotAttendee.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,86 @@ describe('AddOnSpotAttendee Component', () => {
expect(screen.getByLabelText('Gender')).toBeInTheDocument();
});

it('handles form input changes correctly', async () => {
renderAddOnSpotAttendee();
it('handles case where signUp response is undefined', async () => {
const mockWithoutSignUp = [
{
request: {
query: SIGNUP_MUTATION,
variables: {
firstName: 'John',
lastName: 'Doe',
email: '[email protected]',
phoneNo: '1234567890',
gender: 'Male',
password: '123456',
orgId: '123',
},
},
result: {
data: {}, // No signUp property
},
},
];

render(
<MockedProvider mocks={mockWithoutSignUp} addTypename={false}>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<BrowserRouter>
<AddOnSpotAttendee {...mockProps} />
</BrowserRouter>
</I18nextProvider>
</Provider>
</MockedProvider>,
);

userEvent.type(screen.getByLabelText('First Name'), 'John');
userEvent.type(screen.getByLabelText('Last Name'), 'Doe');
userEvent.type(screen.getByLabelText('Email'), '[email protected]');
userEvent.type(screen.getByLabelText('Phone No.'), '1234567890');
const genderSelect = screen.getByLabelText('Gender');
fireEvent.change(genderSelect, { target: { value: 'Male' } });

fireEvent.submit(screen.getByTestId('onspot-attendee-form'));

const firstNameInput = screen.getByLabelText('First Name');
const lastNameInput = screen.getByLabelText('Last Name');
const emailInput = screen.getByLabelText('Email');
await waitFor(() => {
expect(toast.success).not.toHaveBeenCalled(); // Ensure success toast is not shown
expect(toast.error).not.toHaveBeenCalled(); // Ensure no unexpected error toast
expect(mockProps.reloadMembers).not.toHaveBeenCalled(); // Reload should not be triggered
expect(mockProps.handleClose).not.toHaveBeenCalled(); // Modal should not close
});
});

userEvent.type(firstNameInput, 'John');
userEvent.type(lastNameInput, 'Doe');
userEvent.type(emailInput, '[email protected]');
it('handles error during form submission', async () => {
render(
<MockedProvider mocks={ERROR_MOCKS} addTypename={false}>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<BrowserRouter>
<AddOnSpotAttendee {...mockProps} />
</BrowserRouter>
</I18nextProvider>
</Provider>
</MockedProvider>,
);

// Fill the form
userEvent.type(screen.getByLabelText('First Name'), 'John');
userEvent.type(screen.getByLabelText('Last Name'), 'Doe');
userEvent.type(screen.getByLabelText('Email'), '[email protected]');
userEvent.type(screen.getByLabelText('Phone No.'), '1234567890');
const genderSelect = screen.getByLabelText('Gender');
fireEvent.change(genderSelect, { target: { value: 'Male' } });

// Submit the form
fireEvent.submit(screen.getByTestId('onspot-attendee-form'));

expect(firstNameInput).toHaveValue('John');
expect(lastNameInput).toHaveValue('Doe');
expect(emailInput).toHaveValue('[email protected]');
// Wait for the error to be handled
await waitFor(() => {
expect(toast.error).toHaveBeenCalledWith(
expect.stringContaining('Failed to add attendee'),
);
});
});

it('submits form successfully and calls necessary callbacks', async () => {
Expand Down

0 comments on commit 99648a9

Please sign in to comment.