@@ -5,11 +5,16 @@ import { createRoot } from "react-dom/client";
55import { afterEach , describe , expect , it , vi } from "vitest" ;
66import { AnimationCard } from "./AnimationCard" ;
77import type { GsapAnimation } from "@hyperframes/core/gsap-parser" ;
8+ import { EASE_PRESETS } from "./easePresetLibrary" ;
9+
10+ const trackStudioSegmentEaseEdit = vi . hoisted ( ( ) => vi . fn ( ) ) ;
11+ vi . mock ( "../../telemetry/events" , ( ) => ( { trackStudioSegmentEaseEdit } ) ) ;
812
913( globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT : boolean } ) . IS_REACT_ACT_ENVIRONMENT = true ;
1014
1115afterEach ( ( ) => {
1216 document . body . innerHTML = "" ;
17+ trackStudioSegmentEaseEdit . mockClear ( ) ;
1318} ) ;
1419
1520function baseAnimation ( overrides : Partial < GsapAnimation > = { } ) : GsapAnimation {
@@ -26,6 +31,101 @@ function baseAnimation(overrides: Partial<GsapAnimation> = {}): GsapAnimation {
2631
2732const noop = ( ) => { } ;
2833
34+ function selectPreset ( host : HTMLElement , presetId : string ) : string {
35+ const presetConfig = EASE_PRESETS . find ( ( candidate ) => candidate . id === presetId ) ;
36+ if ( ! presetConfig ) throw new Error ( `Missing ease preset: ${ presetId } ` ) ;
37+
38+ const dropdown = host . querySelector < HTMLButtonElement > ( "[data-ease-type-dropdown]" ) ;
39+ expect ( dropdown ) . not . toBeNull ( ) ;
40+ act ( ( ) => dropdown ?. click ( ) ) ;
41+
42+ const preset = host . querySelector < HTMLButtonElement > ( `[data-ease-preset-id="${ presetId } "]` ) ;
43+ expect ( preset ) . not . toBeNull ( ) ;
44+ act ( ( ) => preset ?. click ( ) ) ;
45+ return presetConfig . ease ;
46+ }
47+
48+ function renderExpandedCard ( {
49+ animation,
50+ flat,
51+ onUpdateMeta = vi . fn ( ) ,
52+ onUpdateKeyframeEase = vi . fn ( ) ,
53+ } : {
54+ animation : GsapAnimation ;
55+ flat ?: boolean ;
56+ onUpdateMeta ?: ReturnType < typeof vi . fn > ;
57+ onUpdateKeyframeEase ?: ReturnType < typeof vi . fn > ;
58+ } ) {
59+ const host = document . createElement ( "div" ) ;
60+ document . body . append ( host ) ;
61+ const root = createRoot ( host ) ;
62+ act ( ( ) => {
63+ root . render (
64+ < AnimationCard
65+ animation = { animation }
66+ defaultExpanded
67+ flat = { flat }
68+ onUpdateProperty = { noop }
69+ onUpdateMeta = { onUpdateMeta }
70+ onDeleteAnimation = { noop }
71+ onAddProperty = { noop }
72+ onRemoveProperty = { noop }
73+ onUpdateKeyframeEase = { onUpdateKeyframeEase }
74+ /> ,
75+ ) ;
76+ } ) ;
77+ return { host, root } ;
78+ }
79+
80+ describe ( "AnimationCard ease editing" , ( ) => {
81+ it ( "commits one preset change to the selected keyframe segment" , ( ) => {
82+ const onUpdateKeyframeEase = vi . fn ( ) ;
83+ const animation = baseAnimation ( {
84+ keyframes : {
85+ format : "percentage" ,
86+ keyframes : [
87+ { percentage : 0 , properties : { opacity : 0 } } ,
88+ { percentage : 50 , properties : { opacity : 0.5 } } ,
89+ { percentage : 100 , properties : { opacity : 1 } } ,
90+ ] ,
91+ } ,
92+ } ) ;
93+ const view = renderExpandedCard ( { animation, onUpdateKeyframeEase } ) ;
94+
95+ const segment = Array . from ( view . host . querySelectorAll ( "button" ) ) . find ( ( button ) =>
96+ button . textContent ?. includes ( "0% → 50%" ) ,
97+ ) ;
98+ expect ( segment ) . toBeDefined ( ) ;
99+ act ( ( ) => segment ?. click ( ) ) ;
100+ const ease = selectPreset ( view . host , "quad-out" ) ;
101+
102+ expect ( onUpdateKeyframeEase ) . toHaveBeenCalledExactlyOnceWith ( animation . id , 50 , ease ) ;
103+ expect ( trackStudioSegmentEaseEdit ) . toHaveBeenCalledExactlyOnceWith ( {
104+ ease,
105+ } ) ;
106+ act ( ( ) => view . root . unmount ( ) ) ;
107+ } ) ;
108+
109+ it ( "commits one preset change through flat tween metadata" , ( ) => {
110+ const onUpdateMeta = vi . fn ( ) ;
111+ const onUpdateKeyframeEase = vi . fn ( ) ;
112+ const animation = baseAnimation ( { id : "flat-tween" } ) ;
113+ const view = renderExpandedCard ( {
114+ animation,
115+ flat : true ,
116+ onUpdateMeta,
117+ onUpdateKeyframeEase,
118+ } ) ;
119+
120+ const ease = selectPreset ( view . host , "quad-out" ) ;
121+
122+ expect ( onUpdateMeta ) . toHaveBeenCalledExactlyOnceWith ( animation . id , { ease } ) ;
123+ expect ( onUpdateKeyframeEase ) . not . toHaveBeenCalled ( ) ;
124+ expect ( trackStudioSegmentEaseEdit ) . not . toHaveBeenCalled ( ) ;
125+ act ( ( ) => view . root . unmount ( ) ) ;
126+ } ) ;
127+ } ) ;
128+
29129describe ( "AnimationCard flat branch" , ( ) => {
30130 it ( "renders a mint border-left and panel-token colors when flat" , ( ) => {
31131 const host = document . createElement ( "div" ) ;
0 commit comments