From 674c0dc8c674fcaa576491802ece09f9ad03aee9 Mon Sep 17 00:00:00 2001 From: Zach Hancock Date: Tue, 12 Sep 2023 10:38:39 -0400 Subject: [PATCH] feat: single tab lti flow --- .../ProctoredExamInstructions.test.jsx | 13 ++++++++++--- .../SubmitProctoredExamInstructions.jsx | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/instructions/proctored_exam/ProctoredExamInstructions.test.jsx b/src/instructions/proctored_exam/ProctoredExamInstructions.test.jsx index 063ad89f..bfd56f9a 100644 --- a/src/instructions/proctored_exam/ProctoredExamInstructions.test.jsx +++ b/src/instructions/proctored_exam/ProctoredExamInstructions.test.jsx @@ -197,8 +197,12 @@ describe('SequenceExamWrapper', () => { }); it('Initiates an LTI launch in a new window when the user clicks the submit button', async () => { - const windowSpy = jest.spyOn(window, 'open'); - windowSpy.mockImplementation(() => ({})); + const { location } = window; + delete window.location; + const mockAssign = jest.fn(); + window.location = { + assign: mockAssign, + }; const attempt = Factory.build('attempt', { attempt_status: ExamStatus.READY_TO_SUBMIT, use_legacy_attempt_api: false, @@ -226,7 +230,10 @@ describe('SequenceExamWrapper', () => { expect(queryByTestId('proctored-exam-instructions-title')).toHaveTextContent('Are you sure you want to end your proctored exam?'); fireEvent.click(queryByTestId('end-exam-button')); - await waitFor(() => { expect(windowSpy).toHaveBeenCalledWith('http://localhost:18740/lti/end_assessment/1', '_blank'); }); + await waitFor(() => { expect(mockAssign).toHaveBeenCalledWith('http://localhost:18740/lti/end_assessment/1'); }); + + // restore window.location + window.location = location; }); it('Instructions are shown when attempt status is verified', () => { diff --git a/src/instructions/proctored_exam/SubmitProctoredExamInstructions.jsx b/src/instructions/proctored_exam/SubmitProctoredExamInstructions.jsx index 87a891fc..247caeab 100644 --- a/src/instructions/proctored_exam/SubmitProctoredExamInstructions.jsx +++ b/src/instructions/proctored_exam/SubmitProctoredExamInstructions.jsx @@ -19,7 +19,7 @@ const SubmitProctoredExamInstructions = () => { const handleSubmitClick = () => { if (examHasLtiProvider) { - window.open(submitLtiAttemptUrl, '_blank'); + window.location.assign(submitLtiAttemptUrl); } submitExam(); };