@@ -26,6 +26,7 @@ import { DBPartInstance } from '@sofie-automation/corelib/dist/dataModel/PartIns
2626import { getCurrentTime } from '../../../../lib'
2727import {
2828 EmptyPieceTimelineObjectsBlob ,
29+ Piece ,
2930 serializePieceTimelineObjectsBlob ,
3031} from '@sofie-automation/corelib/dist/dataModel/Piece'
3132import { PlayoutPartInstanceModel } from '../../../../playout/model/PlayoutPartInstanceModel'
@@ -176,7 +177,9 @@ describe('Test blueprint api context', () => {
176177 return runJobWithPlayoutModel ( context , { playlistId } , null , fcn as any )
177178 }
178179
179- async function setupMyDefaultRundown ( ) : Promise < {
180+ async function setupMyDefaultRundown (
181+ insertExtraContents ?: ( jobContext : MockJobContext , rundownId : RundownId ) => Promise < void >
182+ ) : Promise < {
180183 jobContext : MockJobContext
181184 playlistId : RundownPlaylistId
182185 rundownId : RundownId
@@ -200,6 +203,8 @@ describe('Test blueprint api context', () => {
200203
201204 await setupDefaultRundown ( context , showStyleCompound , playlistId , rundownId )
202205
206+ if ( insertExtraContents ) await insertExtraContents ( context , rundownId )
207+
203208 const allPartInstances = await generateSparsePieceInstances ( context , activationId , rundownId )
204209 expect ( allPartInstances ) . toHaveLength ( 5 )
205210
@@ -1187,16 +1192,84 @@ describe('Test blueprint api context', () => {
11871192 expect ( newPartInstance . partInstance . part . _rank ) . toEqual ( 0.5 )
11881193 expect ( newPartInstance . partInstance . orphaned ) . toEqual ( 'adlib-part' )
11891194
1190- const newNextPartInstances = await service . getPieceInstances ( 'next' )
1191- expect ( newNextPartInstances ) . toHaveLength ( 1 )
1192- expect ( newNextPartInstances [ 0 ] . partInstanceId ) . toEqual (
1195+ const newNextPieceInstances = await service . getPieceInstances ( 'next' )
1196+ expect ( newNextPieceInstances ) . toHaveLength ( 1 )
1197+ expect ( newNextPieceInstances [ 0 ] . partInstanceId ) . toEqual (
11931198 unprotectString ( newPartInstance . partInstance . _id )
11941199 )
11951200
11961201 expect ( service . nextPartState ) . toEqual ( ActionPartChange . SAFE_CHANGE )
11971202 expect ( service . currentPartState ) . toEqual ( ActionPartChange . NONE )
11981203 } )
11991204 } )
1205+
1206+ test ( 'queued part does not hijack infinites from following parts' , async ( ) => {
1207+ // makes sure that infinites which would normally start in the part AFTER the part that is being queued,
1208+ // are not starting in the queued part itself
1209+
1210+ const { jobContext, playlistId, rundownId } = await setupMyDefaultRundown (
1211+ async ( context , rundownId ) => {
1212+ const secondPart = await context . mockCollections . Parts . findOne ( { externalId : 'MOCK_PART_0_1' } )
1213+ if ( ! secondPart ) throw Error ( 'could not find mock part' )
1214+ const piece001 : Piece = {
1215+ _id : protectString ( rundownId + '_piece012' ) ,
1216+ externalId : 'MOCK_PIECE_012' ,
1217+ startRundownId : rundownId ,
1218+ startSegmentId : secondPart . segmentId ,
1219+ startPartId : secondPart . _id ,
1220+ name : 'Piece 012' ,
1221+ enable : {
1222+ start : 0 ,
1223+ } ,
1224+ sourceLayerId : '' ,
1225+ outputLayerId : '' ,
1226+ pieceType : IBlueprintPieceType . Normal ,
1227+ lifespan : PieceLifespan . OutOnSegmentEnd ,
1228+ invalid : false ,
1229+ content : { } ,
1230+ timelineObjectsString : EmptyPieceTimelineObjectsBlob ,
1231+ }
1232+ await context . mockCollections . Pieces . insertOne ( piece001 )
1233+ }
1234+ )
1235+
1236+ const partInstance = ( await jobContext . mockCollections . PartInstances . findOne ( {
1237+ rundownId,
1238+ } ) ) as DBPartInstance
1239+ expect ( partInstance ) . toBeTruthy ( )
1240+ await setPartInstances ( jobContext , playlistId , partInstance , undefined )
1241+
1242+ await wrapWithPlayoutModel ( jobContext , playlistId , async ( playoutModel ) => {
1243+ const { service } = await getTestee ( jobContext , playoutModel )
1244+
1245+ const newPiece : IBlueprintPiece = {
1246+ name : 'test piece' ,
1247+ sourceLayerId : 'sl1' ,
1248+ outputLayerId : 'o1' ,
1249+ externalId : '-' ,
1250+ enable : { start : 0 } ,
1251+ lifespan : PieceLifespan . OutOnRundownEnd ,
1252+ content : {
1253+ timelineObjects : [ ] ,
1254+ } ,
1255+ }
1256+ const newPart : IBlueprintPart = {
1257+ externalId : 'nope' ,
1258+ title : 'something' ,
1259+ }
1260+
1261+ // Create it with most of the real flow
1262+ postProcessPiecesMock . mockImplementationOnce ( postProcessPiecesOrig )
1263+ insertQueuedPartWithPiecesMock . mockImplementationOnce ( insertQueuedPartWithPiecesOrig )
1264+ expect ( ( await service . queuePart ( newPart , [ newPiece ] ) ) . _id ) . toEqual (
1265+ playoutModel . playlist . nextPartInfo ?. partInstanceId
1266+ )
1267+
1268+ const newNextPartInstances = await service . getPieceInstances ( 'next' )
1269+ expect ( newNextPartInstances ) . toHaveLength ( 1 )
1270+ expect ( newNextPartInstances [ 0 ] . piece . name ) . toBe ( 'test piece' )
1271+ } )
1272+ } )
12001273 } )
12011274
12021275 describe ( 'insertPiece' , ( ) => {
0 commit comments