From 3c42deffd27148e263f39c0bae2553a86e8a3c22 Mon Sep 17 00:00:00 2001 From: XnpioChV Date: Mon, 16 Dec 2024 14:37:39 -0500 Subject: [PATCH 1/2] refactor: Update error message while adding library team member --- .../library-team/LibraryTeam.test.tsx | 6 +++--- src/library-authoring/library-team/LibraryTeam.tsx | 11 ++++++++++- src/library-authoring/library-team/messages.ts | 8 ++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/library-authoring/library-team/LibraryTeam.test.tsx b/src/library-authoring/library-team/LibraryTeam.test.tsx index 8e43d0f42..f3ce115e3 100644 --- a/src/library-authoring/library-team/LibraryTeam.test.tsx +++ b/src/library-authoring/library-team/LibraryTeam.test.tsx @@ -183,10 +183,10 @@ describe('', () => { expect(await screen.findByText('Team Member added')).toBeInTheDocument(); }); - it('shows error when user do not exist', async () => { + it('shows error when specific error', async () => { const url = getLibraryTeamApiUrl(libraryId); const axiosMock = new MockAdapter(getAuthenticatedHttpClient()); - axiosMock.onPost(url).reply(400, { email: 'Error' }); + axiosMock.onPost(url).reply(400, { email: 'This is an specific error.' }); await renderLibraryTeam(); @@ -204,7 +204,7 @@ describe('', () => { }); expect(await screen.findByText( - 'Error adding Team Member. Please verify that the email is correct and belongs to a registered user.', + 'Error adding Team Member. This is an specific error.', )).toBeInTheDocument(); }); diff --git a/src/library-authoring/library-team/LibraryTeam.tsx b/src/library-authoring/library-team/LibraryTeam.tsx index 881ce2782..d7f14cbc8 100644 --- a/src/library-authoring/library-team/LibraryTeam.tsx +++ b/src/library-authoring/library-team/LibraryTeam.tsx @@ -68,7 +68,16 @@ const LibraryTeam: React.FC> = () => { }).catch((addMemberError) => { const errorData = typeof addMemberError === 'object' ? addMemberError.response?.data : undefined; if (errorData && 'email' in errorData) { - showToast(intl.formatMessage(messages.addMemberEmailError)); + const errorEmail = errorData.email; + if (typeof errorEmail === 'string') { + showToast(intl.formatMessage(messages.addMemberSpecificError, { + message: errorEmail, + })); + } else { + showToast(intl.formatMessage(messages.addMemberSpecificError, { + message: errorEmail[0], + })); + } } else { showToast(intl.formatMessage(messages.addMemberError)); } diff --git a/src/library-authoring/library-team/messages.ts b/src/library-authoring/library-team/messages.ts index d56d60615..7c4485dd1 100644 --- a/src/library-authoring/library-team/messages.ts +++ b/src/library-authoring/library-team/messages.ts @@ -124,10 +124,10 @@ const messages = defineMessages({ defaultMessage: 'Error adding Team Member', description: 'Message shown when an error occurs while adding a Library Team member', }, - addMemberEmailError: { - id: 'course-authoring.library-authoring.library-team.add-member-email-error', - defaultMessage: 'Error adding Team Member. Please verify that the email is correct and belongs to a registered user.', - description: 'Message shown when an error occurs with email while adding a Library Team member.', + addMemberSpecificError: { + id: 'course-authoring.library-authoring.library-team.add-member-specific-error', + defaultMessage: 'Error adding Team Member. {message}', + description: 'Message shown when an error occurs with an specific error while adding a Library Team member.', }, deleteMemberSuccess: { id: 'course-authoring.library-authoring.library-team.delete-member-success', From 7927ba340e3f32b5af6cd4b4aeb882213d3b90f4 Mon Sep 17 00:00:00 2001 From: XnpioChV Date: Wed, 18 Dec 2024 12:06:13 -0500 Subject: [PATCH 2/2] test: Nits on the code and new tests --- .../library-team/LibraryTeam.test.tsx | 31 +++++++++++++++++-- .../library-team/messages.ts | 2 +- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/library-authoring/library-team/LibraryTeam.test.tsx b/src/library-authoring/library-team/LibraryTeam.test.tsx index f3ce115e3..05f8d1ff5 100644 --- a/src/library-authoring/library-team/LibraryTeam.test.tsx +++ b/src/library-authoring/library-team/LibraryTeam.test.tsx @@ -183,10 +183,10 @@ describe('', () => { expect(await screen.findByText('Team Member added')).toBeInTheDocument(); }); - it('shows error when specific error', async () => { + it('shows error when specific error (string)', async () => { const url = getLibraryTeamApiUrl(libraryId); const axiosMock = new MockAdapter(getAuthenticatedHttpClient()); - axiosMock.onPost(url).reply(400, { email: 'This is an specific error.' }); + axiosMock.onPost(url).reply(400, { email: 'This is a specific error.' }); await renderLibraryTeam(); @@ -204,7 +204,32 @@ describe('', () => { }); expect(await screen.findByText( - 'Error adding Team Member. This is an specific error.', + 'Error adding Team Member. This is a specific error.', + )).toBeInTheDocument(); + }); + + it('shows error when specific error (Array)', async () => { + const url = getLibraryTeamApiUrl(libraryId); + const axiosMock = new MockAdapter(getAuthenticatedHttpClient()); + axiosMock.onPost(url).reply(400, { email: ['This is a specific 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, 'another@user.tld'); + + 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. This is a specific error.', )).toBeInTheDocument(); }); diff --git a/src/library-authoring/library-team/messages.ts b/src/library-authoring/library-team/messages.ts index 7c4485dd1..32623b237 100644 --- a/src/library-authoring/library-team/messages.ts +++ b/src/library-authoring/library-team/messages.ts @@ -127,7 +127,7 @@ const messages = defineMessages({ addMemberSpecificError: { id: 'course-authoring.library-authoring.library-team.add-member-specific-error', defaultMessage: 'Error adding Team Member. {message}', - description: 'Message shown when an error occurs with an specific error while adding a Library Team member.', + description: 'Message shown when an error occurs while adding a Library Team member, including a specific error message.', }, deleteMemberSuccess: { id: 'course-authoring.library-authoring.library-team.delete-member-success',