Skip to content

Commit

Permalink
chore: Updated Instructions test to match the update
Browse files Browse the repository at this point in the history
  • Loading branch information
rijuma committed Oct 9, 2024
1 parent 7df16b4 commit 30c8120
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/instructions/Instructions.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -502,14 +502,15 @@ describe('SequenceExamWrapper', () => {
expect(screen.getByTestId('retry-exam-button')).toHaveTextContent('Retry my exam');
});

it('Shows submitted practice exam instructions if exam is onboarding and attempt status is submitted', () => {
it('Shows submitted practice exam instructions if exam is onboarding and attempt status is submitted on legacy LTI exams', () => {
store.getState = () => ({
specialExams: Factory.build('specialExams', {
activeAttempt: {},
exam: Factory.build('exam', {
is_proctored: true,
type: ExamType.PRACTICE,
attempt: Factory.build('attempt', {
use_legacy_attempt_api: true,
attempt_status: ExamStatus.SUBMITTED,
}),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import { FormattedMessage } from '@edx/frontend-platform/i18n';
import { Button } from '@openedx/paragon';

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

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

const examHasLtiProvider = !exam?.attempt?.use_legacy_attempt_api;
// It does not show the reload button if the exam is submitted and not legacy
const showRetryButton = !(
exam.attempt?.attempt_status === ExamStatus.SUBMITTED
&& !exam.attempt?.use_legacy_attempt_api
);

return (
<div>
Expand All @@ -26,7 +31,7 @@ const SubmittedPracticeExamInstructions = () => {
+ 'completed this practice exam and can continue with your course work.'}
/>
</p>
{!examHasLtiProvider ? (
{showRetryButton ? (
<Button
data-testid="retry-exam-button"
variant="primary"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React from 'react';
import { Factory } from 'rosie';
import { SubmittedPracticeExamInstructions } from './index';
import {
render, screen, initializeTestStore, fireEvent,
} from '../../setupTest';
import { ExamStatus, ExamType } from '../../constants';

const mockresetReturn = {};
const mockDispatch = jest.fn();
Expand All @@ -22,15 +24,131 @@ describe('ExamTimerBlock', () => {
jest.resetAllMocks();
});

describe('when no LTI provider is used', () => {
describe('when the exam is not proctored', () => {
beforeEach(() => {
const preloadedState = {
specialExams: {
exam: {
attempt: {
exam: Factory.build('exam', {
is_proctored: false,
type: ExamType.ONBOARDING,
attempt: Factory.build('attempt'),
}),
},
};
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 the exam is not proctored', () => {
beforeEach(() => {
const preloadedState = {
specialExams: {
exam: Factory.build('exam', {
is_proctored: false,
type: ExamType.ONBOARDING,
attempt: Factory.build('attempt'),
}),
},
};
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 a legacy proctoring attempt API is used', () => {
beforeEach(() => {
const preloadedState = {
specialExams: {
exam: Factory.build('exam', {
is_proctored: true,
type: ExamType.PROCTORED,
attempt: Factory.build('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 but it has an error', () => {
beforeEach(() => {
const preloadedState = {
specialExams: {
exam: Factory.build('exam', {
is_proctored: true,
type: ExamType.PROCTORED,
attempt: Factory.build('attempt', {
use_legacy_attempt_api: false,
attempt_status: ExamStatus.ERROR,
}),
}),
},
};
initializeTestStore(preloadedState);
Expand Down Expand Up @@ -59,11 +177,18 @@ describe('ExamTimerBlock', () => {
});
});

describe('when an LTI provider is used', () => {
describe('when an LTI provider is used and the exam is submitted', () => {
beforeEach(() => {
const preloadedState = {
specialExams: {
exam: {},
exam: Factory.build('exam', {
is_proctored: true,
type: ExamType.PROCTORED,
attempt: Factory.build('attempt', {
use_legacy_attempt_api: false,
attempt_status: ExamStatus.SUBMITTED,
}),
}),
},
};
initializeTestStore(preloadedState);
Expand Down

0 comments on commit 30c8120

Please sign in to comment.