Skip to content

Commit

Permalink
feat: calculate timer low/critical cutoff in UI (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharis278 authored Mar 22, 2023
1 parent 71a6c1c commit d4bfcc3
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 59 deletions.
4 changes: 3 additions & 1 deletion src/core/OuterExamTimer.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ describe('OuterExamTimer', () => {
store.getState = () => ({
examState: {
activeAttempt: attempt,
exam: {},
exam: {
time_limit_mins: 60,
},
},
});

Expand Down
2 changes: 0 additions & 2 deletions src/data/__factories__/attempt.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Factory.define('attempt')
exam_display_name: 'timed',
exam_url_path: 'http://localhost:2000/course/course-v1:test+special+exam/block-v1:test+special+exam+type@sequential+block@abc123',
time_remaining_seconds: 1799.9,
low_threshold_sec: 360,
critically_low_threshold_sec: 90,
course_id: 'course-v1:test+special+exam',
accessibility_time_string: 'you have 30 minutes remaining',
exam_started_poll_url: '/api/edx_proctoring/v1/proctored_exam/attempt/1',
Expand Down
22 changes: 0 additions & 22 deletions src/data/__snapshots__/redux.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ Object {
"attempt_id": 1,
"attempt_status": "started",
"course_id": "course-v1:test+special+exam",
"critically_low_threshold_sec": 90,
"desktop_application_js_url": "",
"exam_display_name": "timed",
"exam_started_poll_url": "/api/edx_proctoring/v1/proctored_exam/attempt/1",
"exam_type": "a timed exam",
"exam_url_path": "http://localhost:2000/course/course-v1:test+special+exam/block-v1:test+special+exam+type@sequential+block@abc123",
"in_timed_exam": true,
"low_threshold_sec": 360,
"software_download_url": "",
"taking_as_proctored": false,
"time_remaining_seconds": 1799.9,
Expand All @@ -31,14 +29,12 @@ Object {
"attempt_id": 1,
"attempt_status": "started",
"course_id": "course-v1:test+special+exam",
"critically_low_threshold_sec": 90,
"desktop_application_js_url": "",
"exam_display_name": "timed",
"exam_started_poll_url": "/api/edx_proctoring/v1/proctored_exam/attempt/1",
"exam_type": "a timed exam",
"exam_url_path": "http://localhost:2000/course/course-v1:test+special+exam/block-v1:test+special+exam+type@sequential+block@abc123",
"in_timed_exam": true,
"low_threshold_sec": 360,
"software_download_url": "",
"taking_as_proctored": false,
"time_remaining_seconds": 1799.9,
Expand Down Expand Up @@ -97,14 +93,12 @@ Object {
"attempt_id": 1,
"attempt_status": "started",
"course_id": "course-v1:test+special+exam",
"critically_low_threshold_sec": 90,
"desktop_application_js_url": "",
"exam_display_name": "timed",
"exam_started_poll_url": "/api/edx_proctoring/v1/proctored_exam/attempt/1",
"exam_type": "a timed exam",
"exam_url_path": "http://localhost:2000/course/course-v1:test+special+exam/block-v1:test+special+exam+type@sequential+block@abc123",
"in_timed_exam": true,
"low_threshold_sec": 360,
"software_download_url": "",
"taking_as_proctored": false,
"time_remaining_seconds": 1799.9,
Expand Down Expand Up @@ -144,14 +138,12 @@ Object {
"attempt_id": 1,
"attempt_status": "started",
"course_id": "course-v1:test+special+exam",
"critically_low_threshold_sec": 90,
"desktop_application_js_url": "",
"exam_display_name": "timed",
"exam_started_poll_url": "/api/edx_proctoring/v1/proctored_exam/attempt/1",
"exam_type": "a timed exam",
"exam_url_path": "http://localhost:2000/course/course-v1:test+special+exam/block-v1:test+special+exam+type@sequential+block@abc123",
"in_timed_exam": true,
"low_threshold_sec": 360,
"software_download_url": "",
"taking_as_proctored": false,
"time_remaining_seconds": 1799.9,
Expand All @@ -166,14 +158,12 @@ Object {
"attempt_id": 1,
"attempt_status": "started",
"course_id": "course-v1:test+special+exam",
"critically_low_threshold_sec": 90,
"desktop_application_js_url": "",
"exam_display_name": "timed",
"exam_started_poll_url": "/api/edx_proctoring/v1/proctored_exam/attempt/1",
"exam_type": "a timed exam",
"exam_url_path": "http://localhost:2000/course/course-v1:test+special+exam/block-v1:test+special+exam+type@sequential+block@abc123",
"in_timed_exam": true,
"low_threshold_sec": 360,
"software_download_url": "",
"taking_as_proctored": false,
"time_remaining_seconds": 1799.9,
Expand Down Expand Up @@ -232,14 +222,12 @@ Object {
"attempt_id": 1,
"attempt_status": "started",
"course_id": "course-v1:test+special+exam",
"critically_low_threshold_sec": 90,
"desktop_application_js_url": "",
"exam_display_name": "timed",
"exam_started_poll_url": "/api/edx_proctoring/v1/proctored_exam/attempt/1",
"exam_type": "a timed exam",
"exam_url_path": "http://localhost:2000/course/course-v1:test+special+exam/block-v1:test+special+exam+type@sequential+block@abc123",
"in_timed_exam": true,
"low_threshold_sec": 360,
"software_download_url": "",
"taking_as_proctored": false,
"time_remaining_seconds": 1799.9,
Expand Down Expand Up @@ -320,14 +308,12 @@ Object {
"attempt_id": 1,
"attempt_status": "started",
"course_id": "course-v1:test+special+exam",
"critically_low_threshold_sec": 90,
"desktop_application_js_url": "",
"exam_display_name": "timed",
"exam_started_poll_url": "/api/edx_proctoring/v1/proctored_exam/attempt/1",
"exam_type": "a timed exam",
"exam_url_path": "http://localhost:2000/course/course-v1:test+special+exam/block-v1:test+special+exam+type@sequential+block@abc123",
"in_timed_exam": true,
"low_threshold_sec": 360,
"software_download_url": "",
"taking_as_proctored": false,
"time_remaining_seconds": 1799.9,
Expand All @@ -342,14 +328,12 @@ Object {
"attempt_id": 1,
"attempt_status": "started",
"course_id": "course-v1:test+special+exam",
"critically_low_threshold_sec": 90,
"desktop_application_js_url": "",
"exam_display_name": "timed",
"exam_started_poll_url": "/api/edx_proctoring/v1/proctored_exam/attempt/1",
"exam_type": "a timed exam",
"exam_url_path": "http://localhost:2000/course/course-v1:test+special+exam/block-v1:test+special+exam+type@sequential+block@abc123",
"in_timed_exam": true,
"low_threshold_sec": 360,
"software_download_url": "",
"taking_as_proctored": false,
"time_remaining_seconds": 1799.9,
Expand All @@ -370,14 +354,12 @@ Object {
"attempt_id": 2,
"attempt_status": "created",
"course_id": "course-v1:test+special+exam",
"critically_low_threshold_sec": 90,
"desktop_application_js_url": "",
"exam_display_name": "timed",
"exam_started_poll_url": "/api/edx_proctoring/v1/proctored_exam/attempt/1",
"exam_type": "a timed exam",
"exam_url_path": "http://localhost:2000/course/course-v1:test+special+exam/block-v1:test+special+exam+type@sequential+block@abc123",
"in_timed_exam": true,
"low_threshold_sec": 360,
"software_download_url": "",
"taking_as_proctored": false,
"time_remaining_seconds": 1799.9,
Expand Down Expand Up @@ -434,14 +416,12 @@ Object {
"attempt_id": 1,
"attempt_status": "started",
"course_id": "course-v1:test+special+exam",
"critically_low_threshold_sec": 90,
"desktop_application_js_url": "",
"exam_display_name": "timed",
"exam_started_poll_url": "/api/edx_proctoring/v1/proctored_exam/attempt/1",
"exam_type": "a timed exam",
"exam_url_path": "http://localhost:2000/course/course-v1:test+special+exam/block-v1:test+special+exam+type@sequential+block@abc123",
"in_timed_exam": true,
"low_threshold_sec": 360,
"software_download_url": "",
"taking_as_proctored": false,
"time_remaining_seconds": 1799.9,
Expand All @@ -456,14 +436,12 @@ Object {
"attempt_id": 1,
"attempt_status": "started",
"course_id": "course-v1:test+special+exam",
"critically_low_threshold_sec": 90,
"desktop_application_js_url": "",
"exam_display_name": "timed",
"exam_started_poll_url": "/api/edx_proctoring/v1/proctored_exam/attempt/1",
"exam_type": "a timed exam",
"exam_url_path": "http://localhost:2000/course/course-v1:test+special+exam/block-v1:test+special+exam+type@sequential+block@abc123",
"in_timed_exam": true,
"low_threshold_sec": 360,
"software_download_url": "",
"taking_as_proctored": false,
"time_remaining_seconds": 1799.9,
Expand Down
2 changes: 0 additions & 2 deletions src/data/slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ export const examSlice = createSlice({
exam_display_name: '',
exam_url_path: '',
time_remaining_seconds: null,
low_threshold_sec: null,
critically_low_threshold_sec: null,
course_id: '',
attempt_id: null,
accessibility_time_string: '',
Expand Down
42 changes: 21 additions & 21 deletions src/timer/CountDownTimer.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ describe('ExamTimerBlock', () => {
attempt_status: 'started',
exam_url_path: 'exam_url_path',
exam_display_name: 'exam name',
time_remaining_seconds: 10,
low_threshold_sec: 15,
critically_low_threshold_sec: 5,
time_remaining_seconds: 24,
exam_started_poll_url: '',
taking_as_proctored: false,
exam_type: 'a timed exam',
},
proctoringSettings: {},
exam: {},
exam: {
time_limit_mins: 2,
},
},
};
store = await initializeTestStore(preloadedState);
Expand Down Expand Up @@ -97,7 +97,7 @@ describe('ExamTimerBlock', () => {
submitExam={submitAttempt}
/>,
);
await waitFor(() => expect(screen.getByText('00:00:09')).toBeInTheDocument());
await waitFor(() => expect(screen.getByText('00:00:23')).toBeInTheDocument());
expect(screen.getByRole('alert')).toHaveClass('alert-warning');
});

Expand All @@ -110,15 +110,15 @@ describe('ExamTimerBlock', () => {
attempt_status: 'started',
exam_url_path: 'exam_url_path',
exam_display_name: 'exam name',
time_remaining_seconds: 5,
low_threshold_sec: 15,
critically_low_threshold_sec: 5,
time_remaining_seconds: 6,
exam_started_poll_url: '',
taking_as_proctored: false,
exam_type: 'a timed exam',
},
proctoringSettings: {},
exam: {},
exam: {
time_limit_mins: 2,
},
},
};
const testStore = await initializeTestStore(preloadedState);
Expand All @@ -133,7 +133,7 @@ describe('ExamTimerBlock', () => {
submitExam={submitAttempt}
/>,
);
await waitFor(() => expect(screen.getByText('00:00:04')).toBeInTheDocument());
await waitFor(() => expect(screen.getByText('00:00:05')).toBeInTheDocument());
expect(screen.getByRole('alert')).toHaveClass('alert-danger');
});

Expand All @@ -147,17 +147,17 @@ describe('ExamTimerBlock', () => {
submitExam={submitAttempt}
/>,
);
await waitFor(() => expect(screen.getByText('00:00:09')).toBeInTheDocument());
await waitFor(() => expect(screen.getByText('00:00:23')).toBeInTheDocument());
expect(screen.getByRole('alert')).toBeInTheDocument();
expect(screen.getByLabelText('Hide Timer')).toBeInTheDocument();

fireEvent.click(screen.getByTestId('hide-timer'));
expect(screen.getByLabelText('Show Timer')).toBeInTheDocument();
expect(screen.queryByText(/00:00:0/)).not.toBeInTheDocument();
expect(screen.queryByText(/00:00:2/)).not.toBeInTheDocument();

fireEvent.click(screen.getByTestId('show-timer'));
expect(screen.getByLabelText('Hide Timer')).toBeInTheDocument();
expect(screen.queryByText(/00:00:0/)).toBeInTheDocument();
expect(screen.queryByText(/00:00:2/)).toBeInTheDocument();
});

it('toggles long text visibility on show more/less', async () => {
Expand All @@ -170,7 +170,7 @@ describe('ExamTimerBlock', () => {
submitExam={submitAttempt}
/>,
);
await waitFor(() => expect(screen.getByText('00:00:09')).toBeInTheDocument());
await waitFor(() => expect(screen.getByText('00:00:23')).toBeInTheDocument());
expect(screen.getByRole('alert')).toBeInTheDocument();

fireEvent.click(screen.getByText('Show more'));
Expand All @@ -192,14 +192,14 @@ describe('ExamTimerBlock', () => {
exam_url_path: 'exam_url_path',
exam_display_name: 'exam name',
time_remaining_seconds: 1,
low_threshold_sec: 15,
critically_low_threshold_sec: 5,
exam_started_poll_url: '',
taking_as_proctored: false,
exam_type: 'a timed exam',
},
proctoringSettings: {},
exam: {},
exam: {
time_limit_mins: 30,
},
},
};
const testStore = await initializeTestStore(preloadedState);
Expand Down Expand Up @@ -231,7 +231,7 @@ describe('ExamTimerBlock', () => {
submitExam={submitAttempt}
/>,
);
await waitFor(() => expect(screen.getByText('00:00:09')).toBeInTheDocument());
await waitFor(() => expect(screen.getByText('00:00:23')).toBeInTheDocument());

fireEvent.click(screen.getByTestId('end-button'));
expect(stopExamAttempt).toHaveBeenCalledTimes(1);
Expand All @@ -247,14 +247,14 @@ describe('ExamTimerBlock', () => {
exam_url_path: 'exam_url_path',
exam_display_name: 'exam name',
time_remaining_seconds: 240,
low_threshold_sec: 15,
critically_low_threshold_sec: 5,
exam_started_poll_url: '',
taking_as_proctored: false,
exam_type: 'a timed exam',
},
proctoringSettings: {},
exam: {},
exam: {
time_limit_mins: 30,
},
},
};
let testStore = await initializeTestStore(preloadedState);
Expand Down
2 changes: 0 additions & 2 deletions src/timer/ExamTimerBlock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ ExamTimerBlock.propTypes = {
exam_url_path: PropTypes.string.isRequired,
exam_display_name: PropTypes.string.isRequired,
time_remaining_seconds: PropTypes.number.isRequired,
low_threshold_sec: PropTypes.number.isRequired,
critically_low_threshold_sec: PropTypes.number.isRequired,
}),
stopExamAttempt: PropTypes.func.isRequired,
expireExamAttempt: PropTypes.func.isRequired,
Expand Down
Loading

0 comments on commit d4bfcc3

Please sign in to comment.