* fix test

* add comment
This commit is contained in:
Alex Christoffer Rasmussen
2025-05-02 19:30:55 +02:00
committed by Carlos Valente
parent 92fbef3515
commit 94b80d3b0b
@@ -88,8 +88,13 @@ describe('mutation on runtimeState', () => {
});
describe('playback operations', async () => {
it('refuses if nothing is loaded', () => {
initRundown(makeRundown({}), {});
it('refuses if nothing is loaded', async () => {
// force update
vi.useFakeTimers();
await initRundown(makeRundown({}), {});
vi.runAllTimers();
vi.useRealTimers();
let success = start(mockState);
expect(success).toBe(false);
@@ -97,9 +102,15 @@ describe('mutation on runtimeState', () => {
expect(success).toBe(false);
});
test('normal playback cycle', () => {
test('normal playback cycle', async () => {
// 1. Load event
const mockRundown = makeRundown({ entries: { [mockEvent.id]: mockEvent }, order: [mockEvent.id] });
// force update
vi.useFakeTimers();
await initRundown(mockRundown, {});
vi.runAllTimers();
vi.useRealTimers();
load(mockEvent, mockRundown, mockRundown.order);
let newState = getState();
expect(newState.eventNow?.id).toBe(mockEvent.id);
@@ -164,20 +175,19 @@ describe('mutation on runtimeState', () => {
expect(newState.runtime.actualStart).toBeNull();
});
// do this before the test so that it is applied
const entries = {
event1: { ...mockEvent, id: 'event1', timeStart: 0, timeEnd: 1000, duration: 1000, parent: null },
event2: { ...mockEvent, id: 'event2', timeStart: 1000, timeEnd: 1500, duration: 500, parent: null },
};
const rundown = makeRundown({ entries, order: ['event1', 'event2'] });
// force update
vi.useFakeTimers();
await initRundown(rundown, {});
vi.runAllTimers();
vi.useRealTimers();
test('runtime offset', async () => {
const entries = {
event1: { ...mockEvent, id: 'event1', timeStart: 0, timeEnd: 1000, duration: 1000, parent: null },
event2: { ...mockEvent, id: 'event2', timeStart: 1000, timeEnd: 1500, duration: 500, parent: null },
};
const rundown = makeRundown({ entries, order: ['event1', 'event2'] });
// force update
vi.useFakeTimers();
await initRundown(rundown, {});
vi.runAllTimers();
vi.useRealTimers();
// 1. Load event
load(entries.event1, rundown, rundown.order);
let newState = getState();
@@ -284,7 +294,7 @@ describe('roll mode', () => {
});
});
describe('roll takover', () => {
describe('roll takeover', async () => {
const rundown = makeRundown({
entries: {
1: { ...mockEvent, id: '1', timeStart: 1000, duration: 1000, timeEnd: 2000 },
@@ -294,6 +304,12 @@ describe('roll mode', () => {
order: ['1', '2', '3'],
});
// force update
vi.useFakeTimers();
await initRundown(rundown, {});
vi.runAllTimers();
vi.useRealTimers();
test('from load', () => {
load(rundown.entries[3] as PlayableEvent, rundown, rundown.order);
const result = roll(rundown, rundown.order);
@@ -313,7 +329,7 @@ describe('roll mode', () => {
});
describe('roll continue with offset', () => {
test('no gaps', () => {
test('no gaps', async () => {
const rundown = makeRundown({
entries: {
1: { ...mockEvent, id: '1', timeStart: 1000, duration: 1000, timeEnd: 2000 },
@@ -323,11 +339,19 @@ describe('roll mode', () => {
order: ['1', '2', '3'],
});
// force update
vi.useFakeTimers();
await initRundown(rundown, {});
vi.runAllTimers();
load(rundown.entries[1] as PlayableEvent, rundown, rundown.order);
start();
// the current offset after manual play
const currentOffset = getState().runtime.offset;
let result = roll(rundown, rundown.order, getState().runtime.offset);
expect(result).toStrictEqual({ eventId: '1', didStart: false });
expect(getState().runtime.offset).toBe(1000);
// the current offset should be maintain by roll mode whn taking over from play
expect(getState().runtime.offset).toBe(currentOffset);
vi.setSystemTime('jan 1 00:00:01');
result = roll(rundown, rundown.order, getState().runtime.offset);
@@ -338,6 +362,8 @@ describe('roll mode', () => {
result = roll(rundown, rundown.order, getState().runtime.offset);
expect(result).toStrictEqual({ eventId: '3', didStart: true });
expect(getState().runtime.offset).toBe(1000);
vi.useRealTimers();
});
});
});