diff --git a/src/proctored-exam-settings/ProctoredExamSettings.jsx b/src/proctored-exam-settings/ProctoredExamSettings.jsx index adceac95f..5dc05e923 100644 --- a/src/proctored-exam-settings/ProctoredExamSettings.jsx +++ b/src/proctored-exam-settings/ProctoredExamSettings.jsx @@ -107,6 +107,7 @@ function ExamSettings(props) { key={provider} value={provider} disabled={isDisabledOption(provider)} + data-test-id={provider} > {provider} @@ -119,7 +120,12 @@ function ExamSettings(props) { {proctortrackEscalationEmailError && ( // tabIndex="-1" to make non-focusable element focusable - + {proctortrackEscalationEmailError} )} diff --git a/src/proctored-exam-settings/ProctoredExamSettings.test.jsx b/src/proctored-exam-settings/ProctoredExamSettings.test.jsx index 819a6013e..9b4875e32 100644 --- a/src/proctored-exam-settings/ProctoredExamSettings.test.jsx +++ b/src/proctored-exam-settings/ProctoredExamSettings.test.jsx @@ -11,25 +11,25 @@ const defaultProps = { }; describe('ProctoredExamSettings check default on create zendesk ticket field tests', () => { - auth.getAuthenticatedHttpClient = jest.fn(() => ({ - get: async () => ({ - data: { - proctored_exam_settings: { - enable_proctored_exams: true, - allow_proctoring_opt_out: false, - proctoring_provider: 'mockproc', - proctoring_escalation_email: 'test@example.com', - create_zendesk_tickets: true, - }, - available_proctoring_providers: ['software_secure', 'proctortrack', 'mockproc'], - }, - catch: () => {}, - }), - })); - - auth.getAuthenticatedUser = jest.fn(() => ({ userId: 3 })); - beforeEach(async () => { + auth.getAuthenticatedHttpClient = jest.fn(() => ({ + get: async () => ({ + data: { + proctored_exam_settings: { + enable_proctored_exams: true, + allow_proctoring_opt_out: false, + proctoring_provider: 'mockproc', + proctoring_escalation_email: 'test@example.com', + create_zendesk_tickets: true, + }, + available_proctoring_providers: ['software_secure', 'proctortrack', 'mockproc'], + course_start_date: '2070-01-01T00:00:00Z', + }, + catch: () => {}, + }), + })); + + auth.getAuthenticatedUser = jest.fn(() => ({ userId: 3, administrator: false })); await act(async () => render()); }); @@ -74,6 +74,152 @@ describe('ProctoredExamSettings check default on create zendesk ticket field tes }); }); +describe('ProctoredExamSettings alert with invalid escalation email', () => { + beforeEach(async () => { + auth.getAuthenticatedHttpClient = jest.fn(() => ({ + get: async () => ({ + data: { + proctored_exam_settings: { + enable_proctored_exams: true, + allow_proctoring_opt_out: false, + proctoring_provider: 'proctortrack', + proctoring_escalation_email: 'test@example.com', + create_zendesk_tickets: true, + }, + available_proctoring_providers: ['software_secure', 'proctortrack', 'mockproc'], + course_start_date: '2070-01-01T00:00:00Z', + }, + catch: () => {}, + }), + })); + + auth.getAuthenticatedUser = jest.fn(() => ({ userId: 3, administrator: false })); + await act(async () => render()); + }); + + afterEach(() => { + cleanup(); + }); + + it('creates an alert when no proctoring escalation email is provided with proctortrack selected', async () => { + await waitFor(() => { + screen.getByDisplayValue('proctortrack'); + }); + const selectEscalationEmailElement = screen.getByDisplayValue('test@example.com'); + await act(async () => { + fireEvent.change(selectEscalationEmailElement, { target: { value: '' } }); + }); + const selectButton = screen.getByTestId('submissionButton'); + await act(async () => { + fireEvent.click(selectButton); + }); + const escalationEmailError = screen.getByTestId('proctortrackEscalationEmailError'); + expect(escalationEmailError.textContent).not.toBeNull(); + }); + + it('creates an alert when invalid proctoring escalation email is provided with proctortrack selected', async () => { + await waitFor(() => { + screen.getByDisplayValue('proctortrack'); + }); + const selectEscalationEmailElement = screen.getByDisplayValue('test@example.com'); + await act(async () => { + fireEvent.change(selectEscalationEmailElement, { target: { value: 'foo.bar' } }); + }); + const selectButton = screen.getByTestId('submissionButton'); + await act(async () => { + fireEvent.click(selectButton); + }); + const escalationEmailError = screen.getByTestId('proctortrackEscalationEmailError'); + expect(escalationEmailError.textContent).not.toBeNull(); + }); + + it('has no error when valid proctoring escalation email is provided with proctortrack selected', async () => { + await waitFor(() => { + screen.getByDisplayValue('proctortrack'); + }); + const selectEscalationEmailElement = screen.getByDisplayValue('test@example.com'); + await act(async () => { + fireEvent.change(selectEscalationEmailElement, { target: { value: 'foo@bar.com' } }); + }); + const selectButton = screen.getByTestId('submissionButton'); + await act(async () => { + fireEvent.click(selectButton); + }); + const escalationEmailError = screen.queryByTestId('proctortrackEscalationEmailError'); + expect(escalationEmailError).toBeNull(); + }); +}); + +describe('Disables proctoring provider options', () => { + const mockGetFutureCourseData = { + data: { + proctored_exam_settings: { + enable_proctored_exams: true, + allow_proctoring_opt_out: false, + proctoring_provider: 'mockproc', + proctoring_escalation_email: 'test@example.com', + create_zendesk_tickets: true, + }, + available_proctoring_providers: ['software_secure', 'proctortrack', 'mockproc'], + course_start_date: '2099-01-01T00:00:00Z', + }, + }; + + const mockGetPastCourseData = { + data: { + proctored_exam_settings: { + enable_proctored_exams: true, + allow_proctoring_opt_out: false, + proctoring_provider: 'mockproc', + proctoring_escalation_email: 'test@example.com', + create_zendesk_tickets: true, + }, + available_proctoring_providers: ['software_secure', 'proctortrack', 'mockproc'], + course_start_date: '2013-01-01T00:00:00Z', + }, + }; + + function mockAPI(getData, isAdmin) { + const mockClientGet = jest.fn(async () => (getData)); + auth.getAuthenticatedHttpClient = jest.fn(() => ({ + get: mockClientGet, + })); + auth.getAuthenticatedUser = jest.fn(() => ({ userId: 3, administrator: isAdmin })); + } + + afterEach(() => { + cleanup(); + }); + + it('disables irrelevant Proctoring Provider fields when user is not an administrator and it is after start date', async () => { + mockAPI(mockGetPastCourseData, false); + await act(async () => render()); + const providerOption = screen.getByTestId('proctortrack'); + expect(providerOption.hasAttribute('disabled')).toEqual(true); + }); + + it('enables all Proctoring Provider options if user is not an administrator and it is before start date', async () => { + mockAPI(mockGetFutureCourseData, false); + await act(async () => render()); + const providerOption = screen.getByTestId('proctortrack'); + expect(providerOption.hasAttribute('disabled')).toEqual(false); + }); + + it('enables all Proctoring Provider options if user administrator and it is after start date', async () => { + mockAPI(mockGetPastCourseData, true); + await act(async () => render()); + const providerOption = screen.getByTestId('proctortrack'); + expect(providerOption.hasAttribute('disabled')).toEqual(false); + }); + + it('enables all Proctoring Provider options if user administrator and it is before start date', async () => { + mockAPI(mockGetFutureCourseData, true); + await act(async () => render()); + const providerOption = screen.getByTestId('proctortrack'); + expect(providerOption.hasAttribute('disabled')).toEqual(false); + }); +}); + describe('ProctoredExamSettings connection states tests', () => { it('shows the spinner before the connection is complete', async () => { render();