|
1 | 1 | import { getRandomString } from '@sofie-automation/corelib/dist/lib' |
2 | 2 | import { PartInstanceAndPieceInstances, PartAndPieces } from '../../util.js' |
3 | 3 | import { createFakePiece } from '../utils.js' |
| 4 | +import { protectString } from '@sofie-automation/corelib/dist/protectedString' |
| 5 | +import { PieceTimelineObjectsBlob } from '@sofie-automation/corelib/dist/dataModel/Piece' |
| 6 | + |
| 7 | +const layer: string = getRandomString() |
| 8 | + |
| 9 | +const generateFakeObectsString = ( |
| 10 | + pieceId: string, |
| 11 | + layer: string, |
| 12 | + beforeStart: number, |
| 13 | + afterStart: number, |
| 14 | + enableWhile: boolean = false |
| 15 | +) => |
| 16 | + protectString<PieceTimelineObjectsBlob>( |
| 17 | + JSON.stringify([ |
| 18 | + // At piece start |
| 19 | + { |
| 20 | + id: pieceId + 'tl_pieceStart' + (enableWhile ? '_while' : ''), |
| 21 | + layer: layer, |
| 22 | + enable: !enableWhile ? { start: 0 } : { while: 1 }, |
| 23 | + content: { deviceType: 0, type: 'none' }, |
| 24 | + }, |
| 25 | + //beforeOffsetObj except if it's piece starts later than the offset. |
| 26 | + { |
| 27 | + id: pieceId + 'tl_beforeOffset' + (enableWhile ? '_while' : ''), |
| 28 | + layer: layer, |
| 29 | + enable: !enableWhile ? { start: beforeStart } : { while: beforeStart }, |
| 30 | + content: { deviceType: 0, type: 'none' }, |
| 31 | + }, |
| 32 | + //afterOffsetObj except if it's piece starts later than the offset. |
| 33 | + { |
| 34 | + id: pieceId + 'tl_afterOffset' + (enableWhile ? '_while' : ''), |
| 35 | + layer: layer, |
| 36 | + enable: !enableWhile ? { start: afterStart } : { while: afterStart }, |
| 37 | + content: { deviceType: 0, type: 'none' }, |
| 38 | + }, |
| 39 | + ]) |
| 40 | + ) |
4 | 41 |
|
5 | 42 | export const findForLayerTestConstants = { |
6 | 43 | previous: { |
@@ -34,5 +71,193 @@ export const findForLayerTestConstants = { |
34 | 71 | }) |
35 | 72 | ) as PartAndPieces[], |
36 | 73 |
|
37 | | - layer: getRandomString(), |
| 74 | + layer, |
| 75 | +} |
| 76 | + |
| 77 | +const partDuration = 3000 |
| 78 | + |
| 79 | +const lookaheadOffsetLayerIds = { |
| 80 | + partStart: 'partStart_' + layer, |
| 81 | + beforeOffset: 'beforeOffset_' + layer, |
| 82 | + afterOffset: 'afterOffset_' + layer, |
| 83 | +} |
| 84 | + |
| 85 | +export const lookaheadOffsetTestConstants = { |
| 86 | + multiLayerPart: { |
| 87 | + part: { _id: 'pLookahead_ml', part: 'lookahead_ml' }, |
| 88 | + |
| 89 | + pieces: [ |
| 90 | + // piece1 — At Part Start - lookaheadOffset should equal nextTimeOffset |
| 91 | + createFakePiece('ml_piece1', { |
| 92 | + enable: { start: 0, duration: partDuration - 0 }, |
| 93 | + sourceLayerId: lookaheadOffsetLayerIds.partStart, |
| 94 | + // We generate three objects, one at the piece's start, one 700 ms after the piece's start, one 1700 ms after the piece's start. |
| 95 | + // We need to check if all offsets are calculated correctly. (1000, 300 and no offset) |
| 96 | + timelineObjectsString: generateFakeObectsString( |
| 97 | + 'ml_piece1', |
| 98 | + lookaheadOffsetLayerIds.partStart, |
| 99 | + 700, |
| 100 | + 1700 |
| 101 | + ), |
| 102 | + }), |
| 103 | + |
| 104 | + // piece2 — Before Offset — lookaheadOffset should equal nextTimeOffset - the piece's start - the timeline object's start. |
| 105 | + createFakePiece('ml_piece2', { |
| 106 | + enable: { start: 500, duration: partDuration - 500 }, |
| 107 | + sourceLayerId: lookaheadOffsetLayerIds.beforeOffset, |
| 108 | + // We generate three objects, one at the piece's start, one 200 ms after the piece's start, one 1200 ms after the piece's start. |
| 109 | + // We need to check if all offsets are calculated correctly. (500, 300 and no offset) |
| 110 | + timelineObjectsString: generateFakeObectsString( |
| 111 | + 'ml_piece2', |
| 112 | + lookaheadOffsetLayerIds.beforeOffset, |
| 113 | + 200, |
| 114 | + 1200 |
| 115 | + ), |
| 116 | + }), |
| 117 | + |
| 118 | + // piece3 — After Offset — no lookahead offset |
| 119 | + createFakePiece('ml_piece3', { |
| 120 | + enable: { start: 1500, duration: partDuration - 1500 }, |
| 121 | + sourceLayerId: lookaheadOffsetLayerIds.afterOffset, |
| 122 | + // We generate three objects, one at the piece's start, one 200 ms after the piece's start, one 400 ms after the piece's start. |
| 123 | + // We need to check if all offsets are calculated correctly. |
| 124 | + // for reference no offset should be calculated for all of it's objects. |
| 125 | + timelineObjectsString: generateFakeObectsString( |
| 126 | + 'ml_piece3', |
| 127 | + lookaheadOffsetLayerIds.afterOffset, |
| 128 | + 200, |
| 129 | + 400 |
| 130 | + ), |
| 131 | + }), |
| 132 | + ], |
| 133 | + |
| 134 | + onTimeline: true, |
| 135 | + } as any as PartAndPieces, |
| 136 | + multiLayerPartWhile: { |
| 137 | + part: { _id: 'pLookahead_ml_while', part: 'lookaheadFull_ml_while' }, |
| 138 | + |
| 139 | + pieces: [ |
| 140 | + // piece1 — At Part Start - lookaheadOffset should equal nextTimeOffset |
| 141 | + createFakePiece('ml_piece1_while', { |
| 142 | + enable: { start: 0, duration: partDuration - 0 }, |
| 143 | + sourceLayerId: lookaheadOffsetLayerIds.partStart, |
| 144 | + // We generate three objects, one at the piece's start, one 700 ms after the piece's start, one 1700 ms after the piece's start. |
| 145 | + // We need to check if all offsets are calculated correctly. (1000, 300 and no offset) |
| 146 | + timelineObjectsString: generateFakeObectsString( |
| 147 | + 'ml_piece1_while', |
| 148 | + lookaheadOffsetLayerIds.partStart, |
| 149 | + 700, |
| 150 | + 1700, |
| 151 | + true |
| 152 | + ), |
| 153 | + }), |
| 154 | + |
| 155 | + // piece2 — Before Offset — lookaheadOffset should equal nextTimeOffset - the piece's start - the timeline object's start |
| 156 | + createFakePiece('ml_piece2_while', { |
| 157 | + enable: { start: 500, duration: partDuration - 500 }, |
| 158 | + sourceLayerId: lookaheadOffsetLayerIds.beforeOffset, |
| 159 | + // We generate three objects, one at the piece's start, one 200 ms after the piece's start, one 1200 ms after the piece's start. |
| 160 | + // We need to check if all offsets are calculated correctly. (500, 300 and no offset) |
| 161 | + timelineObjectsString: generateFakeObectsString( |
| 162 | + 'ml_piece2_while', |
| 163 | + lookaheadOffsetLayerIds.beforeOffset, |
| 164 | + 200, |
| 165 | + 1200, |
| 166 | + true |
| 167 | + ), |
| 168 | + }), |
| 169 | + |
| 170 | + // piece3 — After Offset — no lookahead offset |
| 171 | + createFakePiece('ml_piece3_while', { |
| 172 | + enable: { start: 1500, duration: partDuration - 1500 }, |
| 173 | + sourceLayerId: lookaheadOffsetLayerIds.afterOffset, |
| 174 | + // We generate three objects, one at the piece's start, one 200 ms after the piece's start, one 400 ms after the piece's start. |
| 175 | + // We need to check if all offsets are calculated correctly. (no offset should be calculated) |
| 176 | + timelineObjectsString: generateFakeObectsString( |
| 177 | + 'ml_piece3_while', |
| 178 | + lookaheadOffsetLayerIds.afterOffset, |
| 179 | + 200, |
| 180 | + 400, |
| 181 | + true |
| 182 | + ), |
| 183 | + }), |
| 184 | + ], |
| 185 | + |
| 186 | + onTimeline: true, |
| 187 | + } as any as PartAndPieces, |
| 188 | + singleLayerPart: { |
| 189 | + part: { _id: 'pLookahead_sl', part: 'lookahead_sl' }, |
| 190 | + |
| 191 | + pieces: [ |
| 192 | + // piece1 — At Part Start - should be ignored |
| 193 | + createFakePiece('sl_piece1', { |
| 194 | + enable: { start: 0, duration: partDuration - 0 }, |
| 195 | + sourceLayerId: layer, |
| 196 | + // We generate three objects, one at the piece's start, one 700 ms after the piece's start, one 1700 ms after the piece's start. |
| 197 | + // If the piece is not ignored (which shouldn't happen, it would mean that the logic is wrong) |
| 198 | + // for reference the calculated offset values should be 1000, 300 and no offset |
| 199 | + timelineObjectsString: generateFakeObectsString('sl_piece1', layer, 700, 1700), |
| 200 | + }), |
| 201 | + |
| 202 | + // piece2 — Before Offset — lookaheadOffset should equal nextTimeOffset - the piece's start - the timeline object's start |
| 203 | + createFakePiece('sl_piece2', { |
| 204 | + enable: { start: 500, duration: partDuration - 500 }, |
| 205 | + sourceLayerId: layer, |
| 206 | + // We generate three objects, one at the piece's start, one 200 ms after the piece's start, one 1200 ms after the piece's start. |
| 207 | + // We need to check if all offsets are calculated correctly. (500, 300 and no offset) |
| 208 | + timelineObjectsString: generateFakeObectsString('sl_piece2', layer, 200, 1200), |
| 209 | + }), |
| 210 | + |
| 211 | + // piece3 — After Offset — should be ignored |
| 212 | + createFakePiece('sl_piece3', { |
| 213 | + enable: { start: 1500, duration: partDuration - 1500 }, |
| 214 | + sourceLayerId: layer, |
| 215 | + // We generate three objects, one at the piece's start, one 200 ms after the piece's start, one 400 ms after the piece's start. |
| 216 | + // If the piece is not ignored (which shouldn't happen, it would mean that the logic is wrong) |
| 217 | + // for reference no offset should be calculated for all of it's objects. |
| 218 | + timelineObjectsString: generateFakeObectsString('sl_piece3', layer, 200, 400), |
| 219 | + }), |
| 220 | + ], |
| 221 | + onTimeline: true, |
| 222 | + } as any as PartAndPieces, |
| 223 | + singleLayerPartWhile: { |
| 224 | + part: { _id: 'pLookahead_sl_while', part: 'lookahead_sl_while' }, |
| 225 | + |
| 226 | + pieces: [ |
| 227 | + // piece1 — At Part Start - should be ignored |
| 228 | + createFakePiece('sl_piece1_while', { |
| 229 | + enable: { start: 0, duration: partDuration - 0 }, |
| 230 | + sourceLayerId: layer, |
| 231 | + // We generate three objects, one at the piece's start, one 700 ms after the piece's start, one 1700 ms after the piece's start. |
| 232 | + // If the piece is not ignored (which shouldn't happen, it would mean that the logic is wrong) |
| 233 | + // for reference the calculated offset values should be 1000, 300 and no offset |
| 234 | + timelineObjectsString: generateFakeObectsString('sl_piece1_while', layer, 700, 1700, true), |
| 235 | + }), |
| 236 | + |
| 237 | + // piece2 — Before Offset — lookaheadOffset should equal nextTimeOffset - the piece's start - the timeline object's start |
| 238 | + createFakePiece('sl_piece2_while', { |
| 239 | + enable: { start: 500, duration: partDuration - 500 }, |
| 240 | + sourceLayerId: layer, |
| 241 | + // We generate three objects, one at the piece's start, one 200 ms after the piece's start, one 1200 ms after the piece's start. |
| 242 | + // We need to check if all offsets are calculated correctly. (500, 300 and no offset) |
| 243 | + timelineObjectsString: generateFakeObectsString('sl_piece2_while', layer, 200, 1200, true), |
| 244 | + }), |
| 245 | + |
| 246 | + // piece3 — After Offset — should be ignored |
| 247 | + createFakePiece('sl_piece3_while', { |
| 248 | + enable: { start: 1500, duration: partDuration - 1500 }, |
| 249 | + sourceLayerId: layer, |
| 250 | + // We generate three objects, one at the piece's start, one 200 ms after the piece's start, one 400 ms after the piece's start. |
| 251 | + // If the piece is not ignored (which shouldn't happen, it would mean that the logic is wrong) |
| 252 | + // for reference no offset should be calculated for all of it's objects. |
| 253 | + timelineObjectsString: generateFakeObectsString('sl_piece3_while', layer, 200, 400, true), |
| 254 | + }), |
| 255 | + ], |
| 256 | + onTimeline: true, |
| 257 | + } as any as PartAndPieces, |
| 258 | + |
| 259 | + nextTimeOffset: 1000, |
| 260 | + |
| 261 | + layer, |
| 262 | + lookaheadOffsetLayerIds, |
38 | 263 | } |
0 commit comments