Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

test(web): wait for the rail to settle before measuring it (7.16)

lmlihengab04ae9cd964
diff --git a/packages/web/e2e/company-rail-hints.spec.mjs b/packages/web/e2e/company-rail-hints.spec.mjs
index b54d0c66..2c271481 100644
--- a/packages/web/e2e/company-rail-hints.spec.mjs
+++ b/packages/web/e2e/company-rail-hints.spec.mjs
@@ -27,6 +27,7 @@
*/
import { test, expect, request } from "@playwright/test";
import { ADMIN_ID, ADMIN_PASSWORD, login, provisionAndLogin } from "./auth.mjs";
+import { collapseRail } from "./rail.mjs";
const BASE = process.env.BASE_URL;
const MOCK = process.env.MOCK_URL;
@@ -108,20 +109,11 @@ async function switchToCompany(page) {
}
/**
- * Fold the sidebar to its 48 px rail and wait for the fold to finish: the width animates, and a
- * box measured mid-fold still reports the expanded sidebar's edge (the panel is placed from the
- * row's own box, so only the rail-edge assertion would be wrong — but quietly).
+ * What the panel was placed with, read off the element the layer portaled to the body. The fold
+ * itself lives in `rail.mjs`, beside the numbers that say why the settled column — not merely
+ * "narrower than the expanded sidebar" — is what a rail-edge assertion has to measure; this spec
+ * reached that conclusion first, and `tooltip-beside` later caught a mid-fold edge once.
*/
-async function collapseRail(page) {
- await page.getByRole("button", { name: "收起侧栏" }).click();
- await expect
- .poll(() =>
- page.evaluate(() => document.querySelector("aside")?.getBoundingClientRect().right ?? 999),
- )
- .toBeLessThanOrEqual(48.5);
-}
-
-/** What the panel was placed with, read off the element the layer portaled to the body. */
async function readPanel(panel) {
return panel.evaluate((el) => {
const rect = el.getBoundingClientRect();
diff --git a/packages/web/e2e/rail.mjs b/packages/web/e2e/rail.mjs
new file mode 100644
index 00000000..f93d94c7
--- /dev/null
+++ b/packages/web/e2e/rail.mjs
@@ -0,0 +1,33 @@
+/**
+ * Folding the sidebar to its rail, awaited the one way that is right for every spec that then
+ * measures the rail: the width animates, so "narrower than the expanded sidebar" is not the same
+ * as "settled".
+ *
+ * Measured on the real page (`aside.right` sampled every frame after the fold's click): 231.25 →
+ * 178.28 → 132.84 → 101.83 → 81 → 66.98 → 57.72 → **51.97** → 48.91 → 48, the last ~60 ms of it
+ * flat. A wait that stops at the first sample under 80 therefore returns at 66.98 (or, one frame
+ * later, at 51.97 — the value a run of the `tooltip-beside` suite caught), while the page comes
+ * to rest at 48. A hover panel is placed from its trigger's own box, which has long finished
+ * moving at the 32 px icon size, so nothing but the rail-edge assertion goes wrong — and it goes
+ * wrong quietly, as the pixel or two between where the rail was and where it ended up.
+ *
+ * So wait for the settled column instead: a 48 px rail whose separator measures a hair past the
+ * integer (`RAIL_MAX` gives it that hair).
+ */
+import { expect } from "@playwright/test";
+
+/** A settled rail, plus the sub-pixel its separator adds (the collapsed column itself is 48). */
+const RAIL_MAX = 48.5;
+
+export async function collapseRail(page) {
+ await page.getByRole("button", { name: "收起侧栏" }).click();
+ await expect
+ .poll(
+ () =>
+ page.evaluate(() => document.querySelector("aside")?.getBoundingClientRect().right ?? 999),
+ // The fold is ~150 ms; the poll's default is generous next to it, and naming it keeps a
+ // slow machine's single slow frame from being read as "never settled".
+ { timeout: 15_000 },
+ )
+ .toBeLessThanOrEqual(RAIL_MAX);
+}
diff --git a/packages/web/e2e/tooltip-beside.spec.mjs b/packages/web/e2e/tooltip-beside.spec.mjs
index 673bc30f..b48cfbda 100644
--- a/packages/web/e2e/tooltip-beside.spec.mjs
+++ b/packages/web/e2e/tooltip-beside.spec.mjs
@@ -28,6 +28,7 @@ import { mkdtemp, mkdir } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { provisionAndLogin } from "./auth.mjs";
+import { collapseRail } from "./rail.mjs";
const BASE = process.env.BASE_URL;
const MOCK = process.env.MOCK_URL;
@@ -89,14 +90,10 @@ test("a rail entry's hint opens beside the rail, not over it", async ({ page })
await signIn(page);
await page.goto("/agents");
// The pinned sidebar folds to the rail; its own control is the only way there from the UI.
- // The fold animates its width, so the rail has to be measured once it has settled — an entry
- // measured mid-fold still reports the sidebar's width as its rail's.
- await page.getByRole("button", { name: "收起侧栏" }).click();
- await expect
- .poll(() =>
- page.evaluate(() => document.querySelector("aside")?.getBoundingClientRect().right ?? 0),
- )
- .toBeLessThan(80);
+ // The fold animates its width, and `collapseRail` waits for the column it comes to rest at —
+ // a wait for anything narrower than the expanded sidebar returns mid-fold and hands back an
+ // edge the page has already left behind (see `rail.mjs` for the sampled numbers).
+ await collapseRail(page);
const entry = page.getByRole("link", { name: "插件市场" }).first();
await expect(entry).toBeVisible();