chore: improve convention entry <> event

This commit is contained in:
Carlos Valente
2025-04-17 12:40:32 +02:00
committed by arc-alex
parent 3754c374c3
commit 3118c20719
28 changed files with 245 additions and 245 deletions
+29 -29
View File
@@ -1,5 +1,5 @@
import type { OntimeDelay, OntimeEntry, OntimeEvent, RundownEntries } from 'ontime-types';
import { SupportedEvent } from 'ontime-types';
import { SupportedEntry } from 'ontime-types';
import { getCueCandidate, getIncrement, sanitiseCue } from './cueUtils.js';
@@ -37,8 +37,8 @@ describe('getCueCandidate()', () => {
describe('in the beginning of the rundown', () => {
it('names cue as 1 if next event does not collide', () => {
const entries: RundownEntries = {
'1': { id: '1', cue: '10', type: SupportedEvent.Event } as OntimeEvent,
'2': { id: '2', cue: '11', type: SupportedEvent.Event } as OntimeEvent,
'1': { id: '1', cue: '10', type: SupportedEntry.Event } as OntimeEvent,
'2': { id: '2', cue: '11', type: SupportedEntry.Event } as OntimeEvent,
};
const cue = getCueCandidate(entries, ['1', '2']);
expect(cue).toBe('1');
@@ -46,8 +46,8 @@ describe('getCueCandidate()', () => {
it('creates decimal stem if next cue is 1', () => {
const entries: RundownEntries = {
'1': { id: '1', cue: '1', type: SupportedEvent.Event } as OntimeEvent,
'2': { id: '2', cue: '10', type: SupportedEvent.Event } as OntimeEvent,
'1': { id: '1', cue: '1', type: SupportedEntry.Event } as OntimeEvent,
'2': { id: '2', cue: '10', type: SupportedEntry.Event } as OntimeEvent,
};
const cue = getCueCandidate(entries, ['1', '2']);
expect(cue).toBe('0.1');
@@ -57,8 +57,8 @@ describe('getCueCandidate()', () => {
describe('in the middle of the rundown', () => {
it('names cue as an increment if next event has different stem (case of numbers)', () => {
const entries: RundownEntries = {
'1': { id: '1', cue: '1', type: SupportedEvent.Event } as OntimeEvent,
'2': { id: '2', cue: '10', type: SupportedEvent.Event } as OntimeEvent,
'1': { id: '1', cue: '1', type: SupportedEntry.Event } as OntimeEvent,
'2': { id: '2', cue: '10', type: SupportedEntry.Event } as OntimeEvent,
};
const cue = getCueCandidate(entries, ['1', '2'], '1');
expect(cue).toBe('2');
@@ -66,11 +66,11 @@ describe('getCueCandidate()', () => {
it('names cue as an increment if next event has different stem (case of letters)', () => {
const entries: RundownEntries = {
'1': { id: '1', cue: 'Presenter', type: SupportedEvent.Event } as OntimeEvent,
'1': { id: '1', cue: 'Presenter', type: SupportedEntry.Event } as OntimeEvent,
'2': {
id: '2',
cue: 'Interval',
type: SupportedEvent.Event,
type: SupportedEntry.Event,
} as OntimeEntry,
};
const cue = getCueCandidate(entries, ['1', '2'], '1');
@@ -79,8 +79,8 @@ describe('getCueCandidate()', () => {
it('creates decimal stem if next cue has same stem (case of numbers)', () => {
const entries: RundownEntries = {
'1': { id: '1', cue: '1', type: SupportedEvent.Event } as OntimeEvent,
'2': { id: '2', cue: '2', type: SupportedEvent.Event } as OntimeEvent,
'1': { id: '1', cue: '1', type: SupportedEntry.Event } as OntimeEvent,
'2': { id: '2', cue: '2', type: SupportedEntry.Event } as OntimeEvent,
};
const cue = getCueCandidate(entries, ['1', '2'], '1');
expect(cue).toBe('1.1');
@@ -88,8 +88,8 @@ describe('getCueCandidate()', () => {
it('creates decimal stem if next cue has same stem (case of letters)', () => {
const entries: RundownEntries = {
'1': { id: '1', cue: 'Presenter1', type: SupportedEvent.Event } as OntimeEvent,
'2': { id: '2', cue: 'Presenter2', type: SupportedEvent.Event } as OntimeEvent,
'1': { id: '1', cue: 'Presenter1', type: SupportedEntry.Event } as OntimeEvent,
'2': { id: '2', cue: 'Presenter2', type: SupportedEntry.Event } as OntimeEvent,
};
const cue = getCueCandidate(entries, ['1', '2'], '1');
expect(cue).toBe('Presenter1.1');
@@ -99,8 +99,8 @@ describe('getCueCandidate()', () => {
describe('considers edge cases', () => {
it('previousEvent might not be a cue', () => {
const entries: RundownEntries = {
'1': { id: '1', cue: '10', type: SupportedEvent.Event } as OntimeEvent,
'2': { id: '2', type: SupportedEvent.Delay } as OntimeDelay,
'1': { id: '1', cue: '10', type: SupportedEntry.Event } as OntimeEvent,
'2': { id: '2', type: SupportedEntry.Delay } as OntimeDelay,
};
const cue = getCueCandidate(entries, ['1', '2'], '2');
expect(cue).toBe('11');
@@ -109,8 +109,8 @@ describe('getCueCandidate()', () => {
it('there might not be events before', () => {
const entries: RundownEntries = {
'1': { id: '1', type: SupportedEvent.Delay } as OntimeDelay,
'2': { id: '2', type: SupportedEvent.Delay } as OntimeDelay,
'1': { id: '1', type: SupportedEntry.Delay } as OntimeDelay,
'2': { id: '2', type: SupportedEntry.Delay } as OntimeDelay,
};
const cue = getCueCandidate(entries, ['1', '2'], '2');
expect(cue).toBe('1');
@@ -121,8 +121,8 @@ describe('findCueName() with mixed events', () => {
describe('in the beginning of the rundown', () => {
it('names cue as 1 if next event does not collide', () => {
const entries: RundownEntries = {
'1': { id: '1', cue: '10', type: SupportedEvent.Event } as OntimeEvent,
'2': { id: '2', cue: '11', type: SupportedEvent.Event } as OntimeEvent,
'1': { id: '1', cue: '10', type: SupportedEntry.Event } as OntimeEvent,
'2': { id: '2', cue: '11', type: SupportedEntry.Event } as OntimeEvent,
};
const cue = getCueCandidate(entries, ['1', '2']);
expect(cue).toBe('1');
@@ -130,8 +130,8 @@ describe('findCueName() with mixed events', () => {
it('creates decimal stem if next cue is 1', () => {
const entries: RundownEntries = {
'1': { id: '1', cue: '1', type: SupportedEvent.Event } as OntimeEvent,
'2': { id: '2', cue: '10', type: SupportedEvent.Event } as OntimeEvent,
'1': { id: '1', cue: '1', type: SupportedEntry.Event } as OntimeEvent,
'2': { id: '2', cue: '10', type: SupportedEntry.Event } as OntimeEvent,
};
const cue = getCueCandidate(entries, ['1', '2']);
expect(cue).toBe('0.1');
@@ -141,8 +141,8 @@ describe('findCueName() with mixed events', () => {
describe('in the middle of the rundown', () => {
it('names cue as an increment if next event has different stem (case of numbers)', () => {
const entries: RundownEntries = {
'1': { id: '1', cue: '1', type: SupportedEvent.Event } as OntimeEvent,
'2': { id: '2', cue: '10', type: SupportedEvent.Event } as OntimeEvent,
'1': { id: '1', cue: '1', type: SupportedEntry.Event } as OntimeEvent,
'2': { id: '2', cue: '10', type: SupportedEntry.Event } as OntimeEvent,
};
const cue = getCueCandidate(entries, ['1', '2'], '1');
expect(cue).toBe('2');
@@ -150,8 +150,8 @@ describe('findCueName() with mixed events', () => {
it('names cue as an increment if next event has different stem (case of letters)', () => {
const entries: RundownEntries = {
'1': { id: '1', cue: 'Presenter', type: SupportedEvent.Event } as OntimeEvent,
'2': { id: '2', cue: 'Interval', type: SupportedEvent.Event } as OntimeEvent,
'1': { id: '1', cue: 'Presenter', type: SupportedEntry.Event } as OntimeEvent,
'2': { id: '2', cue: 'Interval', type: SupportedEntry.Event } as OntimeEvent,
};
const cue = getCueCandidate(entries, ['1', '2'], '1');
expect(cue).toBe('Presenter2');
@@ -159,8 +159,8 @@ describe('findCueName() with mixed events', () => {
it('creates decimal stem if next cue has same stem (case of numbers)', () => {
const entries: RundownEntries = {
'1': { id: '1', cue: '1', type: SupportedEvent.Event } as OntimeEvent,
'2': { id: '2', cue: '2', type: SupportedEvent.Event } as OntimeEvent,
'1': { id: '1', cue: '1', type: SupportedEntry.Event } as OntimeEvent,
'2': { id: '2', cue: '2', type: SupportedEntry.Event } as OntimeEvent,
};
const cue = getCueCandidate(entries, ['1', '2'], '1');
expect(cue).toBe('1.1');
@@ -168,8 +168,8 @@ describe('findCueName() with mixed events', () => {
it('creates decimal stem if next cue has same stem (case of letters)', () => {
const entries: RundownEntries = {
'1': { id: '1', cue: 'Presenter1', type: SupportedEvent.Event } as OntimeEvent,
'2': { id: '2', cue: 'Presenter2', type: SupportedEvent.Event } as OntimeEvent,
'1': { id: '1', cue: 'Presenter1', type: SupportedEntry.Event } as OntimeEvent,
'2': { id: '2', cue: 'Presenter2', type: SupportedEntry.Event } as OntimeEvent,
};
const cue = getCueCandidate(entries, ['1', '2'], '1');
expect(cue).toBe('Presenter1.1');
@@ -1,5 +1,5 @@
import type { OntimeBlock, OntimeDelay, OntimeEntry, OntimeEvent } from 'ontime-types';
import { SupportedEvent } from 'ontime-types';
import { SupportedEntry } from 'ontime-types';
import {
getLastEvent,
@@ -16,9 +16,9 @@ describe('getNext()', () => {
it('returns the next event of type event', () => {
const testRundown = {
entries: {
'1': { id: '1', type: SupportedEvent.Event } as OntimeEvent,
'2': { id: '2', type: SupportedEvent.Event } as OntimeEvent,
'3': { id: '3', type: SupportedEvent.Event } as OntimeEvent,
'1': { id: '1', type: SupportedEntry.Event } as OntimeEvent,
'2': { id: '2', type: SupportedEntry.Event } as OntimeEvent,
'3': { id: '3', type: SupportedEntry.Event } as OntimeEvent,
},
order: ['1', '2', '3'],
};
@@ -31,10 +31,10 @@ describe('getNext()', () => {
it('returns any type of OntimeEntry ', () => {
const testRundown = {
entries: {
'1': { id: '1', type: SupportedEvent.Event } as OntimeEvent,
'2': { id: '2', type: SupportedEvent.Delay } as OntimeDelay,
'3': { id: '3', type: SupportedEvent.Block } as OntimeBlock,
'4': { id: '4', type: SupportedEvent.Event } as OntimeEvent,
'1': { id: '1', type: SupportedEntry.Event } as OntimeEvent,
'2': { id: '2', type: SupportedEntry.Delay } as OntimeDelay,
'3': { id: '3', type: SupportedEntry.Block } as OntimeBlock,
'4': { id: '4', type: SupportedEntry.Event } as OntimeEvent,
},
order: ['1', '2', '3', '4'],
};
@@ -47,9 +47,9 @@ describe('getNext()', () => {
it('returns null if none found', () => {
const testRundown = {
entries: {
'1': { id: '1', type: SupportedEvent.Event } as OntimeEvent,
'2': { id: '2', type: SupportedEvent.Event } as OntimeEvent,
'3': { id: '3', type: SupportedEvent.Event } as OntimeEvent,
'1': { id: '1', type: SupportedEntry.Event } as OntimeEvent,
'2': { id: '2', type: SupportedEntry.Event } as OntimeEvent,
'3': { id: '3', type: SupportedEntry.Event } as OntimeEvent,
},
order: ['1', '2', '3'],
};
@@ -62,9 +62,9 @@ describe('getNext()', () => {
describe('getNextEvent()', () => {
it('returns the next event of type event', () => {
const testRundown = [
{ id: '1', type: SupportedEvent.Event } as OntimeEvent,
{ id: '2', type: SupportedEvent.Event } as OntimeEvent,
{ id: '3', type: SupportedEvent.Event } as OntimeEvent,
{ id: '1', type: SupportedEntry.Event } as OntimeEvent,
{ id: '2', type: SupportedEntry.Event } as OntimeEvent,
{ id: '3', type: SupportedEntry.Event } as OntimeEvent,
];
const { nextEvent, nextIndex } = getNextEvent(testRundown, '1');
@@ -74,10 +74,10 @@ describe('getNextEvent()', () => {
it('ignores other event types', () => {
const testRundown = [
{ id: '1', type: SupportedEvent.Event } as OntimeEvent,
{ id: '2', type: SupportedEvent.Delay } as OntimeDelay,
{ id: '3', type: SupportedEvent.Block } as OntimeBlock,
{ id: '4', type: SupportedEvent.Event } as OntimeEvent,
{ id: '1', type: SupportedEntry.Event } as OntimeEvent,
{ id: '2', type: SupportedEntry.Delay } as OntimeDelay,
{ id: '3', type: SupportedEntry.Block } as OntimeBlock,
{ id: '4', type: SupportedEntry.Event } as OntimeEvent,
];
const { nextEvent, nextIndex } = getNextEvent(testRundown, '1');
@@ -87,9 +87,9 @@ describe('getNextEvent()', () => {
it('returns null if none found', () => {
const testRundown = [
{ id: '1', type: SupportedEvent.Event } as OntimeEvent,
{ id: '2', type: SupportedEvent.Delay } as OntimeDelay,
{ id: '3', type: SupportedEvent.Block } as OntimeBlock,
{ id: '1', type: SupportedEntry.Event } as OntimeEvent,
{ id: '2', type: SupportedEntry.Delay } as OntimeDelay,
{ id: '3', type: SupportedEntry.Block } as OntimeBlock,
];
const { nextEvent, nextIndex } = getNextEvent(testRundown, '1');
@@ -102,9 +102,9 @@ describe('getPrevious()', () => {
it('returns the previous event of type event', () => {
const testRundown = {
entries: {
'1': { id: '1', type: SupportedEvent.Event } as OntimeEvent,
'2': { id: '2', type: SupportedEvent.Event } as OntimeEvent,
'3': { id: '3', type: SupportedEvent.Event } as OntimeEvent,
'1': { id: '1', type: SupportedEntry.Event } as OntimeEvent,
'2': { id: '2', type: SupportedEntry.Event } as OntimeEvent,
'3': { id: '3', type: SupportedEntry.Event } as OntimeEvent,
},
order: ['1', '2', '3'],
};
@@ -117,10 +117,10 @@ describe('getPrevious()', () => {
it('allow other event types', () => {
const testRundown = {
entries: {
'1': { id: '1', type: SupportedEvent.Event } as OntimeEvent,
'2': { id: '2', type: SupportedEvent.Delay } as OntimeDelay,
'3': { id: '3', type: SupportedEvent.Block } as OntimeBlock,
'4': { id: '4', type: SupportedEvent.Event } as OntimeEvent,
'1': { id: '1', type: SupportedEntry.Event } as OntimeEvent,
'2': { id: '2', type: SupportedEntry.Delay } as OntimeDelay,
'3': { id: '3', type: SupportedEntry.Block } as OntimeBlock,
'4': { id: '4', type: SupportedEntry.Event } as OntimeEvent,
},
order: ['1', '2', '3', '4'],
};
@@ -133,8 +133,8 @@ describe('getPrevious()', () => {
it('returns null if none found', () => {
const testRundown = {
entries: {
'2': { id: '2', type: SupportedEvent.Event } as OntimeEvent,
'3': { id: '3', type: SupportedEvent.Event } as OntimeEvent,
'2': { id: '2', type: SupportedEntry.Event } as OntimeEvent,
'3': { id: '3', type: SupportedEntry.Event } as OntimeEvent,
},
order: ['1', '2', '3'],
};
@@ -149,9 +149,9 @@ describe('getPreviousEvent()', () => {
it('returns the previous event of type event', () => {
const testRundown = {
entries: {
'1': { id: '1', type: SupportedEvent.Event } as OntimeEvent,
'2': { id: '2', type: SupportedEvent.Event } as OntimeEvent,
'3': { id: '3', type: SupportedEvent.Event } as OntimeEvent,
'1': { id: '1', type: SupportedEntry.Event } as OntimeEvent,
'2': { id: '2', type: SupportedEntry.Event } as OntimeEvent,
'3': { id: '3', type: SupportedEntry.Event } as OntimeEvent,
},
order: ['1', '2', '3'],
};
@@ -164,10 +164,10 @@ describe('getPreviousEvent()', () => {
it('ignores other event types', () => {
const testRundown = {
entries: {
'1': { id: '1', type: SupportedEvent.Event } as OntimeEvent,
'2': { id: '2', type: SupportedEvent.Delay } as OntimeDelay,
'3': { id: '3', type: SupportedEvent.Block } as OntimeBlock,
'4': { id: '4', type: SupportedEvent.Event } as OntimeEvent,
'1': { id: '1', type: SupportedEntry.Event } as OntimeEvent,
'2': { id: '2', type: SupportedEntry.Delay } as OntimeDelay,
'3': { id: '3', type: SupportedEntry.Block } as OntimeBlock,
'4': { id: '4', type: SupportedEntry.Event } as OntimeEvent,
},
order: ['1', '2', '3', '4'],
};
@@ -180,9 +180,9 @@ describe('getPreviousEvent()', () => {
it('returns null if none found', () => {
const testRundown = {
entries: {
'2': { id: '2', type: SupportedEvent.Delay } as OntimeDelay,
'3': { id: '3', type: SupportedEvent.Block } as OntimeBlock,
'4': { id: '4', type: SupportedEvent.Event } as OntimeEvent,
'2': { id: '2', type: SupportedEntry.Delay } as OntimeDelay,
'3': { id: '3', type: SupportedEntry.Block } as OntimeBlock,
'4': { id: '4', type: SupportedEntry.Event } as OntimeEvent,
},
order: ['2', '3', '4'],
};
@@ -244,10 +244,10 @@ describe('swapEventData', () => {
describe('getLastEvent', () => {
it('returns the last event of type event', () => {
const testRundown: OntimeEntry[] = [
{ id: '1', type: SupportedEvent.Event } as OntimeEvent,
{ id: '2', type: SupportedEvent.Delay } as OntimeDelay,
{ id: '3', type: SupportedEvent.Event } as OntimeEvent,
{ id: '4', type: SupportedEvent.Block } as OntimeBlock,
{ id: '1', type: SupportedEntry.Event } as OntimeEvent,
{ id: '2', type: SupportedEntry.Delay } as OntimeDelay,
{ id: '3', type: SupportedEntry.Event } as OntimeEvent,
{ id: '4', type: SupportedEntry.Block } as OntimeBlock,
];
const { lastEvent } = getLastEvent(testRundown);
@@ -255,7 +255,7 @@ describe('getLastEvent', () => {
});
it('handles rundowns with a single event', () => {
const testRundown: OntimeEntry[] = [{ id: '1', type: SupportedEvent.Event } as OntimeEvent];
const testRundown: OntimeEntry[] = [{ id: '1', type: SupportedEntry.Event } as OntimeEvent];
const { lastEvent } = getLastEvent(testRundown);
expect(lastEvent?.id).toBe('1');
});
@@ -263,10 +263,10 @@ describe('getLastEvent', () => {
describe('getLastNormal', () => {
it('returns the last entry', () => {
const entries = {
4: { id: '4', type: SupportedEvent.Block } as OntimeBlock,
1: { id: '1', type: SupportedEvent.Event } as OntimeEvent,
3: { id: '3', type: SupportedEvent.Event } as OntimeEvent,
2: { id: '2', type: SupportedEvent.Delay } as OntimeDelay,
4: { id: '4', type: SupportedEntry.Block } as OntimeBlock,
1: { id: '1', type: SupportedEntry.Event } as OntimeEvent,
3: { id: '3', type: SupportedEntry.Event } as OntimeEvent,
2: { id: '2', type: SupportedEntry.Delay } as OntimeDelay,
};
const order = ['1', '2', '3', '4'];
@@ -277,7 +277,7 @@ describe('getLastEvent', () => {
it('handles rundowns with a single event', () => {
const entries = {
1: { id: '1', type: SupportedEvent.Event } as OntimeEvent,
1: { id: '1', type: SupportedEntry.Event } as OntimeEvent,
};
const lastEvent = getLastNormal(entries, ['1']);
@@ -286,8 +286,8 @@ describe('getLastEvent', () => {
it('handles empty order', () => {
const testRundown = {
1: { id: '1', type: SupportedEvent.Event } as OntimeEvent,
2: { id: '2', type: SupportedEvent.Event } as OntimeEvent,
1: { id: '1', type: SupportedEntry.Event } as OntimeEvent,
2: { id: '2', type: SupportedEntry.Event } as OntimeEvent,
};
const lastEntry = getLastNormal(testRundown, []);
@@ -303,14 +303,14 @@ describe('getLastEvent', () => {
describe('getPreviousBlock()', () => {
const testRundown = {
entries: {
a: { id: 'a', type: SupportedEvent.Event } as OntimeEvent,
b: { id: 'b', type: SupportedEvent.Event } as OntimeEvent,
c: { id: 'c', type: SupportedEvent.Event } as OntimeEvent,
d: { id: 'd', type: SupportedEvent.Delay } as OntimeDelay,
e: { id: 'e', type: SupportedEvent.Block } as OntimeBlock,
f: { id: 'f', type: SupportedEvent.Event } as OntimeEvent,
g: { id: 'g', type: SupportedEvent.Block } as OntimeBlock,
h: { id: 'h', type: SupportedEvent.Event } as OntimeEvent,
a: { id: 'a', type: SupportedEntry.Event } as OntimeEvent,
b: { id: 'b', type: SupportedEntry.Event } as OntimeEvent,
c: { id: 'c', type: SupportedEntry.Event } as OntimeEvent,
d: { id: 'd', type: SupportedEntry.Delay } as OntimeDelay,
e: { id: 'e', type: SupportedEntry.Block } as OntimeBlock,
f: { id: 'f', type: SupportedEntry.Event } as OntimeEvent,
g: { id: 'g', type: SupportedEntry.Block } as OntimeBlock,
h: { id: 'h', type: SupportedEntry.Event } as OntimeEvent,
},
order: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'],
};
@@ -331,7 +331,7 @@ describe('getLastEvent', () => {
it('also works on index 0', () => {
testRundown.order.unshift('0');
// @ts-expect-error -- we are adding an event to the rundown
testRundown.entries['0'] = { id: '0', type: SupportedEvent.Block } as OntimeBlock;
testRundown.entries['0'] = { id: '0', type: SupportedEntry.Block } as OntimeBlock;
const block = getPreviousBlock(testRundown, 'a');
expect(block?.id).toBe('0');
});
@@ -339,11 +339,11 @@ describe('getLastEvent', () => {
it('returns the parent block if nested event', () => {
const testRundown = {
entries: {
1: { id: '1', type: SupportedEvent.Event } as OntimeEvent,
block: { id: 'block', type: SupportedEvent.Block, events: ['21', '22', '23'] } as OntimeBlock,
21: { id: '21', type: SupportedEvent.Event, parent: 'block' } as OntimeEvent,
22: { id: '22', type: SupportedEvent.Event, parent: 'block' } as OntimeEvent,
23: { id: '23', type: SupportedEvent.Event, parent: 'block' } as OntimeEvent,
1: { id: '1', type: SupportedEntry.Event } as OntimeEvent,
block: { id: 'block', type: SupportedEntry.Block, events: ['21', '22', '23'] } as OntimeBlock,
21: { id: '21', type: SupportedEntry.Event, parent: 'block' } as OntimeEvent,
22: { id: '22', type: SupportedEntry.Event, parent: 'block' } as OntimeEvent,
23: { id: '23', type: SupportedEntry.Event, parent: 'block' } as OntimeEvent,
},
order: ['1', 'block'],
};