@@ -18,7 +18,14 @@ import {
1818 shouldHandleTimelineDeleteKey ,
1919 shouldAutoScrollTimeline ,
2020} from "./Timeline" ;
21- import { RULER_H , TRACK_H } from "./timelineLayout" ;
21+ import {
22+ GUTTER ,
23+ MIN_TIMELINE_EXTENT_S ,
24+ RULER_H ,
25+ TRACK_H ,
26+ getTimelineDisplayContentWidth ,
27+ getTimelineFitPps ,
28+ } from "./timelineLayout" ;
2229import { formatTime } from "../lib/time" ;
2330import { usePlayerStore } from "../store/playerStore" ;
2431import { TimelineEditProvider } from "../../contexts/TimelineEditContext" ;
@@ -323,55 +330,55 @@ describe("generateTicks", () => {
323330} ) ;
324331
325332describe ( "formatTime" , ( ) => {
326- it ( "formats 0 seconds as 0 :00" , ( ) => {
327- expect ( formatTime ( 0 ) ) . toBe ( "0 :00" ) ;
333+ it ( "formats 0 seconds as 00 :00" , ( ) => {
334+ expect ( formatTime ( 0 ) ) . toBe ( "00 :00" ) ;
328335 } ) ;
329336
330337 // fallow-ignore-next-line code-duplication
331338 it ( "formats seconds below a minute" , ( ) => {
332- expect ( formatTime ( 5 ) ) . toBe ( "0 :05" ) ;
333- expect ( formatTime ( 30 ) ) . toBe ( "0 :30" ) ;
334- expect ( formatTime ( 59 ) ) . toBe ( "0 :59" ) ;
339+ expect ( formatTime ( 5 ) ) . toBe ( "00 :05" ) ;
340+ expect ( formatTime ( 30 ) ) . toBe ( "00 :30" ) ;
341+ expect ( formatTime ( 59 ) ) . toBe ( "00 :59" ) ;
335342 } ) ;
336343
337344 it ( "formats exactly one minute" , ( ) => {
338- expect ( formatTime ( 60 ) ) . toBe ( "1 :00" ) ;
345+ expect ( formatTime ( 60 ) ) . toBe ( "01 :00" ) ;
339346 } ) ;
340347
341348 it ( "formats minutes and seconds" , ( ) => {
342- expect ( formatTime ( 90 ) ) . toBe ( "1 :30" ) ;
343- expect ( formatTime ( 125 ) ) . toBe ( "2 :05" ) ;
349+ expect ( formatTime ( 90 ) ) . toBe ( "01 :30" ) ;
350+ expect ( formatTime ( 125 ) ) . toBe ( "02 :05" ) ;
344351 } ) ;
345352
346353 it ( "floors fractional seconds" , ( ) => {
347- expect ( formatTime ( 5.7 ) ) . toBe ( "0 :05" ) ;
348- expect ( formatTime ( 59.9 ) ) . toBe ( "0 :59" ) ;
349- expect ( formatTime ( 90.5 ) ) . toBe ( "1 :30" ) ;
354+ expect ( formatTime ( 5.7 ) ) . toBe ( "00 :05" ) ;
355+ expect ( formatTime ( 59.9 ) ) . toBe ( "00 :59" ) ;
356+ expect ( formatTime ( 90.5 ) ) . toBe ( "01 :30" ) ;
350357 } ) ;
351358
352359 it ( "handles large values" , ( ) => {
353360 expect ( formatTime ( 600 ) ) . toBe ( "10:00" ) ;
354361 expect ( formatTime ( 3661 ) ) . toBe ( "61:01" ) ;
355362 } ) ;
356363
357- it ( "zero-pads seconds to two digits" , ( ) => {
358- expect ( formatTime ( 1 ) ) . toBe ( "0 :01" ) ;
359- expect ( formatTime ( 9 ) ) . toBe ( "0 :09" ) ;
360- expect ( formatTime ( 61 ) ) . toBe ( "1 :01" ) ;
364+ it ( "zero-pads minutes and seconds to two digits" , ( ) => {
365+ expect ( formatTime ( 1 ) ) . toBe ( "00 :01" ) ;
366+ expect ( formatTime ( 9 ) ) . toBe ( "00 :09" ) ;
367+ expect ( formatTime ( 61 ) ) . toBe ( "01 :01" ) ;
361368 } ) ;
362369} ) ;
363370
364371describe ( "formatTimelineTickLabel" , ( ) => {
365372 it ( "uses minute-second labels for normal timeline intervals" , ( ) => {
366- expect ( formatTimelineTickLabel ( 90 , 180 , 5 ) ) . toBe ( "1 :30" ) ;
373+ expect ( formatTimelineTickLabel ( 90 , 180 , 5 ) ) . toBe ( "01 :30" ) ;
367374 } ) ;
368375
369376 it ( "uses hour labels for long timelines" , ( ) => {
370377 expect ( formatTimelineTickLabel ( 3661 , 4000 , 60 ) ) . toBe ( "1:01:01" ) ;
371378 } ) ;
372379
373380 it ( "shows subsecond labels when the major ruler interval is below one second" , ( ) => {
374- expect ( formatTimelineTickLabel ( 1.5 , 3 , 0.5 ) ) . toBe ( "0 :01.5" ) ;
381+ expect ( formatTimelineTickLabel ( 1.5 , 3 , 0.5 ) ) . toBe ( "00 :01.5" ) ;
375382 } ) ;
376383} ) ;
377384
@@ -390,6 +397,80 @@ describe("shouldAutoScrollTimeline", () => {
390397 } ) ;
391398} ) ;
392399
400+ describe ( "getTimelineFitPps (min 60s extent)" , ( ) => {
401+ const viewport = 632 ; // usable width = 632 - GUTTER - 2 = 598
402+
403+ it ( "computes fit pps against the 60s floor for short compositions" , ( ) => {
404+ // A 10s comp maps 60s onto the viewport → the comp takes ~1/6 of the width.
405+ const pps = getTimelineFitPps ( viewport , 10 ) ;
406+ expect ( pps ) . toBeCloseTo ( ( viewport - GUTTER - 2 ) / MIN_TIMELINE_EXTENT_S ) ;
407+ expect ( 10 * pps ) . toBeCloseTo ( ( viewport - GUTTER - 2 ) / 6 ) ;
408+ } ) ;
409+
410+ it ( "keeps filling the viewport with the composition when it is 60s or longer" , ( ) => {
411+ expect ( getTimelineFitPps ( viewport , 60 ) ) . toBeCloseTo ( ( viewport - GUTTER - 2 ) / 60 ) ;
412+ expect ( getTimelineFitPps ( viewport , 120 ) ) . toBeCloseTo ( ( viewport - GUTTER - 2 ) / 120 ) ;
413+ } ) ;
414+
415+ it ( "falls back to 100 pps before the viewport is measured" , ( ) => {
416+ expect ( getTimelineFitPps ( 0 , 10 ) ) . toBe ( 100 ) ;
417+ expect ( getTimelineFitPps ( GUTTER , 10 ) ) . toBe ( 100 ) ;
418+ expect ( getTimelineFitPps ( Number . NaN , 10 ) ) . toBe ( 100 ) ;
419+ } ) ;
420+
421+ it ( "uses the floor for zero/invalid durations" , ( ) => {
422+ expect ( getTimelineFitPps ( viewport , 0 ) ) . toBeCloseTo (
423+ ( viewport - GUTTER - 2 ) / MIN_TIMELINE_EXTENT_S ,
424+ ) ;
425+ expect ( getTimelineFitPps ( viewport , Number . NaN ) ) . toBeCloseTo (
426+ ( viewport - GUTTER - 2 ) / MIN_TIMELINE_EXTENT_S ,
427+ ) ;
428+ } ) ;
429+ } ) ;
430+
431+ describe ( "getTimelineDisplayContentWidth" , ( ) => {
432+ it ( "always spans at least MIN_TIMELINE_EXTENT_S seconds of content" , ( ) => {
433+ // 10s of content at 20 pps = 200px; the floor keeps 60s (1200px) rendered.
434+ expect (
435+ getTimelineDisplayContentWidth ( { trackContentWidth : 200 , viewportWidth : 400 , pps : 20 } ) ,
436+ ) . toBe ( MIN_TIMELINE_EXTENT_S * 20 ) ;
437+ } ) ;
438+
439+ it ( "still fills the viewport when that is larger than the 60s floor" , ( ) => {
440+ expect (
441+ getTimelineDisplayContentWidth ( { trackContentWidth : 200 , viewportWidth : 2000 , pps : 5 } ) ,
442+ ) . toBe ( 2000 - GUTTER - 2 ) ;
443+ } ) ;
444+
445+ it ( "tracks a drag ghost past every other bound (drag-to-extend)" , ( ) => {
446+ expect (
447+ getTimelineDisplayContentWidth ( {
448+ trackContentWidth : 500 ,
449+ viewportWidth : 400 ,
450+ pps : 5 ,
451+ dragGhostEndPx : 5000 ,
452+ } ) ,
453+ ) . toBe ( 5000 ) ;
454+ } ) ;
455+
456+ it ( "tracks a resize (trim) ghost past every other bound (trim-to-extend)" , ( ) => {
457+ expect (
458+ getTimelineDisplayContentWidth ( {
459+ trackContentWidth : 500 ,
460+ viewportWidth : 400 ,
461+ pps : 5 ,
462+ resizeGhostEndPx : 4200 ,
463+ } ) ,
464+ ) . toBe ( 4200 ) ;
465+ } ) ;
466+
467+ it ( "keeps long content authoritative" , ( ) => {
468+ expect (
469+ getTimelineDisplayContentWidth ( { trackContentWidth : 9000 , viewportWidth : 400 , pps : 50 } ) ,
470+ ) . toBe ( 9000 ) ;
471+ } ) ;
472+ } ) ;
473+
393474describe ( "getTimelineScrollLeftForZoomTransition" , ( ) => {
394475 it ( "resets horizontal scroll when switching from manual zoom back to fit" , ( ) => {
395476 expect ( getTimelineScrollLeftForZoomTransition ( "manual" , "fit" , 480 ) ) . toBe ( 0 ) ;
@@ -524,7 +605,9 @@ describe("resolveTimelineAssetDrop", () => {
524605 trackOrder : [ 0 , 3 , 7 ] ,
525606 } ,
526607 432 ,
527- 310 ,
608+ // clientY updated for TRACKS_TOP_PAD=72: rectTop(200) + RULER_H(24) +
609+ // TRACKS_TOP_PAD(72) + TRACK_H(48) + TRACK_H/2(24) = 368 → row 1 → track 3.
610+ 368 ,
528611 ) ,
529612 ) . toEqual ( { start : 3 , track : 3 } ) ;
530613 } ) ;
0 commit comments