mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-14 11:53:49 +00:00
Refactor: split runtime state (#1725)
* refactor: runtime types * refactor: runtimeState functions to use the split type * refactor: RuntimeService to use the new split data * refactor: use the split data in the UI * update comments * refactor: rename runtime to offset * fix utils test
This commit is contained in:
committed by
Carlos Valente
parent
ed93cf313a
commit
048a9c96ea
@@ -204,7 +204,7 @@ describe('getExpectedFinish()', () => {
|
||||
pausedAt: null,
|
||||
hasFinished: false,
|
||||
},
|
||||
runtime: {
|
||||
rundown: {
|
||||
actualStart: 79200000,
|
||||
plannedEnd: 600000,
|
||||
},
|
||||
@@ -358,7 +358,7 @@ describe('getCurrent()', () => {
|
||||
duration: 100,
|
||||
startedAt: null,
|
||||
},
|
||||
runtime: {
|
||||
rundown: {
|
||||
plannedEnd: null,
|
||||
},
|
||||
_timer: {
|
||||
@@ -383,7 +383,7 @@ describe('getCurrent()', () => {
|
||||
duration: 100,
|
||||
startedAt: 10,
|
||||
},
|
||||
runtime: {
|
||||
rundown: {
|
||||
plannedEnd: 100,
|
||||
},
|
||||
_timer: {
|
||||
@@ -408,7 +408,7 @@ describe('getCurrent()', () => {
|
||||
duration: 100,
|
||||
startedAt: 10,
|
||||
},
|
||||
runtime: {
|
||||
rundown: {
|
||||
plannedEnd: 100,
|
||||
},
|
||||
_timer: {
|
||||
@@ -434,7 +434,7 @@ describe('getCurrent()', () => {
|
||||
duration: Infinity, // not relevant,
|
||||
startedAt: 79200000, // 22:00:00
|
||||
},
|
||||
runtime: {
|
||||
rundown: {
|
||||
actualStart: 79200000,
|
||||
plannedEnd: 600000,
|
||||
},
|
||||
@@ -462,7 +462,7 @@ describe('getCurrent()', () => {
|
||||
duration: Infinity, // not relevant,
|
||||
startedAt: 79200000, // 22:00:00
|
||||
},
|
||||
runtime: {
|
||||
rundown: {
|
||||
actualStart: 82000000, // 22:46:40 <--- started now
|
||||
plannedEnd: 81000000, // 22:30:00
|
||||
},
|
||||
@@ -735,14 +735,14 @@ describe('getRuntimeOffset()', () => {
|
||||
_timer: {
|
||||
pausedAt: null,
|
||||
},
|
||||
runtime: {
|
||||
rundown: {
|
||||
actualStart: 150,
|
||||
plannedStart: 100,
|
||||
},
|
||||
} as RuntimeState;
|
||||
|
||||
const { offsetAbs } = getRuntimeOffset(state);
|
||||
expect(offsetAbs).toBe(50);
|
||||
const { absolute } = getRuntimeOffset(state);
|
||||
expect(absolute).toBe(50);
|
||||
});
|
||||
|
||||
it('added time subtracts time offset (positive offset)', () => {
|
||||
@@ -759,14 +759,14 @@ describe('getRuntimeOffset()', () => {
|
||||
_timer: {
|
||||
pausedAt: null,
|
||||
},
|
||||
runtime: {
|
||||
rundown: {
|
||||
actualStart: 150,
|
||||
plannedStart: 100,
|
||||
},
|
||||
} as RuntimeState;
|
||||
|
||||
const { offsetAbs } = getRuntimeOffset(state);
|
||||
expect(offsetAbs).toBe(60);
|
||||
const { absolute } = getRuntimeOffset(state);
|
||||
expect(absolute).toBe(60);
|
||||
});
|
||||
|
||||
it('considers running overtime (negative offset)', () => {
|
||||
@@ -784,14 +784,14 @@ describe('getRuntimeOffset()', () => {
|
||||
_timer: {
|
||||
pausedAt: null,
|
||||
},
|
||||
runtime: {
|
||||
rundown: {
|
||||
actualStart: 100,
|
||||
plannedStart: 100,
|
||||
},
|
||||
} as RuntimeState;
|
||||
|
||||
const { offsetAbs } = getRuntimeOffset(state);
|
||||
expect(offsetAbs).toBe(10);
|
||||
const { absolute } = getRuntimeOffset(state);
|
||||
expect(absolute).toBe(10);
|
||||
});
|
||||
|
||||
it('paused time is delayed time (negative offset)', () => {
|
||||
@@ -810,14 +810,14 @@ describe('getRuntimeOffset()', () => {
|
||||
_timer: {
|
||||
pausedAt: 125, // we have been paused for 25ms (see clock)
|
||||
},
|
||||
runtime: {
|
||||
rundown: {
|
||||
actualStart: 100,
|
||||
plannedStart: 100,
|
||||
},
|
||||
} as RuntimeState;
|
||||
|
||||
const { offsetAbs } = getRuntimeOffset(state);
|
||||
expect(offsetAbs).toBe(25);
|
||||
const { absolute } = getRuntimeOffset(state);
|
||||
expect(absolute).toBe(25);
|
||||
});
|
||||
|
||||
it('offset doesnt exist if we havent started', () => {
|
||||
@@ -831,14 +831,16 @@ describe('getRuntimeOffset()', () => {
|
||||
timeStrategy: 'lock-duration',
|
||||
linkStart: false,
|
||||
},
|
||||
runtime: {
|
||||
rundown: {
|
||||
selectedEventIndex: 0,
|
||||
numEvents: 2,
|
||||
offsetAbs: -77400000,
|
||||
plannedStart: 77400000,
|
||||
plannedEnd: 84600000,
|
||||
actualStart: null,
|
||||
expectedEnd: null,
|
||||
},
|
||||
offset: {
|
||||
absolute: -77400000,
|
||||
expectedRundownEnd: null,
|
||||
},
|
||||
timer: {
|
||||
addedTime: 0,
|
||||
@@ -853,8 +855,8 @@ describe('getRuntimeOffset()', () => {
|
||||
_timer: { pausedAt: null },
|
||||
} as RuntimeState;
|
||||
|
||||
const { offsetAbs } = getRuntimeOffset(state);
|
||||
expect(offsetAbs).toBe(0);
|
||||
const { absolute } = getRuntimeOffset(state);
|
||||
expect(absolute).toBe(0);
|
||||
});
|
||||
|
||||
it('with time-to-end, offsets dont exist if we are not in overtime', () => {
|
||||
@@ -882,14 +884,16 @@ describe('getRuntimeOffset()', () => {
|
||||
custom: {},
|
||||
delay: 0,
|
||||
},
|
||||
runtime: {
|
||||
rundown: {
|
||||
selectedEventIndex: 0,
|
||||
numEvents: 1,
|
||||
offsetAbs: 0,
|
||||
plannedStart: 77400000, // 21:30:00
|
||||
plannedEnd: 81000000, // 22:30:00
|
||||
actualStart: 78000000, // 21:40:00
|
||||
expectedEnd: 81600000, // 22:40:00
|
||||
},
|
||||
offset: {
|
||||
absolute: 0,
|
||||
expectedRundownEnd: 81600000, // 22:40:00
|
||||
},
|
||||
timer: {
|
||||
addedTime: 0,
|
||||
@@ -904,8 +908,8 @@ describe('getRuntimeOffset()', () => {
|
||||
_timer: { pausedAt: null },
|
||||
} as RuntimeState;
|
||||
|
||||
const { offsetAbs } = getRuntimeOffset(state);
|
||||
expect(offsetAbs).toBe(0);
|
||||
const { absolute } = getRuntimeOffset(state);
|
||||
expect(absolute).toBe(0);
|
||||
});
|
||||
|
||||
it('with time-to-end, offset is the overtime', () => {
|
||||
@@ -933,14 +937,16 @@ describe('getRuntimeOffset()', () => {
|
||||
custom: {},
|
||||
delay: 0,
|
||||
},
|
||||
runtime: {
|
||||
rundown: {
|
||||
selectedEventIndex: 0,
|
||||
numEvents: 1,
|
||||
offsetAbs: 0,
|
||||
plannedStart: 77400000, // 21:30:00
|
||||
plannedEnd: 81000000, // 22:30:00
|
||||
actualStart: 78000000, // 21:40:00
|
||||
expectedEnd: 81600000, // 22:40:00
|
||||
},
|
||||
offset: {
|
||||
absolute: 0,
|
||||
expectedRundownEnd: 81600000, // 22:40:00
|
||||
},
|
||||
timer: {
|
||||
addedTime: -200000,
|
||||
@@ -955,8 +961,8 @@ describe('getRuntimeOffset()', () => {
|
||||
_timer: { pausedAt: null },
|
||||
} as RuntimeState;
|
||||
|
||||
const { offsetAbs } = getRuntimeOffset(state);
|
||||
expect(offsetAbs).toBe(400000); // <--- offset is always the overtime
|
||||
const { absolute } = getRuntimeOffset(state);
|
||||
expect(absolute).toBe(400000); // <--- offset is always the overtime
|
||||
});
|
||||
|
||||
it('handles time-to-end started after the end time', () => {
|
||||
@@ -973,14 +979,16 @@ describe('getRuntimeOffset()', () => {
|
||||
timerType: TimerType.CountDown,
|
||||
countToEnd: true,
|
||||
},
|
||||
runtime: {
|
||||
rundown: {
|
||||
selectedEventIndex: 0,
|
||||
numEvents: 1,
|
||||
offsetAbs: 0,
|
||||
plannedStart: 77400000, // 21:30:00
|
||||
plannedEnd: 81000000, // 22:30:00
|
||||
actualStart: 82000000, // 22:46:40 <--- started now
|
||||
expectedEnd: 82000000 + 3600000, // <--- now + duration
|
||||
},
|
||||
offset: {
|
||||
absolute: 0,
|
||||
expectedRundownEnd: 82000000 + 3600000, // <--- now + duration
|
||||
},
|
||||
timer: {
|
||||
addedTime: 0,
|
||||
@@ -997,9 +1005,9 @@ describe('getRuntimeOffset()', () => {
|
||||
|
||||
const updateCurrent = getCurrent(state);
|
||||
state.timer.current = updateCurrent;
|
||||
const { offsetAbs } = getRuntimeOffset(state);
|
||||
expect(millisToString(offsetAbs)).toBe('00:16:40');
|
||||
expect(offsetAbs).toBe(82000000 - 81000000); // <-- now - planned end
|
||||
const { absolute } = getRuntimeOffset(state);
|
||||
expect(millisToString(absolute)).toBe('00:16:40');
|
||||
expect(absolute).toBe(82000000 - 81000000); // <-- now - planned end
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1018,15 +1026,15 @@ describe('getoffsetRel()', () => {
|
||||
_timer: {
|
||||
pausedAt: null,
|
||||
},
|
||||
runtime: {
|
||||
rundown: {
|
||||
actualStart: 150,
|
||||
plannedStart: 150,
|
||||
},
|
||||
} as RuntimeState;
|
||||
|
||||
const { offsetAbs, offsetRel } = getRuntimeOffset(state);
|
||||
expect(offsetAbs).toBe(0);
|
||||
expect(offsetRel).toBe(0);
|
||||
const { absolute, relative } = getRuntimeOffset(state);
|
||||
expect(absolute).toBe(0);
|
||||
expect(relative).toBe(0);
|
||||
});
|
||||
it('relative offset is 0 when starting after the planed time', () => {
|
||||
const state = {
|
||||
@@ -1042,15 +1050,15 @@ describe('getoffsetRel()', () => {
|
||||
_timer: {
|
||||
pausedAt: null,
|
||||
},
|
||||
runtime: {
|
||||
rundown: {
|
||||
actualStart: 150,
|
||||
plannedStart: 100,
|
||||
},
|
||||
} as RuntimeState;
|
||||
|
||||
const { offsetAbs, offsetRel } = getRuntimeOffset(state);
|
||||
expect(offsetAbs).toBe(50);
|
||||
expect(offsetRel).toBe(0);
|
||||
const { absolute, relative } = getRuntimeOffset(state);
|
||||
expect(absolute).toBe(50);
|
||||
expect(relative).toBe(0);
|
||||
});
|
||||
it('relative offset is 0 when starting before the planed time', () => {
|
||||
const state = {
|
||||
@@ -1066,15 +1074,15 @@ describe('getoffsetRel()', () => {
|
||||
_timer: {
|
||||
pausedAt: null,
|
||||
},
|
||||
runtime: {
|
||||
rundown: {
|
||||
actualStart: 100,
|
||||
plannedStart: 150,
|
||||
},
|
||||
} as RuntimeState;
|
||||
|
||||
const { offsetAbs, offsetRel } = getRuntimeOffset(state);
|
||||
expect(offsetAbs).toBe(-50);
|
||||
expect(offsetRel).toBe(0);
|
||||
const { absolute, relative } = getRuntimeOffset(state);
|
||||
expect(absolute).toBe(-50);
|
||||
expect(relative).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1175,14 +1183,16 @@ describe('getTimerPhase()', () => {
|
||||
clock: 55691050,
|
||||
eventNow: null,
|
||||
eventNext: null,
|
||||
runtime: {
|
||||
rundown: {
|
||||
selectedEventIndex: null,
|
||||
numEvents: 1,
|
||||
offsetAbs: 0,
|
||||
plannedStart: 55860000,
|
||||
plannedEnd: 55880000,
|
||||
actualStart: null,
|
||||
expectedEnd: null,
|
||||
},
|
||||
offset: {
|
||||
absolute: 0,
|
||||
expectedRundownEnd: null,
|
||||
},
|
||||
timer: {
|
||||
addedTime: 0,
|
||||
@@ -1213,14 +1223,16 @@ describe('getTimerPhase()', () => {
|
||||
clock: 55691050,
|
||||
eventNow: null,
|
||||
eventNext: null,
|
||||
runtime: {
|
||||
rundown: {
|
||||
selectedEventIndex: null,
|
||||
numEvents: 1,
|
||||
offsetAbs: 0,
|
||||
plannedStart: 55860000,
|
||||
plannedEnd: 55880000,
|
||||
actualStart: null,
|
||||
expectedEnd: null,
|
||||
},
|
||||
offset: {
|
||||
absolute: 0,
|
||||
expectedRundownEnd: null,
|
||||
},
|
||||
timer: {
|
||||
addedTime: 0,
|
||||
|
||||
Reference in New Issue
Block a user