mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-06 16:03:52 +00:00
Fix: link events in sheet when there is nothing to link (#1053)
* create failing tests * fix missing optional chaining
This commit is contained in:
committed by
GitHub
parent
c2fa115946
commit
0e32b3a3af
@@ -1,5 +1,21 @@
|
||||
import { CustomFields, HttpSubscription, OscSubscription } from 'ontime-types';
|
||||
import { sanitiseCustomFields, sanitiseHttpSubscriptions, sanitiseOscSubscriptions } from '../parserFunctions.js';
|
||||
import {
|
||||
CustomFields,
|
||||
DatabaseModel,
|
||||
EndAction,
|
||||
HttpSubscription,
|
||||
OntimeEvent,
|
||||
OntimeRundown,
|
||||
OscSubscription,
|
||||
SupportedEvent,
|
||||
TimeStrategy,
|
||||
TimerType,
|
||||
} from 'ontime-types';
|
||||
import {
|
||||
parseRundown,
|
||||
sanitiseCustomFields,
|
||||
sanitiseHttpSubscriptions,
|
||||
sanitiseOscSubscriptions,
|
||||
} from '../parserFunctions.js';
|
||||
|
||||
describe('sanitiseOscSubscriptions()', () => {
|
||||
it('returns an empty array if not an array', () => {
|
||||
@@ -155,3 +171,113 @@ describe('sanitiseCustomFields()', () => {
|
||||
expect(sanitationResult).toStrictEqual(expectedCustomFields);
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseRundown() linking', () => {
|
||||
const blankEvent: OntimeEvent = {
|
||||
id: '',
|
||||
type: SupportedEvent.Event,
|
||||
cue: '',
|
||||
title: '',
|
||||
note: '',
|
||||
endAction: EndAction.None,
|
||||
timerType: TimerType.CountDown,
|
||||
linkStart: null,
|
||||
timeStrategy: TimeStrategy.LockDuration,
|
||||
timeStart: 0,
|
||||
timeEnd: 0,
|
||||
duration: 0,
|
||||
isPublic: false,
|
||||
skip: false,
|
||||
colour: '',
|
||||
revision: 0,
|
||||
timeWarning: 120000,
|
||||
timeDanger: 60000,
|
||||
custom: {},
|
||||
};
|
||||
|
||||
it('returns linked events', () => {
|
||||
const data: Partial<DatabaseModel> = {
|
||||
rundown: [
|
||||
{
|
||||
id: '1',
|
||||
type: SupportedEvent.Event,
|
||||
skip: false,
|
||||
} as OntimeEvent,
|
||||
{
|
||||
id: '2',
|
||||
type: SupportedEvent.Event,
|
||||
linkStart: 'true',
|
||||
skip: false,
|
||||
} as OntimeEvent,
|
||||
],
|
||||
};
|
||||
|
||||
const expected: OntimeRundown = [
|
||||
{ ...blankEvent, id: '1', cue: '0' },
|
||||
{ ...blankEvent, id: '2', cue: '1', linkStart: '1' },
|
||||
];
|
||||
const result = parseRundown(data);
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
it('returns unlinkd if no previous', () => {
|
||||
const data: Partial<DatabaseModel> = {
|
||||
rundown: [
|
||||
{
|
||||
id: '2',
|
||||
type: SupportedEvent.Event,
|
||||
linkStart: 'true',
|
||||
skip: false,
|
||||
} as OntimeEvent,
|
||||
],
|
||||
};
|
||||
|
||||
const expected: OntimeRundown = [{ ...blankEvent, id: '2', cue: '0' }];
|
||||
const result = parseRundown(data);
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
it('returns linked events past blocks and delays', () => {
|
||||
const data: Partial<DatabaseModel> = {
|
||||
rundown: [
|
||||
{
|
||||
id: '1',
|
||||
type: SupportedEvent.Event,
|
||||
skip: false,
|
||||
} as OntimeEvent,
|
||||
{
|
||||
id: 'delay1',
|
||||
type: SupportedEvent.Delay,
|
||||
duration: 0,
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
type: SupportedEvent.Event,
|
||||
linkStart: 'true',
|
||||
skip: false,
|
||||
} as OntimeEvent,
|
||||
{
|
||||
id: 'block1',
|
||||
type: SupportedEvent.Block,
|
||||
title: '',
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
type: SupportedEvent.Event,
|
||||
linkStart: 'true',
|
||||
skip: false,
|
||||
} as OntimeEvent,
|
||||
],
|
||||
};
|
||||
|
||||
const expected: OntimeRundown = [
|
||||
{ ...blankEvent, id: '1', cue: '0' },
|
||||
{ id: 'delay1', type: SupportedEvent.Delay, duration: 0 },
|
||||
{ ...blankEvent, id: '2', cue: '1', linkStart: '1' },
|
||||
{ id: 'block1', type: SupportedEvent.Block, title: '' },
|
||||
{ ...blankEvent, id: '3', cue: '2', linkStart: '2' },
|
||||
];
|
||||
const result = parseRundown(data);
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -49,8 +49,8 @@ export const parseRundown = (data: Partial<DatabaseModel>): OntimeRundown => {
|
||||
|
||||
if (isOntimeEvent(event)) {
|
||||
if (event.linkStart) {
|
||||
const prevEvent = getLastEvent(rundown).lastEvent;
|
||||
event.linkStart = prevEvent.id;
|
||||
const prevId = getLastEvent(rundown).lastEvent?.id ?? null;
|
||||
event.linkStart = prevId;
|
||||
}
|
||||
newEvent = createEvent(event, eventIndex.toString());
|
||||
// skip if event is invalid
|
||||
|
||||
Reference in New Issue
Block a user