Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { TimelineObjRundown, TimelineObjType } from '@sofie-automation/corelib/dist/dataModel/Timeline'
import { deNowifyInfinites } from '../multi-gateway'
import { TSR } from '@sofie-automation/blueprints-integration'
import { literal } from '@sofie-automation/corelib/dist/lib'

describe('Multi-gateway', () => {
describe('deNowifyInfinites', () => {
test('preserves other enable properties when de-nowifying', () => {
const targetNowTime = 1000
const obj1 = literal<TimelineObjRundown>({
id: 'obj1',
enable: {
start: 'now',
duration: 500,
},
layer: 'layer1',
content: {
deviceType: TSR.DeviceType.ABSTRACT,
},
objectType: TimelineObjType.RUNDOWN,
priority: 0,
})

const timelineObjsMap = {
[obj1.id]: obj1,
}

deNowifyInfinites(targetNowTime, [obj1], timelineObjsMap)

expect(obj1.enable).toEqual({
start: targetNowTime,
duration: 500,
})
})

test('preserves other enable properties when de-nowifying with parent group', () => {
const targetNowTime = 1500
const parentObj = literal<TimelineObjRundown>({
id: 'parent',
enable: {
start: 500,
},
layer: 'parentLayer',
content: {
deviceType: TSR.DeviceType.ABSTRACT,
},
objectType: TimelineObjType.RUNDOWN,
priority: 0,
})

const obj1 = literal<TimelineObjRundown>({
id: 'obj1',
inGroup: 'parent',
enable: {
start: 'now',
duration: 200,
},
layer: 'layer1',
content: {
deviceType: TSR.DeviceType.ABSTRACT,
},
objectType: TimelineObjType.RUNDOWN,
priority: 0,
})

const timelineObjsMap = {
[parentObj.id]: parentObj,
[obj1.id]: obj1,
}

deNowifyInfinites(targetNowTime, [obj1], timelineObjsMap)

expect(obj1.enable).toEqual({
start: targetNowTime - 500, // 1500 - 500 = 1000
duration: 200,
})
})

test('does nothing if start is not "now"', () => {
const targetNowTime = 1000
const obj1 = literal<TimelineObjRundown>({
id: 'obj1',
enable: {
start: 500,
duration: 500,
},
layer: 'layer1',
content: {
deviceType: TSR.DeviceType.ABSTRACT,
},
objectType: TimelineObjType.RUNDOWN,
priority: 0,
})

const timelineObjsMap = {
[obj1.id]: obj1,
}

deNowifyInfinites(targetNowTime, [obj1], timelineObjsMap)

expect(obj1.enable).toEqual({
start: 500,
duration: 500,
})
})
})
})
8 changes: 4 additions & 4 deletions packages/job-worker/src/playout/timeline/multi-gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ function updatePartInstancePlannedTimes(
* regeneration, items will already use the timestamps persited by `updatePlannedTimingsForPieceInstances` and will not
* be included in `infiniteObjs`.
*/
function deNowifyInfinites(
export function deNowifyInfinites(
targetNowTime: number,
/** A list of objects that need to be updated */
infiniteObjs: TimelineObjRundown[],
timelineObjsMap: Record<string, TimelineObjRundown>
) {
): void {
/**
* Recursively look up the absolute starttime of a timeline object
* taking into account its parent's times.
Expand Down Expand Up @@ -187,7 +187,7 @@ function deNowifyInfinites(
if (Array.isArray(obj.enable) || obj.enable.start !== 'now') continue

if (!obj.inGroup) {
obj.enable = { start: targetNowTime }
obj.enable = { ...obj.enable, start: targetNowTime }
continue
}

Expand All @@ -205,7 +205,7 @@ function deNowifyInfinites(
continue
}

obj.enable = { start: targetNowTime - parentStartTime }
obj.enable = { ...obj.enable, start: targetNowTime - parentStartTime }
logger.silly(
`deNowifyInfinites: Setting "${obj.id}" enable.start = ${obj.enable.start}, ${targetNowTime} ${parentStartTime} parentObject: "${parentObject.id}"`
)
Expand Down
Loading