Skip to content

Commit c4e1c88

Browse files
authored
Merge pull request Sofie-Automation#1259 from bbc/fix/updating-piece-instances
chore: unit tests for updating infinite piece instances
2 parents 6f5bfa6 + a4250ef commit c4e1c88

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import { protectString } from '@sofie-automation/corelib/dist/protectedString'
2+
import { DBPartInstance } from '@sofie-automation/corelib/dist/dataModel/PartInstance'
3+
import { getRandomId, literal } from '@sofie-automation/corelib/dist/lib'
4+
import { PlayoutPartInstanceModelImpl } from '../PlayoutPartInstanceModelImpl'
5+
import { PieceInstance, PieceInstancePiece } from '@sofie-automation/corelib/dist/dataModel/PieceInstance'
6+
import { IBlueprintPieceType, PieceLifespan } from '@sofie-automation/blueprints-integration'
7+
8+
describe('PlayoutPartInstanceModelImpl', () => {
9+
function createBasicDBPartInstance(): DBPartInstance {
10+
return {
11+
_id: getRandomId(),
12+
rundownId: protectString(''),
13+
segmentId: protectString(''),
14+
playlistActivationId: protectString(''),
15+
segmentPlayoutId: protectString(''),
16+
rehearsal: false,
17+
18+
takeCount: 0,
19+
20+
part: {
21+
_id: getRandomId(),
22+
_rank: 0,
23+
rundownId: protectString(''),
24+
segmentId: protectString(''),
25+
externalId: '',
26+
title: '',
27+
28+
expectedDurationWithTransition: undefined,
29+
},
30+
}
31+
}
32+
33+
function createPieceInstanceAsInfinite(id: string, fromPreviousPlayhead: boolean): PieceInstance {
34+
return literal<PieceInstance>({
35+
_id: protectString(id),
36+
rundownId: protectString(''),
37+
partInstanceId: protectString(''),
38+
playlistActivationId: protectString('active'),
39+
piece: literal<PieceInstancePiece>({
40+
_id: protectString(`${id}_p`),
41+
externalId: '',
42+
startPartId: protectString(''),
43+
enable: { start: 0 },
44+
name: '',
45+
lifespan: PieceLifespan.OutOnRundownChange,
46+
sourceLayerId: '',
47+
outputLayerId: '',
48+
invalid: false,
49+
content: {},
50+
timelineObjectsString: protectString(''),
51+
pieceType: IBlueprintPieceType.Normal,
52+
}),
53+
infinite: {
54+
infiniteInstanceId: protectString(`${id}_inf`),
55+
infiniteInstanceIndex: 0,
56+
infinitePieceId: protectString(`${id}_p`),
57+
fromPreviousPart: false,
58+
fromPreviousPlayhead,
59+
},
60+
})
61+
}
62+
63+
describe('replaceInfinitesFromPreviousPlayhead', () => {
64+
it('works for an empty part', async () => {
65+
const partInstance = createBasicDBPartInstance()
66+
const model = new PlayoutPartInstanceModelImpl(partInstance, [], false)
67+
68+
expect(() => model.replaceInfinitesFromPreviousPlayhead([])).not.toThrow()
69+
expect(model.pieceInstances).toEqual([])
70+
})
71+
72+
it('keeps pieceInstance with fromPreviousPlayhead=false', async () => {
73+
const partInstance = createBasicDBPartInstance()
74+
const model = new PlayoutPartInstanceModelImpl(
75+
partInstance,
76+
[createPieceInstanceAsInfinite('p1', false)],
77+
false
78+
)
79+
80+
expect(() => model.replaceInfinitesFromPreviousPlayhead([])).not.toThrow()
81+
expect(model.pieceInstances.map((p) => p.pieceInstance._id)).toEqual(['p1'])
82+
})
83+
84+
it('deleted pieceInstance with fromPreviousPlayhead=true if no replacement provided', async () => {
85+
const partInstance = createBasicDBPartInstance()
86+
const model = new PlayoutPartInstanceModelImpl(
87+
partInstance,
88+
[createPieceInstanceAsInfinite('p1', true)],
89+
false
90+
)
91+
92+
expect(() => model.replaceInfinitesFromPreviousPlayhead([])).not.toThrow()
93+
expect(model.pieceInstances.map((p) => p.pieceInstance._id)).toEqual([])
94+
})
95+
96+
it('replaces pieceInstance with fromPreviousPlayhead=true if replacement provided', async () => {
97+
const partInstance = createBasicDBPartInstance()
98+
const model = new PlayoutPartInstanceModelImpl(
99+
partInstance,
100+
[createPieceInstanceAsInfinite('p1', true)],
101+
false
102+
)
103+
104+
expect(() =>
105+
model.replaceInfinitesFromPreviousPlayhead([createPieceInstanceAsInfinite('p1', true)])
106+
).not.toThrow()
107+
expect(model.pieceInstances.map((p) => p.pieceInstance._id)).toEqual(['p1'])
108+
})
109+
})
110+
})

0 commit comments

Comments
 (0)