@@ -181,6 +181,7 @@ async function renderPanel(
181181 flatEnabled : boolean ,
182182 elementOverride : ReturnType < typeof baseElement > = baseElement ( ) ,
183183 propsOverride : Partial < PropertyPanelProps > = { } ,
184+ currentTime ?: number ,
184185) {
185186 vi . resetModules ( ) ;
186187 vi . doMock ( "./manualEditingAvailability" , async ( ) => {
@@ -189,6 +190,13 @@ async function renderPanel(
189190 ) ;
190191 return { ...actual , STUDIO_FLAT_INSPECTOR_ENABLED : flatEnabled } ;
191192 } ) ;
193+ // Seed the playhead on the SAME store instance PropertyPanel.tsx will read via
194+ // usePlayerStore (module-fresh since the resetModules() above) — must happen
195+ // before PropertyPanel is imported/rendered so its initial render sees it.
196+ if ( currentTime !== undefined ) {
197+ const { usePlayerStore } = await import ( "../../player/store/playerStore" ) ;
198+ usePlayerStore . getState ( ) . setCurrentTime ( currentTime ) ;
199+ }
192200 const { PropertyPanel } = await import ( "./PropertyPanel" ) ;
193201 const host = document . createElement ( "div" ) ;
194202 document . body . append ( host ) ;
@@ -483,10 +491,20 @@ describe("PropertyPanel — flat Layout/Motion timing agreement (whole-plan cohe
483491 "Layout's X-row keyframe gutter seeks to the SAME absolute time Motion's Timing row shows as the midpoint (50% of an inferred 2s-5s range = 3.5s)" ,
484492 async ( ) => {
485493 const onSeekToTime = vi . fn ( ) ;
486- const { host, root } = await renderPanel ( true , inferredMotionElement ( ) , {
487- gsapAnimations : [ INFERRED_TIMING_ANIMATION ] ,
488- onSeekToTime,
489- } ) ;
494+ // Seed the playhead at the clip's real start (t=2, the 0% keyframe's
495+ // absolute time) — now that the follow-up fix also recomputes
496+ // `currentPct` from the corrected elStart/elDuration basis, "current
497+ // position is at the 0% keyframe" must be expressed as an actual t=2
498+ // seek rather than relying on the store's untouched t=0 default (which,
499+ // post-fix, resolves to a currentPct of -66.7% — well outside the 0%
500+ // keyframe's tolerance window, and no longer "the case the coherence
501+ // bug affected" that this test documents).
502+ const { host, root } = await renderPanel (
503+ true ,
504+ inferredMotionElement ( ) ,
505+ { gsapAnimations : [ INFERRED_TIMING_ANIMATION ] , onSeekToTime } ,
506+ 2 ,
507+ ) ;
490508 openFlatGroup ( host , "Layout" ) ;
491509 const layoutGroup = host . querySelector ( '[data-flat-group-open="true"]' ) ;
492510 if ( ! layoutGroup ) throw new Error ( "expected the Layout group to be open" ) ;
@@ -498,7 +516,7 @@ describe("PropertyPanel — flat Layout/Motion timing agreement (whole-plan cohe
498516 const gutter = xRow . querySelector ( '[data-flat-kf-gutter="true"]' ) ;
499517 if ( ! gutter ) throw new Error ( "expected a keyframe gutter on the X row" ) ;
500518 // The diamond button always carries a `title`; the two plain arrow
501- // buttons don't. At currentPct=0 with keyframes at 0/50/100% , the prev
519+ // buttons don't. At currentPct=0 (playhead on the 0% keyframe) , the prev
502520 // arrow is disabled (no earlier keyframe) and the next arrow seeks to
503521 // the 50% keyframe — exactly the case the coherence bug affected.
504522 const nextArrow = Array . from ( gutter . querySelectorAll < HTMLButtonElement > ( "button" ) ) . find (
@@ -514,3 +532,86 @@ describe("PropertyPanel — flat Layout/Motion timing agreement (whole-plan cohe
514532 RENDER_TIMEOUT_MS ,
515533 ) ;
516534} ) ;
535+
536+ // Follow-up fix (review of 684ec4e87): the seek-basis fix above corrected
537+ // WHERE a keyframe click seeks to, but `currentPct` — the value that drives
538+ // KeyframeNavigation's diamond active/inactive state and prev/next arrow
539+ // targeting — still used the OLD naive basis. For an inferred-duration
540+ // element, seeking to a keyframe's actual absolute time no longer lit that
541+ // keyframe's diamond as active. Prove the round-trip here: seek to the exact
542+ // absolute time of the 50% keyframe (2 + 0.5*3 = 3.5) and confirm its diamond
543+ // renders "active" (title="Remove x keyframe"), not "inactive"/"ghost".
544+ describe ( "PropertyPanel — flat Layout currentPct basis (currentPct follow-up fix)" , ( ) => {
545+ it (
546+ "lights the X-row keyframe diamond as active when the playhead is seeked to that keyframe's real absolute time (inferred 2s-5s range, 50% keyframe = 3.5s)" ,
547+ async ( ) => {
548+ const { host, root } = await renderPanel (
549+ true ,
550+ inferredMotionElement ( ) ,
551+ { gsapAnimations : [ INFERRED_TIMING_ANIMATION ] } ,
552+ 3.5 ,
553+ ) ;
554+ openFlatGroup ( host , "Layout" ) ;
555+ const layoutGroup = host . querySelector ( '[data-flat-group-open="true"]' ) ;
556+ if ( ! layoutGroup ) throw new Error ( "expected the Layout group to be open" ) ;
557+
558+ const xRow = Array . from ( layoutGroup . querySelectorAll < HTMLElement > ( ".group" ) ) . find (
559+ ( el ) => el . querySelector ( "span" ) ?. textContent === "X" ,
560+ ) ;
561+ if ( ! xRow ) throw new Error ( "expected an X row" ) ;
562+ const gutter = xRow . querySelector ( '[data-flat-kf-gutter="true"]' ) ;
563+ if ( ! gutter ) throw new Error ( "expected a keyframe gutter on the X row" ) ;
564+ const diamond = gutter . querySelector < HTMLButtonElement > ( "button[title]" ) ;
565+ if ( ! diamond ) throw new Error ( "expected a keyframe diamond button" ) ;
566+ // KeyframeDiamond's title mapping: active -> "Remove ... keyframe",
567+ // inactive -> "Add ... keyframe", ghost -> "Convert ... to keyframes".
568+ // Before this fix, currentPct was computed against the naive
569+ // elStart=0/elDuration=1 basis, so t=3.5 produced currentPct=350% —
570+ // nowhere near the 50% keyframe within KeyframeNavigation's tolerance —
571+ // and the diamond stayed "inactive" even though the playhead was
572+ // exactly on that keyframe's real time.
573+ expect ( diamond . title ) . toBe ( "Remove x keyframe" ) ;
574+ act ( ( ) => root . unmount ( ) ) ;
575+ } ,
576+ RENDER_TIMEOUT_MS ,
577+ ) ;
578+
579+ it (
580+ "prev/next arrows re-center on the current keyframe once currentPct agrees with the corrected seek basis" ,
581+ async ( ) => {
582+ const onSeekToTime = vi . fn ( ) ;
583+ const { host, root } = await renderPanel (
584+ true ,
585+ inferredMotionElement ( ) ,
586+ { gsapAnimations : [ INFERRED_TIMING_ANIMATION ] , onSeekToTime } ,
587+ 3.5 ,
588+ ) ;
589+ openFlatGroup ( host , "Layout" ) ;
590+ const layoutGroup = host . querySelector ( '[data-flat-group-open="true"]' ) ;
591+ if ( ! layoutGroup ) throw new Error ( "expected the Layout group to be open" ) ;
592+
593+ const xRow = Array . from ( layoutGroup . querySelectorAll < HTMLElement > ( ".group" ) ) . find (
594+ ( el ) => el . querySelector ( "span" ) ?. textContent === "X" ,
595+ ) ;
596+ if ( ! xRow ) throw new Error ( "expected an X row" ) ;
597+ const gutter = xRow . querySelector ( '[data-flat-kf-gutter="true"]' ) ;
598+ if ( ! gutter ) throw new Error ( "expected a keyframe gutter on the X row" ) ;
599+ const buttons = Array . from ( gutter . querySelectorAll < HTMLButtonElement > ( "button" ) ) ;
600+ const [ prevArrow , , nextArrow ] = buttons ;
601+ if ( ! prevArrow || ! nextArrow ) throw new Error ( "expected prev/next arrow buttons" ) ;
602+ // At the 50% keyframe (t=3.5), prev should target the 0% keyframe
603+ // (absolute t=2) and next should target the 100% keyframe (absolute
604+ // t=5) — both only resolvable once currentPct agrees with elStart=2/
605+ // elDuration=3, the same basis the seek fix already uses.
606+ expect ( prevArrow . disabled ) . toBe ( false ) ;
607+ act ( ( ) => prevArrow . dispatchEvent ( new MouseEvent ( "click" , { bubbles : true } ) ) ) ;
608+ expect ( onSeekToTime ) . toHaveBeenLastCalledWith ( 2 ) ;
609+
610+ expect ( nextArrow . disabled ) . toBe ( false ) ;
611+ act ( ( ) => nextArrow . dispatchEvent ( new MouseEvent ( "click" , { bubbles : true } ) ) ) ;
612+ expect ( onSeekToTime ) . toHaveBeenLastCalledWith ( 5 ) ;
613+ act ( ( ) => root . unmount ( ) ) ;
614+ } ,
615+ RENDER_TIMEOUT_MS ,
616+ ) ;
617+ } ) ;
0 commit comments