1- import { describe , expect , it } from "vitest" ;
1+ // @vitest -environment happy-dom
2+
3+ import React , { act , useEffect } from "react" ;
4+ import { createRoot } from "react-dom/client" ;
5+ import { afterEach , describe , expect , it } from "vitest" ;
26import {
37 buildExpandedElements ,
48 resolveTimelineExpansionRawId ,
9+ useExpandedTimelineElements ,
510} from "./useExpandedTimelineElements" ;
611import { buildTimelineElementKey } from "../lib/timelineElementHelpers" ;
7- import type { TimelineElement } from "../store/playerStore" ;
12+ import { usePlayerStore , type TimelineElement } from "../store/playerStore" ;
813import type { ClipManifestClip } from "../lib/playbackTypes" ;
914
15+ globalThis . IS_REACT_ACT_ENVIRONMENT = true ;
16+
1017const clip = ( over : Partial < ClipManifestClip > ) : ClipManifestClip => ( {
1118 id : "x" ,
1219 label : "x" ,
@@ -31,6 +38,19 @@ const el = (over: Partial<TimelineElement>): TimelineElement => ({
3138 ...over ,
3239} ) ;
3340
41+ function TimelineExpansionHarness ( { onValue } : { onValue : ( value : TimelineElement [ ] ) => void } ) {
42+ const value = useExpandedTimelineElements ( ) ;
43+ useEffect ( ( ) => {
44+ onValue ( value ) ;
45+ } , [ onValue , value ] ) ;
46+ return null ;
47+ }
48+
49+ afterEach ( ( ) => {
50+ document . body . innerHTML = "" ;
51+ usePlayerStore . getState ( ) . reset ( ) ;
52+ } ) ;
53+
3454describe ( "buildExpandedElements" , ( ) => {
3555 it ( "rebases a 1-level child onto its sub-comp host (start + sourceFile)" , ( ) => {
3656 // host s3 at absolute 16 → stats-panel.html; children live in that file.
@@ -357,7 +377,7 @@ describe("buildExpandedElements", () => {
357377 it ( "keeps the host row present at every playhead position (keyframe lane repro)" , ( ) => {
358378 // Live repro with no drag at all: seek 0 gave 3 diamonds, seek 7.68 gave 0,
359379 // seek 0.2 gave 3. Diamonds render per row from keyframeCache.get(elementKey),
360- // so the whole lane went with the host row whenever the paused drill-in
380+ // so the whole lane went with the host row whenever the store-time drill-in
361381 // substituted it for its children.
362382 const elements = [
363383 el ( { id : "scene" , domId : "scene" , key : "index.html#scene" , start : 0 , duration : 12 } ) ,
@@ -371,7 +391,6 @@ describe("buildExpandedElements", () => {
371391 for ( const currentTime of [ 0 , 7.68 , 0.2 ] ) {
372392 const rawId = resolveTimelineExpansionRawId ( {
373393 selectedElementId : null ,
374- isPlaying : false ,
375394 currentTime,
376395 manifest,
377396 parentMap,
@@ -424,21 +443,20 @@ describe("buildExpandedElements", () => {
424443} ) ;
425444
426445describe ( "resolveTimelineExpansionRawId" , ( ) => {
427- it ( "returns null when paused inside a childless top-level clip" , ( ) => {
446+ it ( "returns null inside a childless top-level clip" , ( ) => {
428447 const manifest = [ clip ( { id : "title" , start : 0 , duration : 4 } ) ] ;
429448
430449 expect (
431450 resolveTimelineExpansionRawId ( {
432451 selectedElementId : null ,
433- isPlaying : false ,
434452 currentTime : 2 ,
435453 manifest,
436454 parentMap : new Map ( ) ,
437455 } ) ,
438456 ) . toBeNull ( ) ;
439457 } ) ;
440458
441- it ( "auto-expands an active composition with children when paused and nothing is selected" , ( ) => {
459+ it ( "auto-expands an active composition with children when nothing is selected" , ( ) => {
442460 const manifest = [
443461 clip ( { id : "scene" , start : 1 , duration : 5 } ) ,
444462 clip ( { id : "headline" , start : 1.5 , duration : 2 } ) ,
@@ -448,7 +466,6 @@ describe("resolveTimelineExpansionRawId", () => {
448466 expect (
449467 resolveTimelineExpansionRawId ( {
450468 selectedElementId : null ,
451- isPlaying : false ,
452469 currentTime : 2 ,
453470 manifest,
454471 parentMap,
@@ -468,7 +485,6 @@ describe("resolveTimelineExpansionRawId", () => {
468485 expect (
469486 resolveTimelineExpansionRawId ( {
470487 selectedElementId : null ,
471- isPlaying : false ,
472488 currentTime : 12 ,
473489 manifest,
474490 parentMap,
@@ -491,15 +507,14 @@ describe("resolveTimelineExpansionRawId", () => {
491507 expect (
492508 resolveTimelineExpansionRawId ( {
493509 selectedElementId : null ,
494- isPlaying : false ,
495510 currentTime : 5 ,
496511 manifest,
497512 parentMap,
498513 } ) ,
499514 ) . toBe ( "second" ) ;
500515 } ) ;
501516
502- it ( "auto-expands the innermost active nested composition when paused " , ( ) => {
517+ it ( "auto-expands the innermost active nested composition" , ( ) => {
503518 const manifest = [
504519 clip ( { id : "outer" , start : 0 , duration : 10 } ) ,
505520 clip ( { id : "inner" , start : 2 , duration : 5 } ) ,
@@ -513,15 +528,14 @@ describe("resolveTimelineExpansionRawId", () => {
513528 expect (
514529 resolveTimelineExpansionRawId ( {
515530 selectedElementId : null ,
516- isPlaying : false ,
517531 currentTime : 3.5 ,
518532 manifest,
519533 parentMap,
520534 } ) ,
521535 ) . toBe ( "inner" ) ;
522536 } ) ;
523537
524- it ( "does not auto-expand an active composition while playing " , ( ) => {
538+ it ( "resolves an active composition from the current store time " , ( ) => {
525539 const manifest = [
526540 clip ( { id : "scene" , start : 0 , duration : 5 } ) ,
527541 clip ( { id : "headline" , start : 1 , duration : 2 } ) ,
@@ -531,15 +545,49 @@ describe("resolveTimelineExpansionRawId", () => {
531545 expect (
532546 resolveTimelineExpansionRawId ( {
533547 selectedElementId : null ,
534- isPlaying : true ,
535548 currentTime : 2 ,
536549 manifest,
537550 parentMap,
538551 } ) ,
539- ) . toBeNull ( ) ;
552+ ) . toBe ( "scene" ) ;
553+ } ) ;
554+
555+ it ( "keeps inline children visible when the master timeline is playing" , ( ) => {
556+ const elements = [
557+ el ( { id : "scene" , domId : "scene" , key : "index.html#scene" , start : 0 , duration : 5 } ) ,
558+ ] ;
559+ const manifest = [
560+ clip ( { id : "scene" , start : 0 , duration : 5 , compositionSrc : "scene.html" } ) ,
561+ clip ( { id : "headline" , start : 1 , duration : 2 } ) ,
562+ ] ;
563+ const parentMap = new Map ( [ [ "headline" , "scene" ] ] ) ;
564+ let rows : TimelineElement [ ] | undefined ;
565+ const host = document . createElement ( "div" ) ;
566+ document . body . append ( host ) ;
567+ const root = createRoot ( host ) ;
568+
569+ act ( ( ) => {
570+ usePlayerStore . setState ( {
571+ elements,
572+ clipManifest : manifest ,
573+ clipParentMap : parentMap ,
574+ currentTime : 2 ,
575+ isPlaying : true ,
576+ } ) ;
577+ root . render (
578+ React . createElement ( TimelineExpansionHarness , {
579+ onValue : ( value ) => ( rows = value ) ,
580+ } ) ,
581+ ) ;
582+ } ) ;
583+
584+ expect ( usePlayerStore . getState ( ) . isPlaying ) . toBe ( true ) ;
585+ expect ( rows ?. map ( ( row ) => row . domId ?? row . id ) ) . toEqual ( [ "scene" , "headline" ] ) ;
586+
587+ act ( ( ) => root . unmount ( ) ) ;
540588 } ) ;
541589
542- it ( "keeps selected elements ahead of paused active composition auto-expansion" , ( ) => {
590+ it ( "keeps selected elements ahead of active composition auto-expansion" , ( ) => {
543591 const manifest = [
544592 clip ( { id : "scene" , start : 0 , duration : 6 } ) ,
545593 clip ( { id : "headline" , start : 1 , duration : 2 } ) ,
@@ -553,7 +601,6 @@ describe("resolveTimelineExpansionRawId", () => {
553601 expect (
554602 resolveTimelineExpansionRawId ( {
555603 selectedElementId : "caption" ,
556- isPlaying : false ,
557604 currentTime : 1.5 ,
558605 manifest,
559606 parentMap,
0 commit comments