fix: update time in block (#1474)

* fix: update time in block

---------

Co-authored-by: arc-alex <ac@omnivox.dk>
This commit is contained in:
Carlos Valente
2025-01-31 17:20:02 +01:00
committed by GitHub
parent f509655d31
commit 73ada99596
2 changed files with 152 additions and 15 deletions
@@ -1,7 +1,18 @@
import { PlayableEvent, Playback, TimerPhase } from 'ontime-types';
import { OntimeRundown, PlayableEvent, Playback, SupportedEvent, TimerPhase } from 'ontime-types';
import { deepmerge } from 'ontime-utils';
import { type RuntimeState, addTime, clear, getState, load, pause, roll, start, stop } from '../runtimeState.js';
import {
type RuntimeState,
addTime,
clear,
getState,
load,
loadBlock,
pause,
roll,
start,
stop,
} from '../runtimeState.js';
import { initRundown } from '../../services/rundown-service/RundownService.js';
const mockEvent = {
@@ -328,3 +339,125 @@ describe('roll mode', () => {
});
});
});
describe('loadBlock', () => {
test('from no-block to a block will clear startedAt', () => {
const rundown = [
{ id: '0', type: SupportedEvent.Event },
{ id: '1', type: SupportedEvent.Block },
{ id: '2', type: SupportedEvent.Event },
{ id: '3', type: SupportedEvent.Block },
{ id: '4', type: SupportedEvent.Event },
] as OntimeRundown;
const state = {
currentBlock: {
block: null,
startedAt: 123,
},
eventNow: rundown[2],
} as RuntimeState;
loadBlock(rundown, state);
expect(state).toMatchObject({
currentBlock: { block: rundown[1], startedAt: null },
eventNow: rundown[2],
});
});
test('from block to a different block will clear startedAt', () => {
const rundown = [
{ id: '0', type: SupportedEvent.Event },
{ id: '1', type: SupportedEvent.Block },
{ id: '2', type: SupportedEvent.Event },
{ id: '3', type: SupportedEvent.Block },
{ id: '4', type: SupportedEvent.Event },
] as OntimeRundown;
const state = {
currentBlock: {
block: rundown[1],
startedAt: 123,
},
eventNow: rundown[4],
} as RuntimeState;
loadBlock(rundown, state);
expect(state).toMatchObject({
currentBlock: { block: rundown[3], startedAt: null },
eventNow: rundown[4],
});
});
test('from block to a no-block will clear startedAt', () => {
const rundown = [
{ id: '0', type: SupportedEvent.Event },
{ id: '1', type: SupportedEvent.Block },
{ id: '2', type: SupportedEvent.Event },
{ id: '3', type: SupportedEvent.Block },
{ id: '4', type: SupportedEvent.Event },
] as OntimeRundown;
const state = {
currentBlock: {
block: rundown[1],
startedAt: 123,
},
eventNow: rundown[0],
} as RuntimeState;
loadBlock(rundown, state);
expect(state).toMatchObject({
currentBlock: { block: null, startedAt: null },
eventNow: rundown[0],
});
});
test('from block to same block will keep startedAt', () => {
const rundown = [
{ id: '0', type: SupportedEvent.Block },
{ id: '1', type: SupportedEvent.Event },
{ id: '2', type: SupportedEvent.Event },
] as OntimeRundown;
const state = {
currentBlock: {
block: rundown[0],
startedAt: 123,
},
eventNow: rundown[2],
} as RuntimeState;
loadBlock(rundown, state);
expect(state).toMatchObject({
currentBlock: { block: rundown[0], startedAt: 123 },
eventNow: rundown[2],
});
});
test('from no-block to no-block will keep startedAt', () => {
const rundown = [
{ id: '0', type: SupportedEvent.Event },
{ id: '1', type: SupportedEvent.Event },
] as OntimeRundown;
const state = {
currentBlock: {
block: null,
startedAt: 123,
},
eventNow: rundown[0],
} as RuntimeState;
loadBlock(rundown, state);
expect(state).toMatchObject({
currentBlock: { block: null, startedAt: 123 },
eventNow: rundown[0],
});
});
});