33import React , { act , useRef } from "react" ;
44import { createRoot } from "react-dom/client" ;
55import { afterEach , describe , expect , it , vi } from "vitest" ;
6- import { usePlayerStore } from "../store/playerStore" ;
6+ import { usePlayerStore , type TimelineElement } from "../store/playerStore" ;
77import { createTimelineRowGeometry } from "./timelineLayout" ;
88import type { TimelineLogicalRow } from "./timelineKeyboardNavigation" ;
99import { useTimelineKeyboardActor } from "./useTimelineKeyboardActor" ;
@@ -57,13 +57,15 @@ interface HarnessProps {
5757 logicalRows ?: readonly TimelineLogicalRow [ ] ;
5858 rowHeights ?: readonly number [ ] ;
5959 onToggleRow ?: ( target : TimelineLogicalRow ) => void ;
60+ onDrillDown ?: ( element : TimelineElement ) => void ;
6061}
6162
6263function Harness ( {
6364 focusedTargetId = null ,
6465 logicalRows = rows ,
6566 rowHeights = logicalRows . map ( ( ) => 48 ) ,
6667 onToggleRow = vi . fn ( ) ,
68+ onDrillDown,
6769} : HarnessProps ) {
6870 const scrollRef = useRef < HTMLDivElement > ( null ) ;
6971 const keyboard = useTimelineKeyboardActor ( {
@@ -75,6 +77,7 @@ function Harness({
7577 ) ,
7678 scrollRef,
7779 onToggleRow,
80+ onDrillDown,
7881 } ) ;
7982 return (
8083 < div ref = { scrollRef } onFocus = { keyboard . onFocus } onKeyDown = { keyboard . onKeyDown } >
@@ -228,6 +231,26 @@ describe("useTimelineKeyboardActor", () => {
228231 act ( ( ) => root . unmount ( ) ) ;
229232 } ) ;
230233
234+ it ( "drills into a composition clip on Enter and leaves a plain clip alone" , ( ) => {
235+ const scene = { id : "scene" , tag : "div" , start : 0 , duration : 2 , track : 1 } ;
236+ const withElements = rows . map ( ( row , index ) => ( {
237+ ...row ,
238+ items : row . items . map ( ( item ) => ( {
239+ ...item ,
240+ element : index === 0 ? { ...scene , compositionSrc : "scene.html" } : scene ,
241+ } ) ) ,
242+ } ) ) ;
243+ const onDrillDown = vi . fn ( ) ;
244+ const { host, root } = renderHarness ( { logicalRows : withElements , onDrillDown } ) ;
245+ const composition = host . querySelector < HTMLElement > ( '[data-timeline-focus-id="clip-1"]' ) ! ;
246+ const plain = host . querySelector < HTMLElement > ( '[data-timeline-focus-id="clip-2"]' ) ! ;
247+ expect ( key ( plain , "Enter" ) . defaultPrevented ) . toBe ( false ) ;
248+ expect ( onDrillDown ) . not . toHaveBeenCalled ( ) ;
249+ expect ( key ( composition , "Enter" ) . defaultPrevented ) . toBe ( true ) ;
250+ expect ( onDrillDown ) . toHaveBeenCalledWith ( withElements [ 0 ] ! . items [ 0 ] ! . element ) ;
251+ act ( ( ) => root . unmount ( ) ) ;
252+ } ) ;
253+
231254 it ( "collapses expanded rows and leaves native header controls to the browser" , ( ) => {
232255 const onToggleRow = vi . fn ( ) ;
233256 const expandedRows = [ { ...rows [ 0 ] ! , expanded : true } , ...rows . slice ( 1 ) ] ;
0 commit comments