@@ -3,6 +3,9 @@ import { act } from "react";
33import { describe , expect , it , vi } from "vitest" ;
44import { createHappyDomRootHarness } from "./testRootHarness" ;
55import { ClipPeakMarks } from "./ClipPeakMarks" ;
6+ import { TimelineClip } from "./TimelineClip" ;
7+
8+ Object . defineProperty ( globalThis , "IS_REACT_ACT_ENVIRONMENT" , { configurable : true , value : true } ) ;
69
710const harness = createHappyDomRootHarness ( ) ;
811
@@ -13,29 +16,70 @@ async function render(url: string, bins: number[], gain: number) {
1316 ) ;
1417 const host = document . createElement ( "div" ) ;
1518 document . body . appendChild ( host ) ;
16- await act ( async ( ) => {
17- harness . mount ( host ) . render (
18- < ClipPeakMarks peaksUrl = { url } sourceWindow = { { mediaStart : 0 , sourceSpan : 2 } } gain = { gain } >
19+ const root = harness . mount ( host ) ;
20+ const view = ( volume : number ) => (
21+ < TimelineClip
22+ el = { { id : "audio" , tag : "audio" , start : 0 , duration : 2 , track : 0 } }
23+ pps = { 16 }
24+ clipY = { 0 }
25+ isSelected = { false }
26+ isHovered = { false }
27+ hasCustomContent
28+ capabilities = { { canMove : true , canTrimStart : true , canTrimEnd : true } }
29+ isComposition = { false }
30+ tabIndex = { 0 }
31+ onHoverStart = { ( ) => { } }
32+ onHoverEnd = { ( ) => { } }
33+ onClick = { ( ) => { } }
34+ onDoubleClick = { ( ) => { } }
35+ >
36+ < ClipPeakMarks peaksUrl = { url } sourceWindow = { { mediaStart : 0 , sourceSpan : 2 } } gain = { volume } >
1937 < span > wave</ span >
20- </ ClipPeakMarks > ,
21- ) ;
22- } ) ;
38+ </ ClipPeakMarks >
39+ </ TimelineClip >
40+ ) ;
41+ await act ( async ( ) => root . render ( view ( gain ) ) ) ;
2342 await act ( async ( ) => { } ) ;
2443 vi . unstubAllGlobals ( ) ;
25- return host ;
44+ return { host, setGain : async ( value : number ) => act ( async ( ) => root . render ( view ( value ) ) ) } ;
2645}
2746
2847describe ( "ClipPeakMarks" , ( ) => {
29- it ( "paints red marks and the peak on a clip that redlines " , async ( ) => {
30- const host = await render ( "/api/projects/p/peaks/loud.mp4" , [ 0.2 , 0.98 ] , 1 ) ;
48+ it ( "uses a plain warning and describes the focused clip with the numeric peak " , async ( ) => {
49+ const { host } = await render ( "/api/projects/p/peaks/loud.mp4" , [ 0.2 , 0.98 ] , 1 ) ;
3150 expect ( host . textContent ) . toContain ( "wave" ) ;
3251 expect ( host . querySelector ( "[data-testid=clip-peak-marks]" ) ?. textContent ) . toContain (
33- "▲ peaks −0.2 dBFS " ,
52+ "▲ Too loud " ,
3453 ) ;
54+ expect ( host . querySelector ( "[data-peak-text]" ) ?. textContent ) . not . toContain ( "dBFS" ) ;
55+ const clip = host . querySelector ( "button" ) ! ;
56+ await act ( async ( ) => clip . focus ( ) ) ;
57+ await vi . waitFor ( ( ) =>
58+ expect ( document . querySelector ( '[role="tooltip"]' ) ?. textContent ) . toBe (
59+ "Peaks −0.2 dBFS at this volume; export lowers the whole mix" ,
60+ ) ,
61+ ) ;
62+ expect ( clip . getAttribute ( "aria-describedby" ) ) . toBe (
63+ document . querySelector ( '[role="tooltip"]' ) ?. id ,
64+ ) ;
65+ expect ( host . querySelectorAll ( "button" ) ) . toHaveLength ( 1 ) ;
66+ } ) ;
67+
68+ it ( "removes the focused warning when volume becomes quiet without replacing the clip" , async ( ) => {
69+ const { host, setGain } = await render ( "/api/projects/p/peaks/changing.mp4" , [ 1 , 1 ] , 1 ) ;
70+ const clip = host . querySelector ( "button" ) ! ;
71+ await act ( async ( ) => clip . focus ( ) ) ;
72+ await vi . waitFor ( ( ) => expect ( document . querySelector ( '[role="tooltip"]' ) ) . not . toBeNull ( ) ) ;
73+ await setGain ( 0.25 ) ;
74+ await vi . waitFor ( ( ) => expect ( document . querySelector ( '[role="tooltip"]' ) ) . toBeNull ( ) ) ;
75+ expect ( clip . getAttribute ( "aria-describedby" ) ) . toBeNull ( ) ;
76+ expect ( document . activeElement ) . toBe ( clip ) ;
77+ expect ( host . querySelector ( "button" ) ) . toBe ( clip ) ;
78+ expect ( host . querySelector ( "[data-peak-badge]" ) ) . toBeNull ( ) ;
3579 } ) ;
3680
3781 it ( "paints nothing on a quiet clip" , async ( ) => {
38- const host = await render ( "/api/projects/p/peaks/quiet.mp4" , [ 0.25 , 0.25 ] , 1 ) ;
82+ const { host } = await render ( "/api/projects/p/peaks/quiet.mp4" , [ 0.25 , 0.25 ] , 1 ) ;
3983 expect ( host . querySelector ( "[data-testid=clip-peak-marks]" ) ) . toBeNull ( ) ;
4084 } ) ;
4185} ) ;
0 commit comments