prevent frontend errors for escalation email if proctoring is disabled (#61)

This commit is contained in:
alangsto
2021-03-30 09:34:55 -04:00
committed by GitHub
parent d76d9c100d
commit 01208a9f9a
2 changed files with 49 additions and 2 deletions

View File

@@ -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 (
<Form onSubmit={handleSubmit} data-test-id="proctoringForm">
{enableProctoredExams && !formStatus.isValid && formStatus.errors.formProctortrackEscalationEmail
{!formStatus.isValid && formStatus.errors.formProctortrackEscalationEmail
&& (
// tabIndex="-1" to make non-focusable element focusable
<Alert

View File

@@ -238,6 +238,53 @@ describe('ProctoredExamSettings', () => {
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');