-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3864 from opengovsg/form-v2/feat/refactor-collab-…
…error-messages feat(v2): add clearer error messages when updating collaborators
- Loading branch information
Showing
4 changed files
with
161 additions
and
7 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
35 changes: 35 additions & 0 deletions
35
...nd/src/features/admin-form/common/components/CollaboratorModal/CollaboratorModal.test.tsx
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { composeStories } from '@storybook/testing-react' | ||
import { act, render, screen, waitFor } from '@testing-library/react' | ||
import userEvent from '@testing-library/user-event' | ||
|
||
import * as stories from './CollaboratorModal.stories' | ||
|
||
const { EditCollaboratorBadRequestError } = composeStories(stories) | ||
|
||
describe('400 bad request error', () => { | ||
it('should throw the appropriate 400 error message when user attempts to add collaborator', async () => { | ||
await act(async () => { | ||
render(<EditCollaboratorBadRequestError />) | ||
}) | ||
|
||
// Wait until msw has fetched all the necessary resources | ||
await waitFor(() => | ||
expect(screen.getByText(/manage collaborators/i)).toBeVisible(), | ||
) | ||
|
||
const input = screen.getByPlaceholderText(/me@example.com/i) | ||
const submitButton = screen.getByRole('button', { | ||
name: /add collaborator/i, | ||
}) | ||
const mockEmail = '[email protected]' | ||
|
||
await act(async () => userEvent.type(input, mockEmail)) | ||
await act(async () => userEvent.click(submitButton)) | ||
|
||
await screen.findByRole('alert') | ||
|
||
expect(screen.getByRole('alert').textContent).toBe( | ||
'The collaborator was unable to be added or edited. Please try again or refresh the page.', | ||
) | ||
}) | ||
}) |
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