mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-21 06:59:09 +00:00
refactor: extract parent resolution
This commit is contained in:
committed by
Carlos Valente
parent
80a3b04493
commit
5777ef3532
@@ -13,6 +13,7 @@ import {
|
||||
getNextNormal,
|
||||
getPreviousGroupNormal,
|
||||
getPreviousNormal,
|
||||
resolveInsertParent,
|
||||
swapEventData,
|
||||
} from './rundownUtils';
|
||||
import { demoDb } from './rundownUtils.mock';
|
||||
@@ -272,6 +273,43 @@ describe('getInsertAfterId()', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('resolveInsertParent()', () => {
|
||||
const rundown = {
|
||||
id: 'test',
|
||||
title: 'test',
|
||||
entries: {
|
||||
top: { id: 'top', type: SupportedEntry.Event, parent: null } as OntimeEvent,
|
||||
group: { id: 'group', type: SupportedEntry.Group, entries: ['31', '32'] } as unknown as OntimeGroup,
|
||||
'31': { id: '31', type: SupportedEntry.Event, parent: 'group' } as OntimeEvent,
|
||||
'32': { id: '32', type: SupportedEntry.Event, parent: 'group' } as OntimeEvent,
|
||||
},
|
||||
order: ['top', 'group'],
|
||||
flatOrder: ['top', 'group', '31', '32'],
|
||||
revision: 1,
|
||||
} as Rundown;
|
||||
|
||||
it('returns explicit parent id', () => {
|
||||
expect(resolveInsertParent(rundown, { parent: 'group' })).toBe('group');
|
||||
});
|
||||
|
||||
it('returns non-existent explicit parent id as-is', () => {
|
||||
expect(resolveInsertParent(rundown, { parent: 'missing' })).toBe('missing');
|
||||
});
|
||||
|
||||
it('infers parent id from sibling when parent is omitted', () => {
|
||||
expect(resolveInsertParent(rundown, { after: '31' })).toBe('group');
|
||||
expect(resolveInsertParent(rundown, { before: '32' })).toBe('group');
|
||||
});
|
||||
|
||||
it('returns null when no grouped sibling reference exists', () => {
|
||||
expect(resolveInsertParent(rundown, { after: 'top' })).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null when no references are provided', () => {
|
||||
expect(resolveInsertParent(rundown, {})).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('addToRundown()', () => {
|
||||
const makeTestRundown = (): Rundown =>
|
||||
({
|
||||
|
||||
Reference in New Issue
Block a user