mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-16 14:27:26 +00:00
* test(studio): score edits on GSAP-animated size, scale, rotation, keyframes and from/fromTo * test(studio): settle the edit bench only once no shadow preview is waiting to be swapped in * test(studio): end a drag at its recorded pointer-up, even when no frame painted while held * ci(studio): run the keyframed edit accuracy cases in CI across 20 shards * refactor(studio): split the keyframe render and stray-css checks into small helpers * test(studio): bank the edit bench's smooth verdict as smooth, judged on the worst frame's work * style(studio): name the edit gate's smooth count helper * test(studio): count smooth edit cases only among the accurate ones * test(studio): only keyframed cases wait for the preview swap, so others keep main's undo timing * refactor(studio): keep the edit bench's keyframe check apart from the hidden preview scan * test(studio): check the keyframed cases are in the full grid without pinning its size * test(studio): quarantine the nudge sequence whose redo waits behind preview videos (#4889) * test(studio): bank the 255 keyframed edit cases that pass
93 lines
4.1 KiB
JavaScript
93 lines
4.1 KiB
JavaScript
import { mkdtempSync, readFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import { keyframeDrift, strayCss } from "./case.mjs";
|
|
import { buildGrid, writeFixture } from "./grid.mjs";
|
|
import { accurate } from "./ratchet.mjs";
|
|
|
|
const at = (values) => ({ values });
|
|
|
|
describe("keyframeDrift", () => {
|
|
it("passes when every other keyframe reads back its value, and names the one that moved", () => {
|
|
const before = { 0: at({ width: 240 }), 3: at({ width: 360 }) };
|
|
expect(keyframeDrift(before, before)).toMatchObject({ pass: true, diff: 0 });
|
|
const r = keyframeDrift(before, { 0: at({ width: 240 }), 3: at({ width: 372 }) });
|
|
expect(r).toMatchObject({ pass: false, diff: 12, time: 3, prop: "width" });
|
|
});
|
|
|
|
it("fails a value it could not read", () => {
|
|
const before = { 0: at({ x: 0 }) };
|
|
expect(keyframeDrift(before, { 0: at({ x: Number.NaN }) }).pass).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("strayCss", () => {
|
|
const file = (rule, inline = "") =>
|
|
`<style>#target { position: absolute; ${rule} }</style><div ${inline}id="target" class="clip"></div>`;
|
|
const original = { "index.html": file("left: 560px; width: 240px;") };
|
|
|
|
it("allows plain CSS on a property nothing animates", () => {
|
|
const saved = { "index.html": file("left: 600px; width: 240px;") };
|
|
expect(strayCss(original, saved, ["width"])).toMatchObject({ pass: true });
|
|
});
|
|
|
|
it("catches an animated property written as plain CSS, in the rule or inline", () => {
|
|
const rule = { "index.html": file("left: 560px; width: 260px;") };
|
|
expect(strayCss(original, rule, ["width"]).stray).toEqual([
|
|
"index.html rule width: 240px -> 260px",
|
|
]);
|
|
const inline = { "index.html": file("left: 560px; width: 240px;", 'style="width: 260px" ') };
|
|
expect(strayCss(original, inline, ["width"]).stray).toEqual([
|
|
"index.html inline width: - -> 260px",
|
|
]);
|
|
});
|
|
});
|
|
|
|
describe("the keyframed grid", () => {
|
|
const grid = buildGrid("keyframes");
|
|
|
|
it("crosses 5 variants, 5 gestures and 2 playheads with rotation, nesting and zoom", () => {
|
|
expect(grid).toHaveLength(5 * 5 * 2 * 2 * 3 * 2);
|
|
expect(new Set(grid.map((c) => c.id)).size).toBe(grid.length);
|
|
expect(new Set(grid.map((c) => c.gsap))).toEqual(
|
|
new Set(["size", "scale", "spin", "keys", "fromto"]),
|
|
);
|
|
const on = grid.find((c) => c.id === "resize-keys-px-r0-root-z100-on");
|
|
expect(on).toMatchObject({ playhead: 2, keys: { times: [0, 3], render: 3 } });
|
|
expect(grid.find((c) => c.id === "resize-keys-px-r0-root-z100-mid").keys.times).toEqual([
|
|
0, 2, 3,
|
|
]);
|
|
});
|
|
|
|
it("writes each variant's timeline into the file that holds the target", () => {
|
|
const spec = grid.find((c) => c.id === "move-fromto-px-r30-nested-z100-on");
|
|
const dir = mkdtempSync(join(tmpdir(), "edit-bench-keys-"));
|
|
writeFixture(spec, dir);
|
|
const sub = readFileSync(join(dir, "compositions/sub.html"), "utf8");
|
|
expect(sub).toContain('tl.from("#target", { x: -60, duration: 2, ease: "none" }, 0);');
|
|
expect(sub).toContain(
|
|
'tl.fromTo("#target", { x: 0 }, { x: 60, duration: 1, ease: "none" }, 2);',
|
|
);
|
|
});
|
|
|
|
it("runs in the full grid beside the cases already there", () => {
|
|
const full = buildGrid("full").map((c) => c.id);
|
|
expect(full).toEqual(expect.arrayContaining(grid.map((c) => c.id)));
|
|
expect(full.length).toBeGreaterThan(grid.length);
|
|
expect(new Set(full).size).toBe(full.length);
|
|
});
|
|
});
|
|
|
|
describe("the gate on keyframed cases", () => {
|
|
const good = { tracking: 0, drop: 0, reload: 0, render: 0, undo: true };
|
|
it("fails a moved keyframe, stray CSS, a far render or an unmeasured one, and ignores old entries", () => {
|
|
expect(accurate({ ...good, keys: true, css: true, renderKey: 0.1 })).toBe(true);
|
|
expect(accurate({ ...good, keys: false, css: true, renderKey: 0.1 })).toBe(false);
|
|
expect(accurate({ ...good, keys: true, css: false, renderKey: 0.1 })).toBe(false);
|
|
expect(accurate({ ...good, keys: true, css: true, renderKey: 0.6 })).toBe(false);
|
|
expect(accurate({ ...good, keys: true, css: true, renderKey: null })).toBe(false);
|
|
expect(accurate(good)).toBe(true);
|
|
});
|
|
});
|