From 4e609e02e5ac3b8ad4c842fa1a6520ea73964d1b Mon Sep 17 00:00:00 2001 From: Zachary Hancock Date: Thu, 19 Sep 2024 16:03:34 -0400 Subject: [PATCH] feat: improve error message for proctored exam settings (#1300) --- plugins/course-apps/proctoring/Settings.jsx | 54 +++++++++++++------ .../course-apps/proctoring/Settings.test.jsx | 18 +++++++ plugins/course-apps/proctoring/messages.js | 10 ++++ 3 files changed, 67 insertions(+), 15 deletions(-) diff --git a/plugins/course-apps/proctoring/Settings.jsx b/plugins/course-apps/proctoring/Settings.jsx index 4debbcfd7..c4bcec80a 100644 --- a/plugins/course-apps/proctoring/Settings.jsx +++ b/plugins/course-apps/proctoring/Settings.jsx @@ -148,9 +148,9 @@ const ProctoringSettings = ({ intl, onClose }) => { setSaveSuccess(true); setSaveError(false); setSubmissionInProgress(false); - }).catch(() => { + }).catch((error) => { setSaveSuccess(false); - setSaveError(true); + setSaveError(error); setSubmissionInProgress(false); }); } @@ -460,21 +460,32 @@ const ProctoringSettings = ({ intl, onClose }) => { } function renderSaveError() { - return ( - setSaveError(false)} - dismissible - > + let errorMessage = ( + + {intl.formatMessage(messages['authoring.proctoring.support.text'])} + + ), + }} + /> + ); + + if (saveError?.response.status === 403) { + errorMessage = ( { ), }} /> + ); + } + + return ( + setSaveError(false)} + dismissible + > + {errorMessage} ); } diff --git a/plugins/course-apps/proctoring/Settings.test.jsx b/plugins/course-apps/proctoring/Settings.test.jsx index e0e700edc..4edb7f1c2 100644 --- a/plugins/course-apps/proctoring/Settings.test.jsx +++ b/plugins/course-apps/proctoring/Settings.test.jsx @@ -814,6 +814,24 @@ describe('ProctoredExamSettings', () => { }); }); + test('Exams API permission error', async () => { + axiosMock.onPatch( + `${ExamsApiService.getExamsBaseUrl()}/api/v1/configs/course_id/${defaultProps.courseId}`, + ).reply(403, 'error'); + + await act(async () => render(intlWrapper())); + const submitButton = screen.getByTestId('submissionButton'); + fireEvent.click(submitButton); + expect(axiosMock.history.post.length).toBe(1); + await waitFor(() => { + const errorAlert = screen.getByTestId('saveError'); + expect(errorAlert.textContent).toEqual( + expect.stringContaining('You do not have permission to edit proctored exam settings for this course'), + ); + expect(document.activeElement).toEqual(errorAlert); + }); + }); + it('Manages focus correctly after different save statuses', async () => { // first make a call that will cause a save error axiosMock.onPost( diff --git a/plugins/course-apps/proctoring/messages.js b/plugins/course-apps/proctoring/messages.js index 5c9d459fa..82b147fc0 100644 --- a/plugins/course-apps/proctoring/messages.js +++ b/plugins/course-apps/proctoring/messages.js @@ -1,6 +1,16 @@ import { defineMessages } from '@edx/frontend-platform/i18n'; const messages = defineMessages({ + 'authoring.proctoring.alert.error': { + id: 'authoring.proctoring.alert.error', + defaultMessage: 'We encountered a technical error while trying to save proctored exam settings. This might be a temporary issue, so please try again in a few minutes. If the problem persists, please go to the {support_link} for help.', + description: 'Alert message for proctoring settings save error.', + }, + 'authoring.proctoring.alert.forbidden': { + id: 'authoring.proctoring.alert.forbidden', + defaultMessage: 'You do not have permission to edit proctored exam settings for this course. If you are a course team member and this problem persists, please go to the {support_link} for help.', + description: 'Alert message for proctoring settings permission error.', + }, 'authoring.proctoring.no': { id: 'authoring.proctoring.no', defaultMessage: 'No',