@@ -48,20 +48,20 @@ describe("validateOp — no gsap.timeline() declaration", () => {
4848 return parseMutable ( makeHtml ( NO_TIMELINE_SCRIPT ) ) ;
4949 }
5050
51- it ( "addGsapTween → false when script has no timeline" , ( ) => {
52- expect (
53- validateOp ( freshNoTimeline ( ) , {
54- type : "addGsapTween " ,
55- target : "hf-box" ,
56- tween : { method : "to" , properties : { x : 100 } } ,
57- } ) ,
58- ) . toBe ( false ) ;
51+ it ( "addGsapTween → ok: false / E_NO_GSAP_TIMELINE when script has no timeline" , ( ) => {
52+ const r = validateOp ( freshNoTimeline ( ) , {
53+ type : "addGsapTween" ,
54+ target : "hf-box " ,
55+ tween : { method : "to" , properties : { x : 100 } } ,
56+ } ) ;
57+ expect ( r . ok ) . toBe ( false ) ;
58+ if ( ! r . ok ) expect ( r . code ) . toBe ( "E_NO_GSAP_TIMELINE" ) ;
5959 } ) ;
6060
61- it ( "addLabel → false when script has no timeline" , ( ) => {
62- expect ( validateOp ( freshNoTimeline ( ) , { type : "addLabel" , name : "start" , position : 0 } ) ) . toBe (
63- false ,
64- ) ;
61+ it ( "addLabel → ok: false / E_NO_GSAP_TIMELINE when script has no timeline" , ( ) => {
62+ const r = validateOp ( freshNoTimeline ( ) , { type : "addLabel" , name : "start" , position : 0 } ) ;
63+ expect ( r . ok ) . toBe ( false ) ;
64+ if ( ! r . ok ) expect ( r . code ) . toBe ( "E_NO_GSAP_TIMELINE" ) ;
6565 } ) ;
6666
6767 it ( "addGsapTween dispatch returns EMPTY when no timeline — no dangling tl call emitted" , ( ) => {
@@ -80,22 +80,22 @@ describe("validateOp — no gsap.timeline() declaration", () => {
8080// ─── validateOp returns true when GSAP script present ─────────────────────────
8181
8282describe ( "validateOp with GSAP script" , ( ) => {
83- it ( "addGsapTween → true" , ( ) => {
83+ it ( "addGsapTween → ok: true" , ( ) => {
8484 expect (
8585 validateOp ( fresh ( ) , {
8686 type : "addGsapTween" ,
8787 target : "hf-box" ,
8888 tween : { method : "to" , duration : 0.3 , properties : { x : 100 } } ,
89- } ) ,
89+ } ) . ok ,
9090 ) . toBe ( true ) ;
9191 } ) ;
9292
93- it ( "removeGsapTween → true" , ( ) => {
94- expect ( validateOp ( fresh ( ) , { type : "removeGsapTween" , animationId : "some-id" } ) ) . toBe ( true ) ;
93+ it ( "removeGsapTween → ok: true" , ( ) => {
94+ expect ( validateOp ( fresh ( ) , { type : "removeGsapTween" , animationId : "some-id" } ) . ok ) . toBe ( true ) ;
9595 } ) ;
9696
97- it ( "addLabel → true" , ( ) => {
98- expect ( validateOp ( fresh ( ) , { type : "addLabel" , name : "start" , position : 0 } ) ) . toBe ( true ) ;
97+ it ( "addLabel → ok: true" , ( ) => {
98+ expect ( validateOp ( fresh ( ) , { type : "addLabel" , name : "start" , position : 0 } ) . ok ) . toBe ( true ) ;
9999 } ) ;
100100} ) ;
101101
@@ -190,15 +190,30 @@ describe("addGsapTween", () => {
190190 } ) ;
191191} ) ;
192192
193+ // ─── Tween op test helpers ────────────────────────────────────────────────────
194+
195+ const TWEEN_ANIM_ID = `[data-hf-id="hf-box"]-to-200-visual` ;
196+
197+ function assertEmptyForUnknownId ( op : Parameters < typeof applyOp > [ 1 ] ) {
198+ const result = applyOp ( fresh ( ) , op ) ;
199+ expect ( result . forward ) . toHaveLength ( 0 ) ;
200+ }
201+
202+ function assertInverseRestoresScript ( op : Parameters < typeof applyOp > [ 1 ] ) {
203+ const parsed = fresh ( ) ;
204+ const original = getScript ( parsed ) ;
205+ applyPatchesToDocument ( parsed , applyOp ( parsed , op ) . inverse ) ;
206+ expect ( getScript ( parsed ) ) . toBe ( original ) ;
207+ }
208+
193209// ─── setGsapTween ─────────────────────────────────────────────────────────────
194210
195211describe ( "setGsapTween" , ( ) => {
196212 it ( "updates ease in existing tween" , ( ) => {
197213 const parsed = fresh ( ) ;
198- const animId = `[data-hf-id="hf-box"]-to-200-visual` ;
199214 const result = applyOp ( parsed , {
200215 type : "setGsapTween" ,
201- animationId : animId ,
216+ animationId : TWEEN_ANIM_ID ,
202217 properties : { ease : "power3.in" } ,
203218 } ) ;
204219 expect ( result . forward ) . toHaveLength ( 1 ) ;
@@ -209,10 +224,9 @@ describe("setGsapTween", () => {
209224
210225 it ( "updates duration in existing tween" , ( ) => {
211226 const parsed = fresh ( ) ;
212- const animId = `[data-hf-id="hf-box"]-to-200-visual` ;
213227 const result = applyOp ( parsed , {
214228 type : "setGsapTween" ,
215- animationId : animId ,
229+ animationId : TWEEN_ANIM_ID ,
216230 properties : { duration : 1.5 } ,
217231 } ) ;
218232 const newScript = String ( result . forward [ 0 ] ?. value ?? "" ) ;
@@ -221,26 +235,19 @@ describe("setGsapTween", () => {
221235 } ) ;
222236
223237 it ( "returns EMPTY for unknown animationId" , ( ) => {
224- const parsed = fresh ( ) ;
225- const result = applyOp ( parsed , {
238+ assertEmptyForUnknownId ( {
226239 type : "setGsapTween" ,
227240 animationId : "nonexistent-id" ,
228241 properties : { ease : "power1.in" } ,
229242 } ) ;
230- expect ( result . forward ) . toHaveLength ( 0 ) ;
231243 } ) ;
232244
233245 it ( "inverse restores original script" , ( ) => {
234- const parsed = fresh ( ) ;
235- const original = getScript ( parsed ) ;
236- const animId = `[data-hf-id="hf-box"]-to-200-visual` ;
237- const result = applyOp ( parsed , {
246+ assertInverseRestoresScript ( {
238247 type : "setGsapTween" ,
239- animationId : animId ,
248+ animationId : TWEEN_ANIM_ID ,
240249 properties : { ease : "power3.in" } ,
241250 } ) ;
242- applyPatchesToDocument ( parsed , result . inverse ) ;
243- expect ( getScript ( parsed ) ) . toBe ( original ) ;
244251 } ) ;
245252} ) ;
246253
@@ -249,26 +256,18 @@ describe("setGsapTween", () => {
249256describe ( "removeGsapTween" , ( ) => {
250257 it ( "removes tween by animationId" , ( ) => {
251258 const parsed = fresh ( ) ;
252- const animId = `[data-hf-id="hf-box"]-to-200-visual` ;
253- const result = applyOp ( parsed , { type : "removeGsapTween" , animationId : animId } ) ;
259+ const result = applyOp ( parsed , { type : "removeGsapTween" , animationId : TWEEN_ANIM_ID } ) ;
254260 expect ( result . forward ) . toHaveLength ( 1 ) ;
255261 const newScript = String ( result . forward [ 0 ] ?. value ?? "" ) ;
256262 expect ( newScript ) . not . toContain ( "opacity: 1" ) ;
257263 } ) ;
258264
259265 it ( "returns EMPTY for unknown animationId" , ( ) => {
260- const parsed = fresh ( ) ;
261- const result = applyOp ( parsed , { type : "removeGsapTween" , animationId : "no-such-id" } ) ;
262- expect ( result . forward ) . toHaveLength ( 0 ) ;
266+ assertEmptyForUnknownId ( { type : "removeGsapTween" , animationId : "no-such-id" } ) ;
263267 } ) ;
264268
265269 it ( "inverse restores original script" , ( ) => {
266- const parsed = fresh ( ) ;
267- const original = getScript ( parsed ) ;
268- const animId = `[data-hf-id="hf-box"]-to-200-visual` ;
269- const result = applyOp ( parsed , { type : "removeGsapTween" , animationId : animId } ) ;
270- applyPatchesToDocument ( parsed , result . inverse ) ;
271- expect ( getScript ( parsed ) ) . toBe ( original ) ;
270+ assertInverseRestoresScript ( { type : "removeGsapTween" , animationId : TWEEN_ANIM_ID } ) ;
272271 } ) ;
273272} ) ;
274273
0 commit comments