Skip to content

Commit

Permalink
prevent frontend errors for escalation email if proctoring is disabled
Browse files Browse the repository at this point in the history
added test

added test
  • Loading branch information
alangsto committed Mar 29, 2021
1 parent 1baeceb commit 0c4e5d7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/proctored-exam-settings/ProctoredExamSettings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) && enableProctoredExams) {
if (proctortrackEscalationEmail === '') {
const errorMessage = intl.formatMessage(messages['authoring.examsettings.escalationemail.error.blank']);

Expand Down
25 changes: 25 additions & 0 deletions src/proctored-exam-settings/ProctoredExamSettings.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,31 @@ describe('ProctoredExamSettings', () => {
expect(document.activeElement).toEqual(escalationEmailInput);
});

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');
Expand Down

0 comments on commit 0c4e5d7

Please sign in to comment.