Files
ontime/apps/server/src/api-data/rundown/__mocks__/rundown.mocks.ts
T
Carlos Valente 0e6d6cd416 refactor: allow secondary rundowns (#2086)
* refactor: allow secondary rundowns

* ui: move dropdown

* feat: follow loaded

* ui: background edit warning

ui: fix disable radio button

* feat(ui): add loaded sufix in the rundown list

* feat(ui): add direct link to background edit from rundown manager

* fix: better fallback

* fix: default to is isCurrentRundown for nav bar colour

* chore: rename navigate to cuesheet

---------

Co-authored-by: alex-arc <ac@omnivox.dk>
2026-06-07 13:33:38 +02:00

99 lines
2.2 KiB
TypeScript

import {
CustomField,
EntryId,
OntimeDelay,
OntimeEvent,
OntimeGroup,
OntimeMilestone,
Rundown,
SupportedEntry,
isOntimeGroup,
} from 'ontime-types';
import { makeNewRundown } from '../../../models/dataModel.js';
const baseEvent = {
type: SupportedEntry.Event,
skip: false,
revision: 1,
};
const baseGroup = {
type: SupportedEntry.Group,
entries: [],
};
const baseMilestone = {
type: SupportedEntry.Milestone,
cue: '',
title: '',
};
/**
* Utility to create an Ontime event
*/
export function makeOntimeEvent(patch: Partial<OntimeEvent>): OntimeEvent {
return {
...baseEvent,
...patch,
} as OntimeEvent;
}
/**
* Utility to create a delay entry
*/
export function makeOntimeDelay(patch: Partial<OntimeDelay>): OntimeDelay {
return { id: 'delay', type: SupportedEntry.Delay, duration: 0, ...patch } as OntimeDelay;
}
/**
* Utility to create a group entry
*/
export function makeOntimeGroup(patch: Partial<OntimeGroup>): OntimeGroup {
return { id: 'group', ...baseGroup, ...patch } as OntimeGroup;
}
/**
* Utility to create a milestone entry
*/
export function makeOntimeMilestone(patch: Partial<OntimeMilestone>): OntimeMilestone {
return { id: 'milestone', ...baseMilestone, ...patch } as OntimeMilestone;
}
/**
* Utility to create a rundown object.
* Derives flatOrder from order/entries when the patch does not provide one,
* so test fixtures match the shape of a processed rundown.
*/
export function makeRundown(patch: Partial<Rundown>): Rundown {
const rundown = { ...makeNewRundown(), ...patch };
if (!patch.flatOrder) {
const flatOrder: EntryId[] = [];
for (const id of rundown.order) {
flatOrder.push(id);
const entry = rundown.entries[id];
if (isOntimeGroup(entry)) {
flatOrder.push(...entry.entries);
}
}
rundown.flatOrder = flatOrder;
}
return rundown;
}
export function makeCustomField(patch: Partial<CustomField>): CustomField {
return {
type: 'text',
colour: '#000000',
label: 'Custom Field',
...patch,
};
}
/**
* Utility to generate a rundown of OntimeEvents form partial objects
*/
export function prepareTimedEvents(events: Partial<OntimeEvent>[]): OntimeEvent[] {
return events.map(makeOntimeEvent);
}