mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-10 09:53:48 +00:00
fix: parse nested events in rundown
This commit is contained in:
@@ -1,4 +1,12 @@
|
||||
import { SupportedEntry, OntimeEvent, OntimeDelay, OntimeBlock, Rundown, CustomField } from 'ontime-types';
|
||||
import {
|
||||
SupportedEntry,
|
||||
OntimeEvent,
|
||||
OntimeDelay,
|
||||
OntimeBlock,
|
||||
Rundown,
|
||||
CustomField,
|
||||
OntimeMilestone,
|
||||
} from 'ontime-types';
|
||||
|
||||
import { defaultRundown } from '../../../models/dataModel.js';
|
||||
|
||||
@@ -13,6 +21,12 @@ const baseBlock = {
|
||||
entries: [],
|
||||
};
|
||||
|
||||
const baseMilestone = {
|
||||
type: SupportedEntry.Milestone,
|
||||
cue: '',
|
||||
title: '',
|
||||
};
|
||||
|
||||
/**
|
||||
* Utility to create a Ontime event
|
||||
*/
|
||||
@@ -37,6 +51,13 @@ export function makeOntimeBlock(patch: Partial<OntimeBlock>): OntimeBlock {
|
||||
return { id: 'block', ...baseBlock, ...patch } as OntimeBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility to create a block event
|
||||
*/
|
||||
export function makeOntimeMilestone(patch: Partial<OntimeMilestone>): OntimeMilestone {
|
||||
return { id: 'milestone', ...baseMilestone, ...patch } as OntimeMilestone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility to create a rundown object
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { SupportedEntry, OntimeEvent, OntimeBlock, Rundown, CustomFields } from 'ontime-types';
|
||||
|
||||
import { defaultRundown } from '../../../models/dataModel.js';
|
||||
import { makeOntimeBlock, makeOntimeEvent } from '../__mocks__/rundown.mocks.js';
|
||||
import { makeOntimeBlock, makeOntimeEvent, makeOntimeMilestone } from '../__mocks__/rundown.mocks.js';
|
||||
|
||||
import { parseRundowns, parseRundown, handleCustomField, addToCustomAssignment } from '../rundown.parser.js';
|
||||
|
||||
@@ -241,7 +241,7 @@ describe('parseRundown()', () => {
|
||||
expect((parsedRundown.entries['21'] as OntimeEvent).custom).not.toHaveProperty('lighting');
|
||||
});
|
||||
|
||||
it('parses data in blocks', () => {
|
||||
it('parses data in groups', () => {
|
||||
const rundown = {
|
||||
id: 'test',
|
||||
title: '',
|
||||
@@ -254,20 +254,21 @@ describe('parseRundown()', () => {
|
||||
title: 'block-title',
|
||||
note: 'block-note',
|
||||
colour: 'red',
|
||||
entries: ['1', '2'],
|
||||
entries: ['1', '2', '3'],
|
||||
}),
|
||||
'1': makeOntimeEvent({ id: '1' }),
|
||||
'1': makeOntimeEvent({ id: '1', parent: 'block' }),
|
||||
'2': makeOntimeMilestone({ id: '2', parent: 'block' }),
|
||||
},
|
||||
revision: 1,
|
||||
} as Rundown;
|
||||
|
||||
const parsedRundown = parseRundown(rundown, {});
|
||||
expect(parsedRundown.order.length).toEqual(1);
|
||||
expect(parsedRundown.entries.block).toMatchObject({
|
||||
title: 'block-title',
|
||||
note: 'block-note',
|
||||
colour: 'red',
|
||||
entries: ['1'],
|
||||
expect(parsedRundown.order).toStrictEqual(['block']);
|
||||
expect(parsedRundown.flatOrder).toStrictEqual(['block', '1', '2']);
|
||||
expect(parsedRundown.entries).toMatchObject({
|
||||
block: { id: 'block', type: SupportedEntry.Block, entries: ['1', '2'] },
|
||||
'1': { id: '1', type: SupportedEntry.Event },
|
||||
'2': { id: '2', type: SupportedEntry.Milestone },
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -127,9 +127,9 @@ export function parseRundown(
|
||||
cleanupCustomFields(newNestedEvent.custom, parsedCustomFields);
|
||||
eventIndex += 1;
|
||||
} else if (isOntimeDelay(nestedEvent)) {
|
||||
newNestedEvent = { ...delayDef, duration: nestedEvent.duration, id };
|
||||
newNestedEvent = { ...delayDef, duration: nestedEvent.duration, id: nestedEventId };
|
||||
} else if (isOntimeMilestone(nestedEvent)) {
|
||||
newNestedEvent = createMilestone({ ...nestedEvent, id });
|
||||
newNestedEvent = createMilestone({ ...nestedEvent, id: nestedEventId });
|
||||
cleanupCustomFields(newNestedEvent.custom, parsedCustomFields);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user