Skip to content

Commit

Permalink
Add error toast if user is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
EMaksy committed May 13, 2024
1 parent dfcf152 commit 2594639
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion assets/js/pages/Users/EditUserPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ function EditUserPage() {
setUserVersion(etag);
setUser(user);
})
.catch(() => {})
.catch(() => {
toast.error(UNEXPECTED_ERROR_MESSAGE);
})
.finally(() => {
setLoading(false);
});
Expand Down
5 changes: 3 additions & 2 deletions assets/js/pages/Users/EditUserPage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import EditUserPage from './EditUserPage';

const ABILITIES_URL = `/api/v1/abilities`;
const USERS_URL = '/api/v1/users/';
const TOAST_ERROR_MESSAGE = 'Unexpected error occurred, refresh the page';
const axiosMock = new MockAdapter(networkClient);

jest.mock('react-hot-toast', () => ({
Expand Down Expand Up @@ -87,6 +88,7 @@ describe('EditUserPage', () => {
});

await screen.findByText('Not found');
expect(toast.error).toHaveBeenCalledWith(TOAST_ERROR_MESSAGE);
});

it('should edit a user and redirect to users view', async () => {
Expand Down Expand Up @@ -202,7 +204,6 @@ describe('EditUserPage', () => {
});

it('should render toast with an error message when editing a user failed because of a network error', async () => {
const toastMessage = 'Unexpected error occurred, refresh the page';
const user = userEvent.setup();
const userData = userFactory.build();

Expand All @@ -218,6 +219,6 @@ describe('EditUserPage', () => {
});
await screen.findByText('Edit User');
await user.click(screen.getByRole('button', { name: 'Edit' }));
expect(toast.error).toHaveBeenCalledWith(toastMessage);
expect(toast.error).toHaveBeenCalledWith(TOAST_ERROR_MESSAGE);
});
});

0 comments on commit 2594639

Please sign in to comment.