@@ -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'
@@ -177,7 +178,9 @@ describe('Test blueprint api context', () => {
177178 return runJobWithPlayoutModel ( context , { playlistId } , null , fcn as any )
178179 }
179180
180- async function setupMyDefaultRundown ( ) : Promise < {
181+ async function setupMyDefaultRundown (
182+ insertExtraContents ?: ( jobContext : MockJobContext , rundownId : RundownId ) => Promise < void >
183+ ) : Promise < {
181184 jobContext : MockJobContext
182185 playlistId : RundownPlaylistId
183186 rundownId : RundownId
@@ -201,6 +204,8 @@ describe('Test blueprint api context', () => {
201204
202205 await setupDefaultRundown ( context , showStyleCompound , playlistId , rundownId )
203206
207+ if ( insertExtraContents ) await insertExtraContents ( context , rundownId )
208+
204209 const allPartInstances = await generateSparsePieceInstances ( context , activationId , rundownId )
205210 expect ( allPartInstances ) . toHaveLength ( 5 )
206211
@@ -1190,16 +1195,84 @@ describe('Test blueprint api context', () => {
11901195 expect ( newPartInstance . partInstance . part . _rank ) . toEqual ( 0.5 )
11911196 expect ( newPartInstance . partInstance . orphaned ) . toEqual ( 'adlib-part' )
11921197
1193- const newNextPartInstances = await service . getPieceInstances ( 'next' )
1194- expect ( newNextPartInstances ) . toHaveLength ( 1 )
1195- expect ( newNextPartInstances [ 0 ] . partInstanceId ) . toEqual (
1198+ const newNextPieceInstances = await service . getPieceInstances ( 'next' )
1199+ expect ( newNextPieceInstances ) . toHaveLength ( 1 )
1200+ expect ( newNextPieceInstances [ 0 ] . partInstanceId ) . toEqual (
11961201 unprotectString ( newPartInstance . partInstance . _id )
11971202 )
11981203
11991204 expect ( service . nextPartState ) . toEqual ( ActionPartChange . SAFE_CHANGE )
12001205 expect ( service . currentPartState ) . toEqual ( ActionPartChange . NONE )
12011206 } )
12021207 } )
1208+
1209+ test ( 'queued part does not hijack infinites from following parts' , async ( ) => {
1210+ // makes sure that infinites which would normally start in the part AFTER the part that is being queued,
1211+ // are not starting in the queued part itself
1212+
1213+ const { jobContext, playlistId, rundownId } = await setupMyDefaultRundown (
1214+ async ( context , rundownId ) => {
1215+ const secondPart = await context . mockCollections . Parts . findOne ( { externalId : 'MOCK_PART_0_1' } )
1216+ if ( ! secondPart ) throw Error ( 'could not find mock part' )
1217+ const piece001 : Piece = {
1218+ _id : protectString ( rundownId + '_piece012' ) ,
1219+ externalId : 'MOCK_PIECE_012' ,
1220+ startRundownId : rundownId ,
1221+ startSegmentId : secondPart . segmentId ,
1222+ startPartId : secondPart . _id ,
1223+ name : 'Piece 012' ,
1224+ enable : {
1225+ start : 0 ,
1226+ } ,
1227+ sourceLayerId : '' ,
1228+ outputLayerId : '' ,
1229+ pieceType : IBlueprintPieceType . Normal ,
1230+ lifespan : PieceLifespan . OutOnSegmentEnd ,
1231+ invalid : false ,
1232+ content : { } ,
1233+ timelineObjectsString : EmptyPieceTimelineObjectsBlob ,
1234+ }
1235+ await context . mockCollections . Pieces . insertOne ( piece001 )
1236+ }
1237+ )
1238+
1239+ const partInstance = ( await jobContext . mockCollections . PartInstances . findOne ( {
1240+ rundownId,
1241+ } ) ) as DBPartInstance
1242+ expect ( partInstance ) . toBeTruthy ( )
1243+ await setPartInstances ( jobContext , playlistId , partInstance , undefined )
1244+
1245+ await wrapWithPlayoutModel ( jobContext , playlistId , async ( playoutModel ) => {
1246+ const { service } = await getTestee ( jobContext , playoutModel )
1247+
1248+ const newPiece : IBlueprintPiece = {
1249+ name : 'test piece' ,
1250+ sourceLayerId : 'sl1' ,
1251+ outputLayerId : 'o1' ,
1252+ externalId : '-' ,
1253+ enable : { start : 0 } ,
1254+ lifespan : PieceLifespan . OutOnRundownEnd ,
1255+ content : {
1256+ timelineObjects : [ ] ,
1257+ } ,
1258+ }
1259+ const newPart : IBlueprintPart = {
1260+ externalId : 'nope' ,
1261+ title : 'something' ,
1262+ }
1263+
1264+ // Create it with most of the real flow
1265+ postProcessPiecesMock . mockImplementationOnce ( postProcessPiecesOrig )
1266+ insertQueuedPartWithPiecesMock . mockImplementationOnce ( insertQueuedPartWithPiecesOrig )
1267+ expect ( ( await service . queuePart ( newPart , [ newPiece ] ) ) . _id ) . toEqual (
1268+ playoutModel . playlist . nextPartInfo ?. partInstanceId
1269+ )
1270+
1271+ const newNextPartInstances = await service . getPieceInstances ( 'next' )
1272+ expect ( newNextPartInstances ) . toHaveLength ( 1 )
1273+ expect ( newNextPartInstances [ 0 ] . piece . name ) . toBe ( 'test piece' )
1274+ } )
1275+ } )
12031276 } )
12041277
12051278 describe ( 'insertPiece' , ( ) => {
0 commit comments