-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Update error messages when adding user to library (backport) (#1543
) (#1550) Updates the message error when the user doesn't exist when adding a new team member to a library.
- Loading branch information
Showing
6 changed files
with
79 additions
and
19 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import { | |
getLibraryTeamMemberApiUrl, | ||
} from '../data/api'; | ||
import { LibraryProvider } from '../common/context'; | ||
import { ToastProvider } from '../../generic/toast-context'; | ||
import LibraryTeam from './LibraryTeam'; | ||
|
||
mockContentLibrary.applyMock(); | ||
|
@@ -28,9 +29,11 @@ describe('<LibraryTeam />', () => { | |
const { libraryId } = mockContentLibrary; | ||
const renderLibraryTeam = async () => { | ||
render( | ||
<LibraryProvider libraryId={libraryId}> | ||
<LibraryTeam /> | ||
</LibraryProvider>, | ||
<ToastProvider> | ||
<LibraryProvider libraryId={libraryId}> | ||
<LibraryTeam /> | ||
</LibraryProvider> | ||
</ToastProvider>, | ||
); | ||
|
||
await waitFor(() => { | ||
|
@@ -176,6 +179,56 @@ describe('<LibraryTeam />', () => { | |
`{"library_id":"${libraryId}","email":"[email protected]","access_level":"read"}`, | ||
); | ||
}); | ||
|
||
expect(await screen.findByText('Team Member added')).toBeInTheDocument(); | ||
}); | ||
|
||
it('shows error when user do not exist', async () => { | ||
const url = getLibraryTeamApiUrl(libraryId); | ||
const axiosMock = new MockAdapter(getAuthenticatedHttpClient()); | ||
axiosMock.onPost(url).reply(400, { email: 'Error' }); | ||
|
||
await renderLibraryTeam(); | ||
|
||
const addButton = screen.getByRole('button', { name: 'New team member' }); | ||
userEvent.click(addButton); | ||
const emailInput = screen.getByRole('textbox', { name: 'User\'s email address' }); | ||
userEvent.click(emailInput); | ||
userEvent.type(emailInput, '[email protected]'); | ||
|
||
const saveButton = screen.getByRole('button', { name: /add member/i }); | ||
userEvent.click(saveButton); | ||
|
||
await waitFor(() => { | ||
expect(axiosMock.history.post.length).toEqual(1); | ||
}); | ||
|
||
expect(await screen.findByText( | ||
'Error adding Team Member. Please verify that the email is correct and belongs to a registered user.', | ||
)).toBeInTheDocument(); | ||
}); | ||
|
||
it('shows error', async () => { | ||
const url = getLibraryTeamApiUrl(libraryId); | ||
const axiosMock = new MockAdapter(getAuthenticatedHttpClient()); | ||
axiosMock.onPost(url).reply(400, {}); | ||
|
||
await renderLibraryTeam(); | ||
|
||
const addButton = screen.getByRole('button', { name: 'New team member' }); | ||
userEvent.click(addButton); | ||
const emailInput = screen.getByRole('textbox', { name: 'User\'s email address' }); | ||
userEvent.click(emailInput); | ||
userEvent.type(emailInput, '[email protected]'); | ||
|
||
const saveButton = screen.getByRole('button', { name: /add member/i }); | ||
userEvent.click(saveButton); | ||
|
||
await waitFor(() => { | ||
expect(axiosMock.history.post.length).toEqual(1); | ||
}); | ||
|
||
expect(await screen.findByText('Error adding Team Member')).toBeInTheDocument(); | ||
}); | ||
|
||
it('allows library team member roles to be changed', async () => { | ||
|
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