generated from openedx/frontend-template-application
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: error message on reach limit seats in enrollment feature
- Loading branch information
Showing
4 changed files
with
67 additions
and
8 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -5,6 +5,8 @@ import '@testing-library/jest-dom/extend-expect'; | |
|
||
import EnrollStudent from 'features/Classes/EnrollStudent'; | ||
|
||
import * as api from 'features/Students/data/api'; | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
useParams: jest.fn(() => ({ courseName: 'Demo course', className: 'demo class' })), | ||
useLocation: jest.fn().mockReturnValue({ search: '?classId=demo class' }), | ||
|
@@ -39,6 +41,14 @@ describe('EnrollStudent', () => { | |
{ preloadedState: {} }, | ||
); | ||
|
||
const handleEnrollmentsMock = jest.spyOn(api, 'handleEnrollments').mockResolvedValue({ | ||
data: { | ||
results: [{ | ||
tags: 'success', | ||
}], | ||
}, | ||
}); | ||
|
||
const emailInput = getByPlaceholderText('Enter email of the student to enroll'); | ||
fireEvent.change(emailInput, { target: { value: '[email protected]' } }); | ||
|
||
|
@@ -48,5 +58,37 @@ describe('EnrollStudent', () => { | |
await waitFor(() => { | ||
expect(getByText('Email invite has been sent successfully')).toBeInTheDocument(); | ||
}); | ||
|
||
expect(handleEnrollmentsMock).toHaveBeenCalledTimes(1); | ||
handleEnrollmentsMock.mockRestore(); | ||
}); | ||
|
||
test('Should handle form submission and show error toast', async () => { | ||
const onCloseMock = jest.fn(); | ||
|
||
const handleEnrollmentsMock = jest.spyOn(api, 'handleEnrollments').mockResolvedValue({ | ||
data: { | ||
results: [{ tags: 'error', message: 'Enrollment limit reached' }], | ||
}, | ||
}); | ||
|
||
const { getByPlaceholderText, getByText } = renderWithProviders( | ||
<EnrollStudent isOpen onClose={onCloseMock} />, | ||
{ preloadedState: {} }, | ||
); | ||
|
||
const emailInput = getByPlaceholderText('Enter email of the student to enroll'); | ||
fireEvent.change(emailInput, { target: { value: '[email protected]' } }); | ||
|
||
const submitButton = getByText('Send invite'); | ||
fireEvent.click(submitButton); | ||
|
||
await waitFor(() => { | ||
expect(getByText('Enrollment limit reached')).toBeInTheDocument(); | ||
}); | ||
|
||
expect(handleEnrollmentsMock).toHaveBeenCalledTimes(1); | ||
|
||
handleEnrollmentsMock.mockRestore(); | ||
}); | ||
}); |
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
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