Skip to content

Commit

Permalink
fix: Remove retry button in LTI Proctorio exams
Browse files Browse the repository at this point in the history
  • Loading branch information
rijuma committed Oct 9, 2024
1 parent a75987f commit 7df16b4
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import React from 'react';
import { useDispatch } from 'react-redux';
import { useDispatch, useSelector } from 'react-redux';
import { FormattedMessage } from '@edx/frontend-platform/i18n';
import { Button } from '@openedx/paragon';

import { resetExam } from '../../data';

const SubmittedPracticeExamInstructions = () => {
const dispatch = useDispatch();
const { exam } = useSelector(state => state.specialExams);

const examHasLtiProvider = !exam?.attempt?.use_legacy_attempt_api;

return (
<div>
Expand All @@ -23,16 +26,18 @@ const SubmittedPracticeExamInstructions = () => {
+ 'completed this practice exam and can continue with your course work.'}
/>
</p>
<Button
data-testid="retry-exam-button"
variant="primary"
onClick={() => dispatch(resetExam())}
>
<FormattedMessage
id="exam.SubmittedPracticeExamInstructions.retryExamButton"
defaultMessage="Retry my exam"
/>
</Button>
{!examHasLtiProvider ? (
<Button
data-testid="retry-exam-button"
variant="primary"
onClick={() => dispatch(resetExam())}
>
<FormattedMessage
id="exam.SubmittedPracticeExamInstructions.retryExamButton"
defaultMessage="Retry my exam"
/>
</Button>
) : null}
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import React from 'react';
import { SubmittedPracticeExamInstructions } from './index';
import {
render, screen, initializeTestStore, fireEvent,
} from '../../setupTest';

const mockresetReturn = {};
const mockDispatch = jest.fn();

jest.mock('react-redux', () => ({
...jest.requireActual('react-redux'),
useDispatch: () => mockDispatch,
}));

jest.mock('../../data', () => ({
...jest.requireActual('../../data'),
resetExam: () => mockresetReturn,
}));

describe('ExamTimerBlock', () => {
afterEach(() => {
jest.resetAllMocks();
});

describe('when no LTI provider is used', () => {
beforeEach(() => {
const preloadedState = {
specialExams: {
exam: {
attempt: {
use_legacy_attempt_api: true,
},
},
},
};
initializeTestStore(preloadedState);

render(
<SubmittedPracticeExamInstructions />,
);
});

it('renders the component correctly', async () => {
expect(screen.getByText('You have submitted this practice proctored exam')).toBeInTheDocument();
expect(screen.getByText(
'Practice exams do not affect your grade. You have '
+ 'completed this practice exam and can continue with your course work.',
)).toBeInTheDocument();
expect(screen.queryByTestId('retry-exam-button')).toBeInTheDocument();
});

it('calls resetExam() when clicking the retry button', () => {
expect(mockDispatch).not.toHaveBeenCalled();

fireEvent.click(screen.getByTestId('retry-exam-button'));

expect(mockDispatch).toHaveBeenCalledTimes(1);
expect(mockDispatch).toHaveBeenCalledWith(mockresetReturn);
});
});

describe('when an LTI provider is used', () => {
beforeEach(() => {
const preloadedState = {
specialExams: {
exam: {},
},
};
initializeTestStore(preloadedState);

render(
<SubmittedPracticeExamInstructions />,
);
});

it('doesn\'t show the button if it has an LTI provider', async () => {
expect(screen.getByText('You have submitted this practice proctored exam')).toBeInTheDocument();
expect(screen.getByText(
'Practice exams do not affect your grade. You have '
+ 'completed this practice exam and can continue with your course work.',
)).toBeInTheDocument();
expect(screen.queryByTestId('retry-exam-button')).not.toBeInTheDocument();
});
});
});

0 comments on commit 7df16b4

Please sign in to comment.