Over under (#771)

* feat: schedule offset
This commit is contained in:
Carlos Valente
2024-02-16 21:04:58 +01:00
committed by GitHub
parent 436a34aaee
commit 1a420a1ddd
34 changed files with 437 additions and 157 deletions
@@ -5,6 +5,7 @@ import {
getCurrent,
getExpectedFinish,
getRollTimers,
getRuntimeOffset,
normaliseEndTime,
skippedOutOfEvent,
updateRoll,
@@ -1370,3 +1371,68 @@ describe('updateRoll()', () => {
expect(updateRoll(timers)).toStrictEqual(expected);
});
});
describe('getRuntimeOffset()', () => {
it('calculates the difference between schedule and actual start', () => {
const state = {
eventNow: {
id: '1',
timeStart: 100,
},
timer: {
startedAt: 150,
addedTime: 10,
current: 0,
},
_timer: {
pausedAt: null,
},
} as RuntimeState;
const offset = getRuntimeOffset(state);
expect(offset).toBe(60);
});
it('adds the overtime time of the current timer', () => {
const state = {
eventNow: {
id: '1',
timeStart: 100,
timeEnd: 140,
},
timer: {
startedAt: 100,
current: -10,
addedTime: 0,
},
_timer: {
pausedAt: null,
},
} as RuntimeState;
const offset = getRuntimeOffset(state);
expect(offset).toBe(10);
});
it('accounts for paused time', () => {
const state = {
eventNow: {
id: '1',
timeStart: 100,
timeEnd: 150,
},
clock: 150,
timer: {
startedAt: 100,
current: 25,
addedTime: 0,
},
_timer: {
pausedAt: 125,
},
} as RuntimeState;
const offset = getRuntimeOffset(state);
expect(offset).toBe(25);
});
});