Skip to content

Commit 1aa0fdb

Browse files
committed
test(studio): pin which tween a resize edits when the element has several
A composition animates the same property more than once — a scale-in early, a scale-out late — and the one the user means is the one under the playhead. Editing the wrong one changes a moment they are not looking at and leaves the moment they are looking at unchanged, which reads as "the resize did nothing". Six playheads across two scale tweens, including both sides of the midpoint between them and a time past the end of both. Verified against a stubbed selection that always takes the first tween: three of the six fail.
1 parent 84e5b01 commit 1aa0fdb

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

‎packages/studio/src/hooks/gsapResizeSweep.test.ts‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,63 @@ it(`sweeps ${CASES.length} animated shapes without a stale id or a mixed tween`,
212212

213213
expect(failures).toEqual([]);
214214
});
215+
216+
/**
217+
* Which tween a resize edits when the element has several in the same group.
218+
*
219+
* A composition animates the same property more than once — a scale-in early
220+
* and a scale-out late — and the one the user means is the one under the
221+
* playhead. Editing the wrong one changes a moment they are not looking at and
222+
* leaves the moment they ARE looking at unchanged, which reads as "the resize
223+
* did nothing".
224+
*/
225+
function scaleAt(id: string, position: number): GsapAnimation {
226+
return {
227+
...tween(id, { scale: 1 }, 2),
228+
position,
229+
resolvedStart: position,
230+
keyframes: {
231+
keyframes: [
232+
{ percentage: 0, properties: { scale: 1 } },
233+
{ percentage: 100, properties: { scale: 1.4 } },
234+
],
235+
},
236+
} as unknown as GsapAnimation;
237+
}
238+
239+
const PLAYHEADS: Array<[number, string]> = [
240+
[0.5, "#el-early"],
241+
[1.9, "#el-early"],
242+
[3, "#el-early"],
243+
[3.1, "#el-late"],
244+
[4.5, "#el-late"],
245+
[9, "#el-late"],
246+
];
247+
248+
it.each(PLAYHEADS)("at t=%s edits the tween under the playhead (%s)", async (time, expected) => {
249+
document.body.innerHTML = "";
250+
const el = document.createElement("div");
251+
el.id = "el";
252+
el.setAttribute("data-hf-studio-original-box-width", "630");
253+
el.setAttribute("data-hf-studio-original-box-height", "408");
254+
document.body.append(el);
255+
usePlayerStore.setState({ currentTime: time, activeKeyframePct: null });
256+
257+
const animations = [scaleAt("#el-early", 0), scaleAt("#el-late", 4)];
258+
const commitMutation = vi.fn();
259+
await tryGsapResizeIntercept(
260+
{ id: "el", selector: "#el", element: el } as DomEditSelection,
261+
{ width: 326, height: 213 },
262+
animations,
263+
null,
264+
commitMutation as never,
265+
async () => animations,
266+
);
267+
268+
const touched = new Set(
269+
commitMutation.mock.calls
270+
.map((call) => (call[1] as { animationId?: string }).animationId)
271+
.filter((id): id is string => id != null),
272+
);
273+
expect([...touched]).toEqual([expected]);
274+
});

0 commit comments

Comments
 (0)