diff --git a/packages/studio/tests/e2e/edit-accuracy/case.mjs b/packages/studio/tests/e2e/edit-accuracy/case.mjs index 7f1321d89d..6ddb20ed16 100644 --- a/packages/studio/tests/e2e/edit-accuracy/case.mjs +++ b/packages/studio/tests/e2e/edit-accuracy/case.mjs @@ -719,9 +719,15 @@ async function waitingQuad(page, map) { } /** The box as the preview shows it: the waiting marker's quad while a press waits for its replay, else the element. */ -export async function measureShown(ctx, gesture, read = measure, quadOf = contentQuad) { +export async function measureShown( + ctx, + gesture, + read = measure, + quadOf = contentQuad, + pointerMoved = true, +) { for (;;) { - const waiting = await ctx.page.$("[data-dom-edit-press-waiting]"); + const waiting = pointerMoved ? await ctx.page.$("[data-dom-edit-press-waiting]") : null; try { const m = await read(ctx); if (gesture === "crop") m.outline = await cropOutline(ctx, m.map); @@ -740,8 +746,8 @@ export async function measureShown(ctx, gesture, read = measure, quadOf = conten } } -export async function sample(ctx, gesture, point, pointerScreen) { - const { m, actual } = await measureShown(ctx, gesture); +export async function sample(ctx, gesture, point, pointerScreen, pointerMoved = true) { + const { m, actual } = await measureShown(ctx, gesture, measure, contentQuad, pointerMoved); return { m, actual, p: point(m), c: m.map.toComp(pointerScreen) }; } @@ -929,7 +935,7 @@ export async function pointerGesture(ctx, gesture, pre, route) { traceBench("press", { gesture }); await ctx.page.mouse.down(); await nextFrame(ctx.page); - const s0 = await sample(ctx, gesture, g.point, press); + const s0 = await sample(ctx, gesture, g.point, press, false); traceBench("pressed", { gesture, jump: pre && quadDistance(s0.m.visible, pre.visible) }); await recording(ctx.page, true); const errors = []; diff --git a/packages/studio/tests/e2e/edit-accuracy/settle.test.mjs b/packages/studio/tests/e2e/edit-accuracy/settle.test.mjs index bf241e61ed..4d9e64f0f1 100644 --- a/packages/studio/tests/e2e/edit-accuracy/settle.test.mjs +++ b/packages/studio/tests/e2e/edit-accuracy/settle.test.mjs @@ -277,6 +277,18 @@ describe("the box a press is measured against", () => { expect(shown.actual[0][0]).toBe(0); }); + // fails without the fix: the press itself read the waiting outline, so a sealed press jumped 0.2 px. + it("reads the element at the press, before the pointer moves", async () => { + const shown = await measureShown( + { page: page([marker([true])]) }, + "move", + read, + async () => quad(260), + false, + ); + expect(shown.m.visible[0][0]).toBe(0); + }); + it("reads the element when nothing waits", async () => { const shown = await measureShown({ page: page([]) }, "move", read, async () => quad(260)); expect(shown.m.visible[0][0]).toBe(0); diff --git a/packages/studio/tests/e2e/edit-accuracy/teleport.mjs b/packages/studio/tests/e2e/edit-accuracy/teleport.mjs index edf1c9cc9f..cfee5b0a3b 100644 --- a/packages/studio/tests/e2e/edit-accuracy/teleport.mjs +++ b/packages/studio/tests/e2e/edit-accuracy/teleport.mjs @@ -444,12 +444,23 @@ function trackers(gesture, first, p0) { const round = (v) => Math.round(v * 100) / 100; +/** A waiting box follows the pointer once it moves; until then it is Studio's resting outline: the element is read. */ +function untilPointerMoves(frames) { + const [x, y] = frames[0]?.pointer ?? []; + const moved = frames.findIndex((f) => f.pointer[0] !== x || f.pointer[1] !== y); + return frames.map((f, i) => + f.waitingQuad && (moved < 0 || i < moved) ? { ...f, waitingQuad: undefined } : f, + ); +} + /** Fails a frame whose tracked point outran the pointer or left its path; after release, the release point. */ // fallow-ignore-next-line complexity export function scoreTeleport(gesture, samples) { - const frames = samples - .filter((s) => s.quad && s.root && s.pointer) - .map((s) => ({ ...s, map: compositionMapper(s.root, COMPOSITION) })); + const frames = untilPointerMoves( + samples + .filter((s) => s.quad && s.root && s.pointer) + .map((s) => ({ ...s, map: compositionMapper(s.root, COMPOSITION) })), + ); if (frames.length < 2) { const count = (f) => samples.filter(f).length; const failed = samples.find((s) => s.error)?.error; diff --git a/packages/studio/tests/e2e/edit-accuracy/teleport.test.mjs b/packages/studio/tests/e2e/edit-accuracy/teleport.test.mjs index 05519dbb16..65d5d73ff4 100644 --- a/packages/studio/tests/e2e/edit-accuracy/teleport.test.mjs +++ b/packages/studio/tests/e2e/edit-accuracy/teleport.test.mjs @@ -42,6 +42,11 @@ describe("scoreTeleport", () => { pass: true, }); }); + // fails without the fix: a sealed press anchored on Studio's outline, which sits off the element in both modes. + it("scores a press that waits with the pointer still like one that never waited", () => { + const sealed = drag.map((f, i) => (i < 2 ? { ...f, waitingQuad: box(0.2) } : f)); + expect(scoreTeleport("move", sealed).max).toBe(scoreTeleport("move", drag).max); + }); it("rejects a jumping outline while the element waits", () => { const jumped = waitingDrag.map((f, i) => (i === 4 ? { ...f, waitingQuad: box(f.t + 37) } : f)); expect(scoreTeleport("move", [...jumped, frame(50, false)]).pass).toBe(false);