mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-11 02:13:48 +00:00
refactor: declare timer phase
This commit is contained in:
committed by
Carlos Valente
parent
a53d354b16
commit
fd2eee32aa
@@ -1,11 +1,12 @@
|
||||
import { MILLIS_PER_HOUR, dayInMs, millisToString } from 'ontime-utils';
|
||||
import { EndAction, OntimeEvent, Playback, TimeStrategy, TimerType } from 'ontime-types';
|
||||
import { EndAction, OntimeEvent, Playback, TimeStrategy, TimerPhase, TimerType } from 'ontime-types';
|
||||
|
||||
import {
|
||||
getCurrent,
|
||||
getExpectedFinish,
|
||||
getRollTimers,
|
||||
getRuntimeOffset,
|
||||
getTimerPhase,
|
||||
getTotalDuration,
|
||||
normaliseEndTime,
|
||||
skippedOutOfEvent,
|
||||
@@ -1756,3 +1757,97 @@ describe('getTotalDuration()', () => {
|
||||
expect(millisToString(duration)).toBe('62:00:00');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getTimerPhase()', () => {
|
||||
it('should be None if the timer is not running', () => {
|
||||
const state = {
|
||||
timer: {
|
||||
addedTime: 0,
|
||||
current: null,
|
||||
duration: null,
|
||||
elapsed: null,
|
||||
expectedFinish: null,
|
||||
finishedAt: null,
|
||||
playback: Playback.Stop,
|
||||
phase: TimerPhase.None,
|
||||
secondaryTimer: null,
|
||||
startedAt: null,
|
||||
},
|
||||
} as RuntimeState;
|
||||
|
||||
const phase = getTimerPhase(state);
|
||||
expect(phase).toBe(TimerPhase.None);
|
||||
});
|
||||
|
||||
it('can be negative', () => {
|
||||
const state = {
|
||||
timer: {
|
||||
addedTime: 0,
|
||||
current: -50,
|
||||
duration: 1000,
|
||||
playback: Playback.Play,
|
||||
},
|
||||
eventNow: {
|
||||
timeDanger: 100,
|
||||
timeWarning: 200,
|
||||
},
|
||||
} as RuntimeState;
|
||||
|
||||
const phase = getTimerPhase(state);
|
||||
expect(phase).toBe(TimerPhase.Negative);
|
||||
});
|
||||
|
||||
it('can be danger', () => {
|
||||
const state = {
|
||||
timer: {
|
||||
addedTime: 0,
|
||||
current: 0,
|
||||
duration: 1000,
|
||||
playback: Playback.Play,
|
||||
},
|
||||
eventNow: {
|
||||
timeDanger: 100,
|
||||
timeWarning: 200,
|
||||
},
|
||||
} as RuntimeState;
|
||||
|
||||
const phase = getTimerPhase(state);
|
||||
expect(phase).toBe(TimerPhase.Danger);
|
||||
});
|
||||
|
||||
it('can be warning', () => {
|
||||
const state = {
|
||||
timer: {
|
||||
addedTime: 0,
|
||||
current: 150,
|
||||
duration: 1000,
|
||||
playback: Playback.Play,
|
||||
},
|
||||
eventNow: {
|
||||
timeDanger: 100,
|
||||
timeWarning: 200,
|
||||
},
|
||||
} as RuntimeState;
|
||||
|
||||
const phase = getTimerPhase(state);
|
||||
expect(phase).toBe(TimerPhase.Warning);
|
||||
});
|
||||
|
||||
it('it default if the timer is playing and there is none of the above', () => {
|
||||
const state = {
|
||||
timer: {
|
||||
addedTime: 0,
|
||||
current: 250,
|
||||
duration: 1000,
|
||||
playback: Playback.Play,
|
||||
},
|
||||
eventNow: {
|
||||
timeDanger: 100,
|
||||
timeWarning: 200,
|
||||
},
|
||||
} as RuntimeState;
|
||||
|
||||
const phase = getTimerPhase(state);
|
||||
expect(phase).toBe(TimerPhase.Default);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user