Skip to content

Commit

Permalink
Revert "[fix] The special exam timer synced with backend to show accu…
Browse files Browse the repository at this point in the history
…rate count down timer (#43)" (#44)

This reverts commit b34e0f9.

Co-authored-by: Simon Chen <[email protected]>
  • Loading branch information
schenedx and Simon Chen authored Sep 23, 2021
1 parent b34e0f9 commit e6aa31c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 74 deletions.
63 changes: 0 additions & 63 deletions src/timer/CountDownTimer.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ describe('ExamTimerBlock', () => {
stopExamAttempt={stopExamAttempt}
expireExamAttempt={expireExamAttempt}
pollExamAttempt={pollAttempt}
submitExam={submitAttempt}
/>,
);

Expand Down Expand Up @@ -81,7 +80,6 @@ describe('ExamTimerBlock', () => {
stopExamAttempt={stopExamAttempt}
expireExamAttempt={expireExamAttempt}
pollExamAttempt={pollAttempt}
submitExam={submitAttempt}
/>,
);
expect(container.firstChild).not.toBeInTheDocument();
Expand All @@ -94,7 +92,6 @@ describe('ExamTimerBlock', () => {
stopExamAttempt={stopExamAttempt}
expireExamAttempt={expireExamAttempt}
pollExamAttempt={pollAttempt}
submitExam={submitAttempt}
/>,
);
await waitFor(() => expect(screen.getByText('00:00:09')).toBeInTheDocument());
Expand Down Expand Up @@ -130,7 +127,6 @@ describe('ExamTimerBlock', () => {
stopExamAttempt={stopExamAttempt}
expireExamAttempt={expireExamAttempt}
pollExamAttempt={pollAttempt}
submitExam={submitAttempt}
/>,
);
await waitFor(() => expect(screen.getByText('00:00:04')).toBeInTheDocument());
Expand All @@ -144,7 +140,6 @@ describe('ExamTimerBlock', () => {
stopExamAttempt={stopExamAttempt}
expireExamAttempt={expireExamAttempt}
pollExamAttempt={pollAttempt}
submitExam={submitAttempt}
/>,
);
await waitFor(() => expect(screen.getByText('00:00:09')).toBeInTheDocument());
Expand All @@ -167,7 +162,6 @@ describe('ExamTimerBlock', () => {
stopExamAttempt={stopExamAttempt}
expireExamAttempt={expireExamAttempt}
pollExamAttempt={pollAttempt}
submitExam={submitAttempt}
/>,
);
await waitFor(() => expect(screen.getByText('00:00:09')).toBeInTheDocument());
Expand Down Expand Up @@ -236,61 +230,4 @@ describe('ExamTimerBlock', () => {
fireEvent.click(screen.getByTestId('end-button'));
expect(stopExamAttempt).toHaveBeenCalledTimes(1);
});

it('Update exam timer when attempt time_remaining_seconds is smaller than displayed time', async () => {
const preloadedState = {
examState: {
isLoading: true,
timeIsOver: false,
activeAttempt: {
attempt_status: 'started',
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: {},
},
};
let testStore = await initializeTestStore(preloadedState);
examStore.getState = store.testStore;
attempt = testStore.getState().examState.activeAttempt;
const { rerender } = render(
<ExamTimerBlock
attempt={attempt}
stopExamAttempt={stopExamAttempt}
expireExamAttempt={expireExamAttempt}
pollExamAttempt={pollAttempt}
submitExam={submitAttempt}
/>,
);
await waitFor(() => expect(screen.getByText('00:03:59')).toBeInTheDocument());

preloadedState.examState.activeAttempt = {
...attempt,
time_remaining_seconds: 20,
};
testStore = await initializeTestStore(preloadedState);
examStore.getState = store.testStore;
const updatedAttempt = testStore.getState().examState.activeAttempt;

expect(updatedAttempt.time_remaining_seconds).toBe(20);

rerender(
<ExamTimerBlock
attempt={updatedAttempt}
stopExamAttempt={stopExamAttempt}
expireExamAttempt={expireExamAttempt}
pollExamAttempt={pollAttempt}
submitExam={submitAttempt}
/>,
);

await waitFor(() => expect(screen.getByText('00:00:19')).toBeInTheDocument());
});
});
19 changes: 8 additions & 11 deletions src/timer/TimerProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ const TimerServiceProvider = ({
critically_low_threshold_sec: criticalLowTime,
low_threshold_sec: lowTime,
} = attempt;
const startValue = Math.floor(timeRemaining);
const LIMIT = GRACE_PERIOD_SECS ? 0 - GRACE_PERIOD_SECS : 0;
let liveInterval = null;

const getTimeString = () => Object.values(timeState).map(
item => {
Expand Down Expand Up @@ -77,29 +77,26 @@ const TimerServiceProvider = ({
};

useEffect(() => {
let secondsLeft = startValue;
let timerTick = 0;
let secondsLeft = Math.floor(timeRemaining);
liveInterval = setInterval(() => {
const interval = setInterval(() => {
secondsLeft -= 1;
timerTick += 1;
setTimeState(getFormattedRemainingTime(secondsLeft));
processTimeLeft(liveInterval, secondsLeft);
processTimeLeft(interval, secondsLeft);
// no polling during grace period
if (timerTick % POLL_INTERVAL === 0 && secondsLeft >= 0) {
pollExam();
}

// if exam is proctored ping provider app also
if (workerUrl && timerTick % pingInterval === pingInterval / 2) {
pingHandler(pingInterval, workerUrl);
}
}, 1000);
return () => {
if (liveInterval) {
clearInterval(liveInterval);
liveInterval = null;
}
};
}, [timeRemaining]);

return () => { clearInterval(interval); };
}, []);

return (
<TimerContext.Provider value={{
Expand Down

0 comments on commit e6aa31c

Please sign in to comment.