Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 28 additions & 14 deletions packages/studio/tests/e2e/edit-accuracy/case.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -710,17 +710,35 @@ function plan(gesture, pre, pressComp) {
};
}

// A press made while the preview reloads waits for it: Studio draws its box at the pointer meanwhile.
async function waitingQuad(page, map) {
const waiting = await page.$("[data-dom-edit-press-waiting]");
const quad = waiting && (await contentQuad(waiting)).map(map.toComp);
await waiting?.dispose();
return quad;
}

const WAITING_BOX = "[data-dom-edit-press-waiting]";
const WAITING_ON_SAVE = `${WAITING_BOX}:not([data-dom-edit-press-waiting="frame"])`;

/** The waiting box's quad while it is still in the page and still waiting, else null: a replay ends the wait and
* may then remount the box. A waiting box in the page with no quad still throws. */
async function liveMarkerQuad(waiting, quadOf) {
let quad;
try {
quad = await quadOf(waiting);
} catch (error) {
if (await waiting.evaluate((e) => e.isConnected)) throw error;
return null;
}
const live = await waiting.evaluate(
(e) => e.isConnected && e.hasAttribute("data-dom-edit-press-waiting"),
);
return live ? quad : null;
}

// A press made while the preview reloads waits for it: Studio draws its box at the pointer meanwhile.
export async function waitingQuad(page, map, quadOf = contentQuad) {
const waiting = await page.$(WAITING_BOX);
try {
return (waiting && (await liveMarkerQuad(waiting, quadOf))?.map(map.toComp)) ?? null;
} finally {
await waiting?.dispose();
}
}

/** 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,
Expand All @@ -734,14 +752,10 @@ export async function measureShown(
try {
const m = await read(ctx);
if (gesture === "crop") m.outline = await cropOutline(ctx, m.map);
const quad = waiting && (await quadOf(waiting)).map(m.map.toComp);
const quad = waiting && (await liveMarkerQuad(waiting, quadOf))?.map(m.map.toComp);
// Replay removes the marker before moving the element. Do not combine a pre-replay
// element read with a post-replay marker read into a position nobody displayed.
if (
waiting &&
!(await waiting.evaluate((e) => e.hasAttribute("data-dom-edit-press-waiting")))
)
continue;
if (waiting && !quad) continue;
return { m: quad ? { ...m, quad, visible: quad } : m, actual: m.visible };
} finally {
await waiting?.dispose();
Expand Down
55 changes: 55 additions & 0 deletions packages/studio/tests/e2e/edit-accuracy/settle.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
seekBound,
swapPending,
unsettledBy,
waitingQuad,
} from "./case.mjs";
import { heldSize, keyedBy, restedFor, shownOnceRested } from "./sequences.mjs";

Expand Down Expand Up @@ -313,6 +314,60 @@ describe("the box a press is measured against", () => {
);
expect(shown.m.visible[0][0]).toBe(0);
});

// fails without the fix: a sealed fast-keys drag threw "element has no rendered box" when Studio
// remounted the selection box right after the replay, before the marker's box was read.
it("reads again when Studio took the waiting box out of the page before its box was read", async () => {
const gone = async () => {
throw new Error("element has no rendered box");
};
const shown = await measureShown({ page: page([marker([false])]) }, "move", read, gone);
expect(shown.m.visible[0][0]).toBe(0);
});

it("still fails when a waiting box in the page has no box", async () => {
const empty = async () => {
throw new Error("element has no rendered box");
};
await expect(
measureShown({ page: page([marker([true])]) }, "move", read, empty),
).rejects.toThrow("element has no rendered box");
});

// The box as each read finds it: Studio's own check runs on it, in the page or out of it.
const box = (...states) => ({
evaluate: async (check) => {
const [isConnected, waiting] = states.shift() ?? [false, false];
return check({ isConnected, hasAttribute: () => waiting });
},
dispose: async () => {},
});
const gone = async () => {
throw new Error("element has no rendered box");
};
const map = { toComp: (p) => p };

it("does not take the quad of a box that left the page, still marked waiting, after it was read", async () => {
const shown = await measureShown({ page: page([box([false, true])]) }, "move", read, async () =>
quad(260),
);
expect(shown.m.visible[0][0]).toBe(0);
});

// fails without the fix: the read before the press threw when Studio remounted the waiting box first.
it("before the press, a waiting box that left the page is no waiting box", async () => {
expect(await waitingQuad(page([box([false, false])]), map, gone)).toBeNull();
expect(await waitingQuad(page([box([false, true])]), map, async () => quad(260))).toBeNull();
});

it("before the press, a waiting box in the page gives its quad, or fails when it has none", async () => {
expect((await waitingQuad(page([box([true, true])]), map, async () => quad(260)))[0][0]).toBe(
260,
);
await expect(waitingQuad(page([box([true, true])]), map, gone)).rejects.toThrow(
"element has no rendered box",
);
});
});

// fails without the fix: the sequence read the file once its write count was met, while a sealed press that waited for
Expand Down
Loading