@@ -1163,6 +1163,61 @@ describe("VirtualPreview replay", () => {
11631163 expect ( reportedTimes ( onTimeChange ) . at ( - 1 ) ) . toBe ( 14 ) ;
11641164 } ) ;
11651165
1166+ it . each ( [
1167+ { initiallyPlaying : true , firstIntent : undefined , nextIntent : undefined , shouldPlay : true } ,
1168+ { initiallyPlaying : true , firstIntent : true , nextIntent : undefined , shouldPlay : true } ,
1169+ { initiallyPlaying : true , firstIntent : true , nextIntent : false , shouldPlay : false } ,
1170+ { initiallyPlaying : false , firstIntent : undefined , nextIntent : undefined , shouldPlay : false } ,
1171+ ] ) ( "keeps a source-switch scrub playing unless explicitly paused: $firstIntent → $nextIntent" , ( {
1172+ initiallyPlaying,
1173+ firstIntent,
1174+ nextIntent,
1175+ shouldPlay,
1176+ } ) => {
1177+ const sources : VideoSource [ ] = [
1178+ { id : "a1" , src : "file:///tmp/a1.mp4" , label : "a1" } ,
1179+ { id : "a2" , src : "file:///tmp/a2.mp4" , label : "a2" } ,
1180+ ] ;
1181+ const clips = [ clip ( "clip_1" , "a1" , 0 , 5 , 0 ) , clip ( "clip_2" , "a2" , 0 , 5 , 5 ) ] ;
1182+ let seekTarget : {
1183+ timeSec : number ;
1184+ requestId : number ;
1185+ preservePlayback ?: boolean ;
1186+ } | null = null ;
1187+ const view = render (
1188+ < VirtualPreview videoSources = { sources } clips = { clips } seekTarget = { seekTarget } /> ,
1189+ ) ;
1190+ const firstElement = view . container . querySelector ( "video" ) ;
1191+ if ( ! firstElement ) throw new Error ( "no initial video" ) ;
1192+ const firstVideo = driveVideo ( firstElement ) ;
1193+ act ( ( ) => fireEvent . loadedMetadata ( firstElement ) ) ;
1194+ if ( initiallyPlaying ) firstVideo . play ( ) ;
1195+ firstVideo . seekTo ( 3 ) ;
1196+
1197+ act ( ( ) => {
1198+ seekTarget = { timeSec : 6 , requestId : 1 , preservePlayback : firstIntent } ;
1199+ view . rerender (
1200+ < VirtualPreview videoSources = { sources } clips = { clips } seekTarget = { seekTarget } /> ,
1201+ ) ;
1202+ } ) ;
1203+ const nextElement = view . container . querySelector ( "video" ) ;
1204+ if ( ! nextElement || nextElement === firstElement ) throw new Error ( "source did not switch" ) ;
1205+ const nextVideo = driveVideo ( nextElement ) ;
1206+ expect ( nextElement . paused ) . toBe ( true ) ;
1207+
1208+ // Pointerup or a later drag position arrives while the new decoder is
1209+ // still paused before metadata. It must retain the scrub's play intent.
1210+ act ( ( ) => {
1211+ seekTarget = { timeSec : 6.5 , requestId : 2 , preservePlayback : nextIntent } ;
1212+ view . rerender (
1213+ < VirtualPreview videoSources = { sources } clips = { clips } seekTarget = { seekTarget } /> ,
1214+ ) ;
1215+ } ) ;
1216+ act ( ( ) => fireEvent . loadedMetadata ( nextElement ) ) ;
1217+ expect ( nextVideo . currentTime ) . toBe ( 1.5 ) ;
1218+ expect ( nextElement . paused ) . toBe ( ! shouldPlay ) ;
1219+ } ) ;
1220+
11661221 it ( "does not let stale loadState in tick closure block clip boundary checks or timeline end" , ( ) => {
11671222 const sources : VideoSource [ ] = [
11681223 { id : "a1" , src : "file:///tmp/a1.mp4" , label : "a1" } ,
0 commit comments