-
-
Notifications
You must be signed in to change notification settings - Fork 811
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
120 additions
and
83 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
import React from 'react'; | ||
import { | ||
fireEvent, | ||
queryByLabelText, | ||
render, | ||
waitFor, | ||
} from '@testing-library/react'; | ||
import { fireEvent, render, waitFor } from '@testing-library/react'; | ||
import { MockedProvider } from '@apollo/react-testing'; | ||
import { EventRegistrantsModal } from './EventRegistrantsModal'; | ||
import { EVENT_ATTENDEES, MEMBERS_LIST } from 'GraphQl/Queries/Queries'; | ||
|
@@ -46,7 +41,19 @@ const queryMockWithRegistrant = [ | |
result: { | ||
data: { | ||
event: { | ||
attendees: [{ _id: 'user1', firstName: 'John', lastName: 'Doe' }], | ||
attendees: [ | ||
{ | ||
_id: 'user1', | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
createdAt: '2023-01-01', | ||
gender: 'Male', | ||
birthDate: '1990-01-01', | ||
eventsAttended: { | ||
_id: 'event123', | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
|
@@ -69,9 +76,9 @@ const queryMockOrgMembers = [ | |
_id: 'user1', | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
email: '[email protected]', | ||
image: '', | ||
createdAt: '12/12/22', | ||
image: null, | ||
email: '[email protected]', | ||
createdAt: '2023-01-01', | ||
organizationsBlockedBy: [], | ||
}, | ||
], | ||
|
@@ -81,6 +88,24 @@ const queryMockOrgMembers = [ | |
}, | ||
}, | ||
]; | ||
const queryMockWithoutOrgMembers = [ | ||
{ | ||
request: { | ||
query: MEMBERS_LIST, | ||
variables: { id: 'org123' }, | ||
}, | ||
result: { | ||
data: { | ||
organizations: [ | ||
{ | ||
_id: 'org123', | ||
members: [], | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
const successfulAddRegistrantMock = [ | ||
{ | ||
|
@@ -180,19 +205,18 @@ describe('Testing Event Registrants Modal', () => { | |
|
||
await waitFor(() => | ||
expect( | ||
queryByText('Please choose a user to add first!'), | ||
queryByText('Please choose an user to add first!'), | ||
).toBeInTheDocument(), | ||
); | ||
|
||
// Choose a user to add as an attendee | ||
const attendeeInput = queryByLabelText('Add a Registrant'); | ||
if (attendeeInput) { | ||
fireEvent.change(attendeeInput, { | ||
target: { value: 'John Doe' }, | ||
}); | ||
fireEvent.keyDown(attendeeInput, { key: 'ArrowDown' }); | ||
fireEvent.keyDown(attendeeInput, { key: 'Enter' }); | ||
} | ||
const attendeeInput = queryByLabelText('Add an Registrant'); | ||
fireEvent.change(attendeeInput as Element, { | ||
target: { value: 'John Doe' }, | ||
}); | ||
fireEvent.keyDown(attendeeInput as HTMLElement, { key: 'ArrowDown' }); | ||
fireEvent.keyDown(attendeeInput as HTMLElement, { key: 'Enter' }); | ||
|
||
fireEvent.click(queryByText('Add Registrant') as Element); | ||
|
||
await waitFor(() => | ||
|
@@ -234,7 +258,7 @@ describe('Testing Event Registrants Modal', () => { | |
); | ||
|
||
// Choose a user to add as an attendee | ||
const attendeeInput = queryByLabelText('Add a Registrant'); | ||
const attendeeInput = queryByLabelText('Add an Registrant'); | ||
fireEvent.change(attendeeInput as Element, { | ||
target: { value: 'John Doe' }, | ||
}); | ||
|
@@ -293,7 +317,7 @@ describe('Testing Event Registrants Modal', () => { | |
}); | ||
|
||
test('Delete attendee mutation must fail properly', async () => { | ||
const { queryByText, getByLabelText } = render( | ||
const { queryByText, getByTestId } = render( | ||
<MockedProvider | ||
addTypename={false} | ||
mocks={[ | ||
|
@@ -321,7 +345,7 @@ describe('Testing Event Registrants Modal', () => { | |
|
||
await waitFor(() => expect(queryByText('John Doe')).toBeInTheDocument()); | ||
|
||
const deleteButton = getByLabelText('Delete'); | ||
const deleteButton = getByTestId('CancelIcon'); | ||
fireEvent.click(deleteButton); | ||
|
||
await waitFor(() => | ||
|
@@ -332,4 +356,48 @@ describe('Testing Event Registrants Modal', () => { | |
expect(queryByText('Error removing attendee')).toBeInTheDocument(), | ||
); | ||
}); | ||
test('Autocomplete functionality works correctly', async () => { | ||
const { getByTitle, getByText, getByPlaceholderText } = render( | ||
<MockedProvider | ||
addTypename={false} | ||
mocks={[...queryMockWithoutRegistrant, ...queryMockWithoutOrgMembers]} | ||
> | ||
<BrowserRouter> | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<Provider store={store}> | ||
<I18nextProvider i18n={i18nForTest}> | ||
<ToastContainer /> | ||
<EventRegistrantsModal {...props} /> | ||
</I18nextProvider> | ||
</Provider> | ||
</LocalizationProvider> | ||
</BrowserRouter> | ||
</MockedProvider>, | ||
); | ||
|
||
// Wait for loading state to finish | ||
await waitFor(() => { | ||
const autocomplete = getByPlaceholderText( | ||
'Choose the user that you want to add', | ||
); | ||
expect(autocomplete).toBeInTheDocument(); | ||
}); | ||
|
||
// Test empty state with no options | ||
const autocomplete = getByPlaceholderText( | ||
'Choose the user that you want to add', | ||
); | ||
fireEvent.change(autocomplete, { target: { value: 'NonexistentUser' } }); | ||
|
||
await waitFor(() => { | ||
expect(getByText('No Registrations found')).toBeInTheDocument(); | ||
expect(getByText('Add Onspot Registration')).toBeInTheDocument(); | ||
}); | ||
|
||
// Test clicking "Add Onspot Registration" | ||
fireEvent.click(getByText('Add Onspot Registration')); | ||
expect(getByText('Add Onspot Registration')).toBeInTheDocument(); | ||
const closeButton = getByTitle('Close'); | ||
fireEvent.click(closeButton); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters