11/* eslint-disable @typescript-eslint/unbound-method */
22import { IBlueprintMutatablePart , IBlueprintPiece } from '@sofie-automation/blueprints-integration'
3- import { PlayoutModel } from '../../playout/model/PlayoutModel.js'
43import { WatchedPackagesHelper } from '../context/watchedPackages.js'
54import { JobContext , ProcessedShowStyleCompound } from '../../jobs/index.js'
65import { mock } from 'jest-mock-extended'
76import { PartAndPieceInstanceActionService } from '../context/services/PartAndPieceInstanceActionService.js'
87import { OnTakeContext } from '../context/index.js'
8+ import { DBPart } from '@sofie-automation/corelib/dist/dataModel/Part'
9+ import { PartId , RundownId , SegmentId } from '@sofie-automation/corelib/dist/dataModel/Ids'
10+ import { protectString } from '@sofie-automation/corelib/dist/protectedString'
11+ import { PlayoutModelImpl } from '../../playout/model/implementation/PlayoutModelImpl.js'
912
1013describe ( 'Test blueprint api context' , ( ) => {
1114 async function getTestee ( ) {
15+ const mockPlayoutModel = mock < PlayoutModelImpl > ( )
1216 const mockActionService = mock < PartAndPieceInstanceActionService > ( )
1317 const context = new OnTakeContext (
1418 {
1519 name : 'fakeContext' ,
1620 identifier : 'action' ,
1721 } ,
1822 mock < JobContext > ( ) ,
19- mock < PlayoutModel > ( ) ,
23+ mockPlayoutModel ,
2024 mock < ProcessedShowStyleCompound > ( ) ,
2125 mock < WatchedPackagesHelper > ( ) ,
2226 mockActionService
@@ -25,6 +29,7 @@ describe('Test blueprint api context', () => {
2529 return {
2630 context,
2731 mockActionService,
32+ mockPlayoutModel,
2833 }
2934 }
3035
@@ -99,6 +104,42 @@ describe('Test blueprint api context', () => {
99104 expect ( mockActionService . getPartForPreviousPiece ) . toHaveBeenCalledWith ( { _id : 'pieceId' } )
100105 } )
101106
107+ test ( 'getUpcomingParts' , async ( ) => {
108+ const { context, mockPlayoutModel } = await getTestee ( )
109+
110+ mockPlayoutModel . getAllOrderedParts . mockReturnValue (
111+ mock ( [
112+ {
113+ _id : protectString < PartId > ( 'part1' ) ,
114+ title : 'Part 1' ,
115+ invalid : false ,
116+ floated : false ,
117+ _rank : 1 ,
118+ rundownId : protectString < RundownId > ( 'rundown1' ) ,
119+ externalId : 'ext1' ,
120+ segmentId : protectString < SegmentId > ( 'seg1' ) ,
121+ expectedDurationWithTransition : 1000 ,
122+ userEditOperations : [ ] ,
123+ } as DBPart ,
124+ {
125+ _id : protectString < PartId > ( 'part2' ) ,
126+ title : 'Part 2' ,
127+ invalid : false ,
128+ floated : false ,
129+ _rank : 1 ,
130+ rundownId : protectString < RundownId > ( 'rundown1' ) ,
131+ externalId : 'ext1' ,
132+ segmentId : protectString < SegmentId > ( 'seg1' ) ,
133+ expectedDurationWithTransition : 1000 ,
134+ userEditOperations : [ ] ,
135+ } as unknown as DBPart ,
136+ ] )
137+ )
138+
139+ const parts = await context . getUpcomingParts ( )
140+ expect ( parts . map ( ( i ) => i . title ) ) . toEqual ( [ 'Part 1' , 'Part 2' ] )
141+ } )
142+
102143 test ( 'insertPiece' , async ( ) => {
103144 const { context, mockActionService } = await getTestee ( )
104145
0 commit comments