Skip to content

Commit b9628ad

Browse files
committed
chore(EAV-640): add test cases for calculateSegmentTiming
1 parent 0b69fc2 commit b9628ad

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { calculateSegmentTiming } from '../segmentTiming.js'
2+
import { DBPart } from '@sofie-automation/corelib/dist/dataModel/Part'
3+
import { DBPartInstance } from '@sofie-automation/corelib/dist/dataModel/PartInstance'
4+
import { protectString } from '@sofie-automation/corelib/dist/protectedString'
5+
6+
function makeTestPart(id: string, expectedDuration: number): Partial<DBPart> {
7+
return {
8+
_id: protectString(`part_${id}`),
9+
segmentId: protectString('segment_1'),
10+
rundownId: protectString('rundown_1'),
11+
untimed: false,
12+
expectedDurationWithTransition: expectedDuration,
13+
}
14+
}
15+
16+
function makeTestPartInstance(id: string, partId: string, expectedDuration: number): Partial<DBPartInstance> {
17+
return {
18+
_id: protectString(`partInstance_${id}`),
19+
part: makeTestPart(partId, expectedDuration) as DBPart,
20+
rundownId: protectString('rundown_1'),
21+
segmentId: protectString('segment_1'),
22+
playlistActivationId: protectString('activation_1'),
23+
}
24+
}
25+
26+
describe('segmentTiming - calculateSegmentTiming', () => {
27+
it('should use partInstance duration when available instead of original part duration', () => {
28+
const parts = [makeTestPart('1', 5000), makeTestPart('2', 3000)]
29+
30+
// Create partInstances with modified durations
31+
const partInstances = [makeTestPartInstance('1', '1', 6000), makeTestPartInstance('2', '2', 4000)]
32+
33+
const result = calculateSegmentTiming(undefined, partInstances as DBPartInstance[], parts as DBPart[])
34+
35+
// Should use the modified durations from partInstances (6000 + 4000), not the original (5000 + 3000)
36+
expect(result.expectedDurationMs).toBe(10000)
37+
})
38+
39+
it('should fall back to original part duration when no matching partInstance', () => {
40+
const parts = [makeTestPart('1', 5000), makeTestPart('2', 3000), makeTestPart('3', 2000)]
41+
42+
// Only provide instances for parts 1 and 2, part 3 has no instance
43+
const partInstances = [
44+
makeTestPartInstance('1', '1', 6000), // modified from 5000
45+
makeTestPartInstance('2', '2', 3000), // unchanged
46+
]
47+
48+
const result = calculateSegmentTiming(undefined, partInstances as DBPartInstance[], parts as DBPart[])
49+
50+
// Should use: 6000 (instance) + 3000 (instance) + 2000 (original, no instance)
51+
expect(result.expectedDurationMs).toBe(11000)
52+
})
53+
})

0 commit comments

Comments
 (0)