Skip to content

Commit bb5fa8e

Browse files
committed
chore: update tests to conform to already existing tests
1 parent c200112 commit bb5fa8e

File tree

3 files changed

+54
-57
lines changed

3 files changed

+54
-57
lines changed

packages/job-worker/src/playout/lookahead/__tests__/lookaheadOffset/constants.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,22 +318,19 @@ export const baseContext = {
318318
device: 'casparcg',
319319
layer: 10,
320320
lookahead: LookaheadMode.PRELOAD,
321-
lookaheadDepth: 1,
322-
lookaheadMaxSearchDistance: 10,
321+
lookaheadDepth: 2,
323322
},
324323
layer2: {
325324
device: 'casparcg',
326325
layer: 10,
327326
lookahead: LookaheadMode.PRELOAD,
328-
lookaheadDepth: 1,
329-
lookaheadMaxSearchDistance: 10,
327+
lookaheadDepth: 2,
330328
},
331329
layer3: {
332330
device: 'casparcg',
333331
layer: 10,
334332
lookahead: LookaheadMode.PRELOAD,
335-
lookaheadDepth: 1,
336-
lookaheadMaxSearchDistance: 10,
333+
lookaheadDepth: 2,
337334
},
338335
},
339336
},

packages/job-worker/src/playout/lookahead/__tests__/lookaheadOffset/lookaheadOffset.test.ts

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -58,78 +58,72 @@ describe('lookahead offset integration', () => {
5858

5959
expect(res).toEqual([])
6060
})
61-
test('returns one lookahead object for a single future part', async () => {
61+
test('respects lookaheadMaxSearchDistance', async () => {
6262
getOrderedPartsAfterPlayheadMock.mockReturnValue([
63-
{
64-
_id: protectString('p1'),
65-
classesForNext: [],
66-
} as any,
63+
{ _id: protectString('p1'), classesForNext: [] } as any,
64+
{ _id: protectString('p2'), classesForNext: [] } as any,
65+
{ _id: protectString('p3'), classesForNext: [] } as any,
66+
{ _id: protectString('p4'), classesForNext: [] } as any,
6767
])
6868

69-
const findFetchMock = jest.fn().mockResolvedValue([makePiece({ partId: 'p1', layer: 'layer1' })])
69+
const findFetchMock = jest
70+
.fn()
71+
.mockResolvedValue([
72+
makePiece({ partId: 'p1', layer: 'layer1' }),
73+
makePiece({ partId: 'p2', layer: 'layer1' }),
74+
makePiece({ partId: 'p3', layer: 'layer1' }),
75+
makePiece({ partId: 'p4', layer: 'layer1' }),
76+
])
7077

7178
context = {
7279
...context,
80+
studio: {
81+
...context.studio,
82+
mappings: {
83+
...context.studio.mappings,
84+
layer1: {
85+
...context.studio.mappings['layer1'],
86+
lookaheadMaxSearchDistance: 3,
87+
},
88+
},
89+
},
7390
directCollections: {
7491
...context.directCollections,
7592
Pieces: {
7693
...context.directCollections.Pieces,
7794
findFetch: findFetchMock,
7895
},
7996
},
80-
} as unknown as JobContext
97+
} as JobContext
8198

8299
const res = await getLookeaheadObjects(context, playoutModel, {
83100
current: undefined,
84101
next: undefined,
85102
previous: undefined,
86103
} as SelectedPartInstancesTimelineInfo)
87104

88-
expect(res).toHaveLength(1)
89-
90-
const obj = res[0]
91-
expect(obj.layer).toBe('layer1_lookahead')
92-
expect(obj.objectType).toBe('rundown')
93-
expect(obj.pieceInstanceId).toContain('p1')
94-
expect(obj.partInstanceId).toContain('p1')
95-
expect(obj.content).toMatchObject({
105+
expect(res).toHaveLength(2)
106+
const obj0 = res[0]
107+
const obj1 = res[1]
108+
109+
expect(obj0.layer).toBe('layer1_lookahead')
110+
expect(obj0.objectType).toBe('rundown')
111+
expect(obj0.pieceInstanceId).toContain('p1')
112+
expect(obj0.partInstanceId).toContain('p1')
113+
expect(obj0.content).toMatchObject({
114+
deviceType: TSR.DeviceType.CASPARCG,
115+
type: TSR.TimelineContentTypeCasparCg.MEDIA,
116+
file: 'AMB',
117+
})
118+
expect(obj1.layer).toBe('layer1_lookahead')
119+
expect(obj1.objectType).toBe('rundown')
120+
expect(obj1.pieceInstanceId).toContain('p2')
121+
expect(obj1.partInstanceId).toContain('p2')
122+
expect(obj1.content).toMatchObject({
96123
deviceType: TSR.DeviceType.CASPARCG,
97124
type: TSR.TimelineContentTypeCasparCg.MEDIA,
98125
file: 'AMB',
99126
})
100-
})
101-
test('respects lookaheadMaxSearchDistance', async () => {
102-
findLargestLookaheadDistanceMock.mockReturnValue(10)
103-
getOrderedPartsAfterPlayheadMock.mockReturnValue([
104-
{ _id: protectString('p1'), classesForNext: [] } as any,
105-
{ _id: protectString('p2'), classesForNext: [] } as any,
106-
])
107-
108-
context = {
109-
...context,
110-
studio: {
111-
...context.studio,
112-
mappings: {
113-
...context.studio.mappings,
114-
layer1: {
115-
...context.studio.mappings['layer1'],
116-
lookaheadMaxSearchDistance: 1,
117-
},
118-
},
119-
},
120-
} as JobContext
121-
122-
context.directCollections.Pieces.findFetch = jest
123-
.fn()
124-
.mockResolvedValue([
125-
makePiece({ partId: 'p1', layer: 'layer1' }),
126-
makePiece({ partId: 'p2', layer: 'layer1' }),
127-
])
128-
129-
const res = await getLookeaheadObjects(context, playoutModel, {} as SelectedPartInstancesTimelineInfo)
130-
131-
expect(res).toHaveLength(1)
132-
expect(res[0].partInstanceId).toContain('p1')
133127
})
134128
test('applies nextTimeOffset to lookahead objects in future part', async () => {
135129
playoutModel = {
@@ -140,11 +134,17 @@ describe('lookahead offset integration', () => {
140134
},
141135
} as PlayoutModel
142136
findLargestLookaheadDistanceMock.mockReturnValue(1)
143-
getOrderedPartsAfterPlayheadMock.mockReturnValue([{ _id: protectString('p1'), classesForNext: [] } as any])
137+
getOrderedPartsAfterPlayheadMock.mockReturnValue([
138+
{ _id: protectString('p1'), classesForNext: [] } as any,
139+
{ _id: protectString('p2'), classesForNext: [] } as any,
140+
])
144141

145142
context.directCollections.Pieces.findFetch = jest
146143
.fn()
147-
.mockResolvedValue([makePiece({ partId: 'p1', layer: 'layer1', start: 0 })])
144+
.mockResolvedValue([
145+
makePiece({ partId: 'p1', layer: 'layer1' }),
146+
makePiece({ partId: 'p2', layer: 'layer1' }),
147+
])
148148

149149
const res = await getLookeaheadObjects(context, playoutModel, {} as SelectedPartInstancesTimelineInfo)
150150

packages/job-worker/src/playout/lookahead/findForLayer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export function findLookaheadForLayer(
7474
res.future.push(...nextObjs)
7575
}
7676
previousPart = nextPartInfo.part
77-
} else lookaheadMaxSearchDistance += 1 // if there is no next part, we should look at the future parts. It's easiest to just expand the search by one.
77+
}
7878

7979
if (lookaheadMaxSearchDistance > 1 && lookaheadTargetFutureObjects > 0) {
8080
for (const partInfo of orderedPartInfos.slice(0, lookaheadMaxSearchDistance - 1)) {

0 commit comments

Comments
 (0)