Skip to content

Commit 1917daa

Browse files
committed
chore: add tests for PlayoutSegmentModelImpl
1 parent 51c4ca1 commit 1917daa

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import { DBSegment, SegmentOrphanedReason } from '@sofie-automation/corelib/dist/dataModel/Segment'
2+
import { PlayoutSegmentModelImpl } from '../PlayoutSegmentModelImpl'
3+
import { protectString } from '@sofie-automation/corelib/dist/protectedString'
4+
import { DBPart } from '@sofie-automation/corelib/dist/dataModel/Part'
5+
6+
describe('PlayoutSegmentModelImpl', () => {
7+
function createBasicDBSegment(): DBSegment {
8+
return {
9+
_id: protectString('abc'),
10+
rundownId: protectString('rd0'),
11+
externalId: 'ext1',
12+
externalModified: 100000,
13+
_rank: 1,
14+
name: 'test segment',
15+
}
16+
}
17+
18+
it('segment getter', async () => {
19+
const segment = createBasicDBSegment()
20+
const model = new PlayoutSegmentModelImpl(segment, [])
21+
22+
expect(model.segment).toBe(segment)
23+
})
24+
25+
describe('getPartIds', () => {
26+
it('no parts', async () => {
27+
const segment = createBasicDBSegment()
28+
const model = new PlayoutSegmentModelImpl(segment, [])
29+
30+
expect(model.getPartIds()).toEqual([])
31+
})
32+
it('with parts', async () => {
33+
const fakePart: DBPart = { _id: protectString('part0'), _rank: 1 } as any
34+
const fakePart2: DBPart = { _id: protectString('part1'), _rank: 2 } as any
35+
const segment = createBasicDBSegment()
36+
const model = new PlayoutSegmentModelImpl(segment, [fakePart, fakePart2])
37+
38+
expect(model.getPartIds()).toEqual([fakePart._id, fakePart2._id])
39+
})
40+
it('with parts ensuring order', async () => {
41+
const fakePart: DBPart = { _id: protectString('part0'), _rank: 5 } as any
42+
const fakePart2: DBPart = { _id: protectString('part1'), _rank: 2 } as any
43+
const segment = createBasicDBSegment()
44+
const model = new PlayoutSegmentModelImpl(segment, [fakePart, fakePart2])
45+
46+
expect(model.getPartIds()).toEqual([fakePart2._id, fakePart._id])
47+
})
48+
})
49+
50+
describe('getPart', () => {
51+
it('no parts', async () => {
52+
const segment = createBasicDBSegment()
53+
const model = new PlayoutSegmentModelImpl(segment, [])
54+
55+
expect(model.getPart(protectString('missing'))).toBeUndefined()
56+
})
57+
it('with other parts', async () => {
58+
const fakePart: DBPart = { _id: protectString('part0'), _rank: 1 } as any
59+
const fakePart2: DBPart = { _id: protectString('part1'), _rank: 2 } as any
60+
const segment = createBasicDBSegment()
61+
const model = new PlayoutSegmentModelImpl(segment, [fakePart, fakePart2])
62+
63+
expect(model.getPart(protectString('missing'))).toBeUndefined()
64+
})
65+
it('with found part', async () => {
66+
const fakePart: DBPart = { _id: protectString('part0'), _rank: 1 } as any
67+
const fakePart2: DBPart = { _id: protectString('part1'), _rank: 2 } as any
68+
const segment = createBasicDBSegment()
69+
const model = new PlayoutSegmentModelImpl(segment, [fakePart, fakePart2])
70+
71+
expect(model.getPart(fakePart._id)).toBe(fakePart)
72+
})
73+
})
74+
75+
describe('setScratchpadRank', () => {
76+
it('not scratchpad segment', async () => {
77+
const segment = createBasicDBSegment()
78+
const originalRank = segment._rank
79+
const model = new PlayoutSegmentModelImpl(segment, [])
80+
81+
expect(() => model.setScratchpadRank(originalRank + 1)).toThrow(
82+
/setScratchpadRank can only be used on a SCRATCHPAD segment/
83+
)
84+
expect(model.segment._rank).toBe(originalRank)
85+
})
86+
87+
it('is scratchpad segment', async () => {
88+
const segment = createBasicDBSegment()
89+
segment.orphaned = SegmentOrphanedReason.SCRATCHPAD
90+
91+
const originalRank = segment._rank
92+
const model = new PlayoutSegmentModelImpl(segment, [])
93+
94+
model.setScratchpadRank(originalRank + 1)
95+
expect(model.segment._rank).toBe(originalRank + 1)
96+
})
97+
98+
it('not orphaned segment', async () => {
99+
const segment = createBasicDBSegment()
100+
segment.orphaned = SegmentOrphanedReason.DELETED
101+
102+
const originalRank = segment._rank
103+
const model = new PlayoutSegmentModelImpl(segment, [])
104+
105+
expect(() => model.setScratchpadRank(originalRank + 1)).toThrow(
106+
/setScratchpadRank can only be used on a SCRATCHPAD segment/
107+
)
108+
expect(model.segment._rank).toBe(originalRank)
109+
})
110+
})
111+
})

0 commit comments

Comments
 (0)