From 01208a9f9a1d38c9ccf04a354205ed99c2a40ff4 Mon Sep 17 00:00:00 2001 From: alangsto <46360176+alangsto@users.noreply.github.com> Date: Tue, 30 Mar 2021 09:34:55 -0400 Subject: [PATCH] prevent frontend errors for escalation email if proctoring is disabled (#61) --- .../ProctoredExamSettings.jsx | 4 +- .../ProctoredExamSettings.test.jsx | 47 +++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/proctored-exam-settings/ProctoredExamSettings.jsx b/src/proctored-exam-settings/ProctoredExamSettings.jsx index d7eb93824..b60750587 100644 --- a/src/proctored-exam-settings/ProctoredExamSettings.jsx +++ b/src/proctored-exam-settings/ProctoredExamSettings.jsx @@ -108,7 +108,7 @@ function ProctoredExamSettings({ courseId, intl }) { function handleSubmit(event) { event.preventDefault(); - if (proctoringProvider === 'proctortrack' && !EmailValidator.validate(proctortrackEscalationEmail)) { + if (proctoringProvider === 'proctortrack' && !EmailValidator.validate(proctortrackEscalationEmail) && !(proctortrackEscalationEmail === '' && !enableProctoredExams)) { if (proctortrackEscalationEmail === '') { const errorMessage = intl.formatMessage(messages['authoring.examsettings.escalationemail.error.blank']); @@ -192,7 +192,7 @@ function ProctoredExamSettings({ courseId, intl }) { function renderContent() { return (
- {enableProctoredExams && !formStatus.isValid && formStatus.errors.formProctortrackEscalationEmail + {!formStatus.isValid && formStatus.errors.formProctortrackEscalationEmail && ( // tabIndex="-1" to make non-focusable element focusable { expect(document.activeElement).toEqual(escalationEmailInput); }); + it('Creates an alert when invalid proctoring escalation email is provided with proctoring disabled', async () => { + await waitFor(() => { + screen.getByDisplayValue('proctortrack'); + }); + const selectEscalationEmailElement = screen.getByDisplayValue('test@example.com'); + await act(async () => { + fireEvent.change(selectEscalationEmailElement, { target: { value: 'foo.bar' } }); + }); + const enableProctoringElement = screen.getByLabelText('Enable Proctored Exams'); + await act(async () => fireEvent.click(enableProctoringElement)); + const selectButton = screen.getByTestId('submissionButton'); + await act(async () => { + fireEvent.click(selectButton); + }); + + // verify alert content and focus management + const escalationEmailError = screen.getByTestId('proctortrackEscalationEmailError'); + expect(document.activeElement).toEqual(escalationEmailError); + expect(escalationEmailError.textContent).not.toBeNull(); + expect(document.activeElement).toEqual(escalationEmailError); + }); + + it('Has no error when invalid proctoring escalation email is provided with proctoring disabled', async () => { + await waitFor(() => { + screen.getByDisplayValue('proctortrack'); + }); + const selectEscalationEmailElement = screen.getByDisplayValue('test@example.com'); + await act(async () => { + fireEvent.change(selectEscalationEmailElement, { target: { value: '' } }); + }); + const enableProctoringElement = screen.getByLabelText('Enable Proctored Exams'); + await act(async () => fireEvent.click(enableProctoringElement)); + const selectButton = screen.getByTestId('submissionButton'); + await act(async () => { + fireEvent.click(selectButton); + }); + + // verify there is no escalation email alert, and focus has been set on save success alert + expect(screen.queryByTestId('proctortrackEscalationEmailError')).toBeNull(); + + const errorAlert = screen.getByTestId('saveSuccess'); + expect(errorAlert.textContent).toEqual( + expect.stringContaining('Proctored exam settings saved successfully.'), + ); + expect(document.activeElement).toEqual(errorAlert); + }); + it('Has no error when valid proctoring escalation email is provided with proctortrack selected', async () => { await waitFor(() => { screen.getByDisplayValue('proctortrack');