fix: account for pending timers

This commit is contained in:
Carlos Valente
2024-06-04 15:32:50 +02:00
committed by Carlos Valente
parent 147e5f5a27
commit ee1753ef29
3 changed files with 46 additions and 0 deletions
@@ -1850,4 +1850,44 @@ describe('getTimerPhase()', () => {
const phase = getTimerPhase(state);
expect(phase).toBe(TimerPhase.Default);
});
it('#1042 identifies waiting to roll', () => {
const state = {
clock: 55691050,
eventNow: null,
publicEventNow: null,
eventNext: null,
publicEventNext: null,
runtime: {
selectedEventIndex: null,
numEvents: 1,
offset: null,
plannedStart: 55860000,
plannedEnd: 55880000,
actualStart: null,
expectedEnd: null,
},
timer: {
addedTime: 0,
current: null,
duration: null,
elapsed: 0,
expectedFinish: null,
finishedAt: null,
phase: 'none',
playback: 'roll',
secondaryTimer: 168950,
startedAt: null,
},
_timer: {
forceFinish: null,
totalDelay: 0,
pausedAt: null,
secondaryTarget: 55860000,
},
} as RuntimeState;
const phase = getTimerPhase(state);
expect(phase).toBe(TimerPhase.Pending);
});
});
+5
View File
@@ -385,6 +385,11 @@ export function getTimerPhase(state: RuntimeState): TimerPhase {
}
const current = state.timer.current;
if (current === null || state.eventNow === null) {
return TimerPhase.Pending;
}
if (current < 0) {
return TimerPhase.Negative;
}
@@ -7,6 +7,7 @@ export enum TimerPhase {
Warning = 'warning',
Danger = 'danger',
Negative = 'negative',
Pending = 'pending', // used for waiting to roll
}
export type TimerState = {