Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BD-26] Remove exam review text on submitted exam page #54

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ const BASE_API_URL = '/api/edx_proctoring/v1/proctored_exam/attempt';

export async function fetchExamAttemptsData(courseId, sequenceId) {
const url = new URL(
`${getConfig().LMS_BASE_URL}${BASE_API_URL}/course_id/${courseId}/content_id/${sequenceId}?is_learning_mfe=true`,
`${getConfig().LMS_BASE_URL}${BASE_API_URL}/course_id/${courseId}`,
);
if (sequenceId) {
url.searchParams.append('content_id', sequenceId);
}
url.searchParams.append('is_learning_mfe', true);
const { data } = await getAuthenticatedHttpClient().get(url.href);
return data;
}
Expand Down
39 changes: 37 additions & 2 deletions src/data/redux.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const axiosMock = new MockAdapter(getAuthenticatedHttpClient());
describe('Data layer integration tests', () => {
const exam = Factory.build('exam', { attempt: Factory.build('attempt') });
const { course_id: courseId, content_id: contentId, attempt } = exam;
const fetchExamAttemptsDataUrl = `${getConfig().LMS_BASE_URL}${BASE_API_URL}/course_id/${courseId}/content_id/${contentId}?is_learning_mfe=true`;
const fetchExamAttemptsDataUrl = `${getConfig().LMS_BASE_URL}${BASE_API_URL}/course_id/${courseId}`
+ `?content_id=${encodeURIComponent(contentId)}&is_learning_mfe=true`;
const updateAttemptStatusUrl = `${getConfig().LMS_BASE_URL}${BASE_API_URL}/${attempt.attempt_id}`;
let store;

Expand Down Expand Up @@ -186,7 +187,7 @@ describe('Data layer integration tests', () => {
it('Should stop exam, and update attempt and exam', async () => {
axiosMock.onGet(fetchExamAttemptsDataUrl).replyOnce(200, { exam, active_attempt: attempt });
axiosMock.onGet(fetchExamAttemptsDataUrl).reply(200, { exam: readyToSubmitExam, active_attempt: {} });
axiosMock.onPost(updateAttemptStatusUrl).reply(200, { exam_attempt_id: readyToSubmitAttempt.attempt_id });
axiosMock.onPut(updateAttemptStatusUrl).reply(200, { exam_attempt_id: readyToSubmitAttempt.attempt_id });

await executeThunk(thunks.getExamAttemptsData(courseId, contentId), store.dispatch);
let state = store.getState();
Expand All @@ -197,6 +198,40 @@ describe('Data layer integration tests', () => {
expect(state.examState.exam.attempt.attempt_status).toBe(ExamStatus.READY_TO_SUBMIT);
});

it('Should stop exam, and redirect to sequence if no exam attempt', async () => {
const { location } = window;
delete window.location;
window.location = {
href: '',
};

axiosMock.onGet(fetchExamAttemptsDataUrl).replyOnce(200, { exam: {}, active_attempt: attempt });
axiosMock.onPut(updateAttemptStatusUrl).reply(200, { exam_attempt_id: readyToSubmitAttempt.attempt_id });

await executeThunk(thunks.getExamAttemptsData(courseId, contentId), store.dispatch);
const state = store.getState();
expect(state.examState.activeAttempt.attempt_status).toBe(ExamStatus.STARTED);

await executeThunk(thunks.stopExam(), store.dispatch, store.getState);
expect(axiosMock.history.put[0].url).toEqual(updateAttemptStatusUrl);
expect(window.location.href).toEqual(attempt.exam_url_path);

window.location = location;
});

it('Should fail to fetch if error occurs', async () => {
axiosMock.onGet(fetchExamAttemptsDataUrl).replyOnce(200, { exam: {}, active_attempt: attempt });
axiosMock.onPut(updateAttemptStatusUrl).networkError();

await executeThunk(thunks.getExamAttemptsData(courseId, contentId), store.dispatch);
let state = store.getState();
expect(state.examState.activeAttempt.attempt_status).toBe(ExamStatus.STARTED);

await executeThunk(thunks.stopExam(), store.dispatch, store.getState);
state = store.getState();
expect(state.examState.apiErrorMsg).toBe('Network Error');
});

it('Should fail to fetch if no active attempt', async () => {
axiosMock.onGet(fetchExamAttemptsDataUrl).reply(200, { exam: Factory.build('exam'), active_attempt: {} });
axiosMock.onGet(updateAttemptStatusUrl).reply(200, { exam_attempt_id: readyToSubmitAttempt.attempt_id });
Expand Down
30 changes: 20 additions & 10 deletions src/data/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
fetchExamReviewPolicy,
resetAttempt,
declineAttempt,
endExamWithFailure,
} from './api';
import { isEmpty } from '../helpers';
import {
Expand Down Expand Up @@ -231,13 +232,19 @@ export function stopExam() {
}

const { attempt_id: attemptId, exam_url_path: examUrl } = activeAttempt;
if (!exam.attempt || attemptId !== exam.attempt.attempt_id) {
try {
await stopAttempt(attemptId);
window.location.href = examUrl;
} catch (error) {
handleAPIError(error, dispatch);
}
return;
}

await updateAttemptAfter(
exam.course_id, exam.content_id, stopAttempt(attemptId), true,
)(dispatch);

if (attemptId !== exam.attempt.attempt_id) {
window.location.href = examUrl;
}
};
}

Expand Down Expand Up @@ -320,7 +327,7 @@ export function expireExam() {
}

await updateAttemptAfter(
exam.course_id, exam.content_id, submitAttempt(attemptId),
activeAttempt.course_id, exam.content_id, submitAttempt(attemptId),
)(dispatch);
dispatch(expireExamAttempt());

Expand All @@ -340,12 +347,15 @@ export function expireExam() {
* @param workerUrl - location of the worker from the provider
*/
export function pingAttempt(timeoutInSeconds, workerUrl) {
return async (dispatch) => {
return async (dispatch, getState) => {
await pingApplication(timeoutInSeconds, workerUrl)
.catch((error) => handleAPIError(
{ message: error ? error.message : 'Worker failed to respond.' },
dispatch,
));
.catch(async (error) => {
const { exam, activeAttempt } = getState().examState;
const message = error ? error.message : 'Worker failed to respond.';
await updateAttemptAfter(
exam.course_id, exam.content_id, endExamWithFailure(activeAttempt.attempt_id, message),
)(dispatch);
});
};
}

Expand Down
8 changes: 6 additions & 2 deletions src/exam/ExamWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ const ExamWrapper = ({ children, ...props }) => {

ExamWrapper.propTypes = {
sequence: PropTypes.shape({
id: PropTypes.string.isRequired,
id: PropTypes.string,
isTimeLimited: PropTypes.bool,
allowProctoringOptOut: PropTypes.bool,
}).isRequired,
}),
courseId: PropTypes.string.isRequired,
children: PropTypes.element.isRequired,
};

ExamWrapper.defaultProps = {
sequence: {},
};

export default ExamWrapper;
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const EntranceProctoredExamInstructions = ({ skipProctoredExam }) => {
<p>
<FormattedMessage
id="exam.ReadyToResumeProctoredExamInstructions.text"
ddefaultMessage="You will have {totalTime} to complete your exam."
defaultMessage="You will have {totalTime} to complete your exam."
values={{ totalTime }}
/>
</p>
Expand Down
39 changes: 15 additions & 24 deletions src/instructions/timed_exam/SubmittedTimedExamInstructions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,21 @@ const SubmittedTimedExamInstructions = () => {
const state = useContext(ExamStateContext);

return (
<>
<h3 className="h3" data-testid="exam.submittedExamInstructions.title">
{state.timeIsOver
? (
<FormattedMessage
id="exam.submittedExamInstructions.overtimeTitle"
defaultMessage="The time allotted for this exam has expired. Your exam has been submitted and any work you completed will be graded."
/>
)
: (
<FormattedMessage
id="exam.submittedExamInstructions.title"
defaultMessage="You have submitted your timed exam."
/>
)}
</h3>
<p>
<FormattedMessage
id="exam.submittedExamInstructions.text"
defaultMessage={'After the due date has passed, you can review the exam,'
+ ' but you cannot change your answers.'}
/>
</p>
</>
<h3 className="h3" data-testid="exam.submittedExamInstructions.title">
{state.timeIsOver
? (
<FormattedMessage
id="exam.submittedExamInstructions.overtimeTitle"
defaultMessage="The time allotted for this exam has expired. Your exam has been submitted and any work you completed will be graded."
/>
)
: (
<FormattedMessage
id="exam.submittedExamInstructions.title"
defaultMessage="You have submitted your timed exam."
/>
)}
</h3>
);
};

Expand Down
4 changes: 2 additions & 2 deletions src/timer/CountDownTimer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const CountDownTimer = injectIntl((props) => {
})}
>
{isShowTimer
? <Icon data-testid="hide-timer" src={Visibility} onClick={hideTimer} />
: <Icon data-testid="show-timer" src={VisibilityOff} onClick={showTimer} />}
? <Icon data-testid="hide-timer" src={VisibilityOff} onClick={hideTimer} />
: <Icon data-testid="show-timer" src={Visibility} onClick={showTimer} />}
</span>
</div>
);
Expand Down