Files
plan2code/scripts/test-web-console-page-layout.mjs
T

94 lines
4.8 KiB
JavaScript
Raw Normal View History

// Page tests for the page shell: what keeps the console page itself from
// scrolling (only its panels scroll), checked at wide and narrow window sizes.
// A change to src/web-console/public/styles/ or index.html needs only this
// file, not the whole page suites. Run with:
// npm run test:page -- scripts/test-web-console-page-layout.mjs
//
// Each test drives the real console in a real Chrome or Edge through
// scripts/page-test-helpers.mjs: one browser for the file, a fresh console
// session per test.
import test from "node:test";
import assert from "node:assert/strict";
import { pageSuite, openSession } from "./page-test-helpers.mjs";
const suite = pageSuite(test);
// A plan session on the person's turn: one text question and the agent listening.
const PLAN_QUESTION = {
items: [{ id: "q1", kind: "text", title: "What to call it", body: "A short name for the export." }],
agent: { status: "waiting" },
};
test("the page itself never scrolls: oversized content stays inside its own panel", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
await s.page.locator("#main [data-item=\"q1\"]").first().waitFor();
const page = await s.page.evaluate(() => {
const big = document.createElement("div");
big.style.cssText = "height: 5000px";
document.querySelector(".main").append(big);
const root = document.documentElement;
const before = { scrollHeight: root.scrollHeight, innerHeight: innerHeight };
scrollTo(0, 400);
return {
...before,
scrolled: scrollY,
rootOverflow: getComputedStyle(root).overflowY,
bodyOverflow: getComputedStyle(document.body).overflowY,
bodyHeight: Math.round(document.body.getBoundingClientRect().height),
};
});
assert.equal(page.rootOverflow, "hidden", "the page root never scrolls");
assert.equal(page.bodyOverflow, "hidden", "the body never scrolls");
assert.equal(page.bodyHeight, page.innerHeight, "the body is exactly the window tall");
assert.ok(page.scrollHeight <= page.innerHeight, "the page is never taller than the window (an absolutely placed bit in a panel stretched it)");
assert.equal(page.scrolled, 0, "the page does not move when asked to scroll");
});
test("the one-column layout (900px and narrower) keeps its page scroll", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
await s.page.setViewportSize({ width: 600, height: 700 });
const narrow = await s.page.evaluate(() => getComputedStyle(document.documentElement).overflowY);
assert.equal(narrow, "visible", "its content sits under the first screen, so the lock must not apply");
});
test("a stacked Notes panel has a handle that drags its height, keeps it and resets on double-click", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION });
await s.page.setViewportSize({ width: 1000, height: 700 });
await s.page.locator("#main [data-item=\"q1\"]").first().waitFor();
const grip = s.page.locator("#aside .aside-grip");
await grip.waitFor();
const asideHeight = async () => Math.round((await s.page.locator("#aside").boundingBox()).height);
const auto = await asideHeight();
const drag = async (dy) => {
const box = await grip.boundingBox();
const x = box.x + box.width / 2;
const y = box.y + box.height / 2;
await s.page.mouse.move(x, y);
await s.page.mouse.down();
await s.page.mouse.move(x, y + dy / 2, { steps: 4 });
await s.page.mouse.move(x, y + dy, { steps: 4 });
await s.page.mouse.up();
};
await drag(-120);
const taller = await asideHeight();
assert.ok(taller >= auto + 100, `dragging the handle up makes the panel taller (${auto} -> ${taller})`);
await s.page.waitForFunction((h) => Number(document.querySelector("#aside .aside-grip").getAttribute("aria-valuenow")) === h, taller);
await drag(60);
const shorter = await asideHeight();
assert.ok(shorter <= taller - 40 && shorter >= 96, `dragging it down makes the panel shorter (${taller} -> ${shorter})`);
// Kept with the saved looks, so the next session opens at this height.
const saved = async () => s.page.evaluate(async () => (await (await fetch("/looks")).json()).looks?.asideHeight);
await s.page.waitForFunction(async (h) => (await (await fetch("/looks")).json()).looks?.asideHeight === h, shorter);
assert.equal(await saved(), shorter, "the height is kept in the saved looks");
await grip.dblclick();
assert.equal(await asideHeight(), auto, "a double-click goes back to the automatic height");
assert.equal(await s.page.evaluate(() => document.documentElement.hasAttribute("data-aside-h")), false);
await s.page.setViewportSize({ width: 1400, height: 700 });
assert.equal(await grip.isVisible(), false, "side by side, the panel has no handle");
});