forked from nrkno/sofie-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request nrkno#1259 from bbc/fix/updating-piece-instances
chore: unit tests for updating infinite piece instances
- Loading branch information
Showing
1 changed file
with
110 additions
and
0 deletions.
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
...ob-worker/src/playout/model/implementation/__tests__/PlayoutPartInstanceModelImpl.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { protectString } from '@sofie-automation/corelib/dist/protectedString' | ||
import { DBPartInstance } from '@sofie-automation/corelib/dist/dataModel/PartInstance' | ||
import { getRandomId, literal } from '@sofie-automation/corelib/dist/lib' | ||
import { PlayoutPartInstanceModelImpl } from '../PlayoutPartInstanceModelImpl' | ||
import { PieceInstance, PieceInstancePiece } from '@sofie-automation/corelib/dist/dataModel/PieceInstance' | ||
import { IBlueprintPieceType, PieceLifespan } from '@sofie-automation/blueprints-integration' | ||
|
||
describe('PlayoutPartInstanceModelImpl', () => { | ||
function createBasicDBPartInstance(): DBPartInstance { | ||
return { | ||
_id: getRandomId(), | ||
rundownId: protectString(''), | ||
segmentId: protectString(''), | ||
playlistActivationId: protectString(''), | ||
segmentPlayoutId: protectString(''), | ||
rehearsal: false, | ||
|
||
takeCount: 0, | ||
|
||
part: { | ||
_id: getRandomId(), | ||
_rank: 0, | ||
rundownId: protectString(''), | ||
segmentId: protectString(''), | ||
externalId: '', | ||
title: '', | ||
|
||
expectedDurationWithTransition: undefined, | ||
}, | ||
} | ||
} | ||
|
||
function createPieceInstanceAsInfinite(id: string, fromPreviousPlayhead: boolean): PieceInstance { | ||
return literal<PieceInstance>({ | ||
_id: protectString(id), | ||
rundownId: protectString(''), | ||
partInstanceId: protectString(''), | ||
playlistActivationId: protectString('active'), | ||
piece: literal<PieceInstancePiece>({ | ||
_id: protectString(`${id}_p`), | ||
externalId: '', | ||
startPartId: protectString(''), | ||
enable: { start: 0 }, | ||
name: '', | ||
lifespan: PieceLifespan.OutOnRundownChange, | ||
sourceLayerId: '', | ||
outputLayerId: '', | ||
invalid: false, | ||
content: {}, | ||
timelineObjectsString: protectString(''), | ||
pieceType: IBlueprintPieceType.Normal, | ||
}), | ||
infinite: { | ||
infiniteInstanceId: protectString(`${id}_inf`), | ||
infiniteInstanceIndex: 0, | ||
infinitePieceId: protectString(`${id}_p`), | ||
fromPreviousPart: false, | ||
fromPreviousPlayhead, | ||
}, | ||
}) | ||
} | ||
|
||
describe('replaceInfinitesFromPreviousPlayhead', () => { | ||
it('works for an empty part', async () => { | ||
const partInstance = createBasicDBPartInstance() | ||
const model = new PlayoutPartInstanceModelImpl(partInstance, [], false) | ||
|
||
expect(() => model.replaceInfinitesFromPreviousPlayhead([])).not.toThrow() | ||
expect(model.pieceInstances).toEqual([]) | ||
}) | ||
|
||
it('keeps pieceInstance with fromPreviousPlayhead=false', async () => { | ||
const partInstance = createBasicDBPartInstance() | ||
const model = new PlayoutPartInstanceModelImpl( | ||
partInstance, | ||
[createPieceInstanceAsInfinite('p1', false)], | ||
false | ||
) | ||
|
||
expect(() => model.replaceInfinitesFromPreviousPlayhead([])).not.toThrow() | ||
expect(model.pieceInstances.map((p) => p.pieceInstance._id)).toEqual(['p1']) | ||
}) | ||
|
||
it('deleted pieceInstance with fromPreviousPlayhead=true if no replacement provided', async () => { | ||
const partInstance = createBasicDBPartInstance() | ||
const model = new PlayoutPartInstanceModelImpl( | ||
partInstance, | ||
[createPieceInstanceAsInfinite('p1', true)], | ||
false | ||
) | ||
|
||
expect(() => model.replaceInfinitesFromPreviousPlayhead([])).not.toThrow() | ||
expect(model.pieceInstances.map((p) => p.pieceInstance._id)).toEqual([]) | ||
}) | ||
|
||
it('replaces pieceInstance with fromPreviousPlayhead=true if replacement provided', async () => { | ||
const partInstance = createBasicDBPartInstance() | ||
const model = new PlayoutPartInstanceModelImpl( | ||
partInstance, | ||
[createPieceInstanceAsInfinite('p1', true)], | ||
false | ||
) | ||
|
||
expect(() => | ||
model.replaceInfinitesFromPreviousPlayhead([createPieceInstanceAsInfinite('p1', true)]) | ||
).not.toThrow() | ||
expect(model.pieceInstances.map((p) => p.pieceInstance._id)).toEqual(['p1']) | ||
}) | ||
}) | ||
}) |