mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-17 04:45:33 -08:00
Share the redraw-safe style and scroll helpers across the page tests, use them for every card and pane they read or scroll, and wait for the workspace frame before the session page types @
AI Assisted
This commit is contained in:
1 parent
7d5e78179e
commit
77ddcc048d
5 files changed
+49
-43
No files matched your search
@@ -134,3 +134,38 @@ export const textOf = async (locator) => (await locator.innerText()).trim();
|
|||||||
|
|
||||||
// The scroll offset of the first element matching `selector`.
|
// The scroll offset of the first element matching `selector`.
|
||||||
export const scrollTopOf = (page, selector) => page.$eval(selector, (el) => el.scrollTop);
|
export const scrollTopOf = (page, selector) => page.$eval(selector, (el) => el.scrollTop);
|
||||||
|
|
||||||
|
// Scrolls what `locator` names to `top` ("end" for its bottom), or as far as
|
||||||
|
// it goes when that is less, and returns where it landed. A redraw can replace
|
||||||
|
// the element between Playwright finding it and the scroll, and one not laid
|
||||||
|
// out yet cannot scroll, so it scrolls again until the element on the page
|
||||||
|
// holds a place past its top.
|
||||||
|
export async function scrollCard(locator, top) {
|
||||||
|
const deadline = Date.now() + 5000;
|
||||||
|
for (;;) {
|
||||||
|
const at = await locator.evaluate((el, want) => {
|
||||||
|
if (!el.isConnected) return null;
|
||||||
|
const max = el.scrollHeight - el.clientHeight;
|
||||||
|
const target = want === "end" ? max : Math.min(want, max);
|
||||||
|
el.scrollTop = target;
|
||||||
|
return max > 0 && Math.abs(el.scrollTop - target) < 1 ? el.scrollTop : null;
|
||||||
|
}, top);
|
||||||
|
if (at !== null) return at;
|
||||||
|
if (Date.now() > deadline) throw new Error(`the element never held a scroll to ${top}`);
|
||||||
|
await new Promise((r) => setTimeout(r, 50));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The computed `props` of the element `locator` names. A redraw can replace the
|
||||||
|
// element between Playwright finding it and the read, and an element off the
|
||||||
|
// page reads "" for every style, so a read of one is taken again.
|
||||||
|
export async function stylesOf(locator, props) {
|
||||||
|
const deadline = Date.now() + 5000;
|
||||||
|
for (;;) {
|
||||||
|
const got = await locator.evaluate((x, ps) => (x.isConnected ? Object.fromEntries(ps.map((p) => [p, getComputedStyle(x)[p]])) : null), props);
|
||||||
|
if (got) return got;
|
||||||
|
if (Date.now() > deadline) throw new Error(`${props.join(", ")}: the element never stayed on the page long enough to read`);
|
||||||
|
await new Promise((r) => setTimeout(r, 50));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export const styleOf = async (locator, prop) => (await stylesOf(locator, [prop]))[prop];
|
||||||
@@ -11,7 +11,7 @@ import assert from "node:assert/strict";
|
|||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { gitInit } from "./skill-script-helpers.mjs";
|
import { gitInit } from "./skill-script-helpers.mjs";
|
||||||
import { pageSuite, openSession, tempProject, sendAndCollect, itemCard, scrollTopOf } from "./page-test-helpers.mjs";
|
import { pageSuite, openSession, tempProject, sendAndCollect, itemCard, scrollTopOf, scrollCard, stylesOf, styleOf } from "./page-test-helpers.mjs";
|
||||||
|
|
||||||
const suite = pageSuite(test);
|
const suite = pageSuite(test);
|
||||||
|
|
||||||
@@ -41,25 +41,6 @@ test("a text answer typed on the page reaches the agent as it was typed", async
|
|||||||
|
|
||||||
// The agent's side of one question: settle what came before, post `item`
|
// The agent's side of one question: settle what came before, post `item`
|
||||||
// alone, and wait for its card.
|
// alone, and wait for its card.
|
||||||
// Scrolls the card `locator` names to `top` ("end" for its bottom) and returns
|
|
||||||
// where it landed. A redraw can replace the card between Playwright finding it
|
|
||||||
// and the scroll, and a card not laid out yet cannot scroll, so it scrolls
|
|
||||||
// again until the card on the page holds the place.
|
|
||||||
async function scrollCard(locator, top) {
|
|
||||||
const deadline = Date.now() + 5000;
|
|
||||||
for (;;) {
|
|
||||||
const at = await locator.evaluate((el, want) => {
|
|
||||||
if (!el.isConnected) return null;
|
|
||||||
el.scrollTop = want === "end" ? el.scrollHeight : want;
|
|
||||||
const held = want === "end" ? el.scrollTop + el.clientHeight >= el.scrollHeight - 1 : el.scrollTop === want;
|
|
||||||
return held ? el.scrollTop : null;
|
|
||||||
}, top);
|
|
||||||
if (at !== null) return at;
|
|
||||||
if (Date.now() > deadline) throw new Error(`the card never held a scroll to ${top}`);
|
|
||||||
await new Promise((r) => setTimeout(r, 50));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function ask(s, item) {
|
async function ask(s, item) {
|
||||||
s.post({ settle: true, items: [item] });
|
s.post({ settle: true, items: [item] });
|
||||||
const card = itemCard(s.page, item.id);
|
const card = itemCard(s.page, item.id);
|
||||||
@@ -247,7 +228,7 @@ test("a redraw keeps your place: the scroll and the focused field survive an age
|
|||||||
// On a doc: the column scrolls.
|
// On a doc: the column scrolls.
|
||||||
await s.page.locator("#views").getByRole("button", { name: /What we've agreed/ }).click();
|
await s.page.locator("#views").getByRole("button", { name: /What we've agreed/ }).click();
|
||||||
await s.page.getByText("Paragraph 80.").waitFor();
|
await s.page.getByText("Paragraph 80.").waitFor();
|
||||||
await s.page.locator("#main").evaluate((el) => (el.scrollTop = 900));
|
await scrollCard(s.page.locator("#main"), 900);
|
||||||
const docBefore = await scrollTopOf(s.page, "#main");
|
const docBefore = await scrollTopOf(s.page, "#main");
|
||||||
assert.ok(docBefore > 0, "the doc column scrolls");
|
assert.ok(docBefore > 0, "the doc column scrolls");
|
||||||
await unrelatedPost(s, "Audit export, take four");
|
await unrelatedPost(s, "Audit export, take four");
|
||||||
@@ -314,7 +295,7 @@ test("a redraw keeps the place of the dashboard, the waiting screen and the fini
|
|||||||
const welcomeDone = s.page.getByRole("button", { name: "Start building" });
|
const welcomeDone = s.page.getByRole("button", { name: "Start building" });
|
||||||
if (await welcomeDone.isVisible()) await welcomeDone.click();
|
if (await welcomeDone.isVisible()) await welcomeDone.click();
|
||||||
await welcomeDone.waitFor({ state: "hidden" });
|
await welcomeDone.waitFor({ state: "hidden" });
|
||||||
await s.page.locator("#main > .dash").evaluate((el) => (el.scrollTop = 150));
|
await scrollCard(s.page.locator("#main > .dash"), 150);
|
||||||
assert.equal(await scrollTopOf(s.page, "#main > .dash"), 150, "the dashboard scrolls");
|
assert.equal(await scrollTopOf(s.page, "#main > .dash"), 150, "the dashboard scrolls");
|
||||||
await unrelatedPost(s, "Dashboard, take two");
|
await unrelatedPost(s, "Dashboard, take two");
|
||||||
assert.equal(await scrollTopOf(s.page, "#main > .dash"), 150, "the dashboard lost its place");
|
assert.equal(await scrollTopOf(s.page, "#main > .dash"), 150, "the dashboard lost its place");
|
||||||
@@ -329,7 +310,7 @@ test("a redraw keeps the place of the dashboard, the waiting screen and the fini
|
|||||||
await s.page.setViewportSize({ width: 1280, height: 300 });
|
await s.page.setViewportSize({ width: 1280, height: 300 });
|
||||||
const pane = "#main > .waiting-pane";
|
const pane = "#main > .waiting-pane";
|
||||||
await s.page.locator(pane).waitFor();
|
await s.page.locator(pane).waitFor();
|
||||||
await s.page.locator(pane).evaluate((el) => (el.scrollTop = 60));
|
await scrollCard(s.page.locator(pane), 60);
|
||||||
const waitingAt = await scrollTopOf(s.page, pane);
|
const waitingAt = await scrollTopOf(s.page, pane);
|
||||||
assert.ok(waitingAt > 0, "the waiting screen scrolls");
|
assert.ok(waitingAt > 0, "the waiting screen scrolls");
|
||||||
await unrelatedPost(s, "Phase 1, take two");
|
await unrelatedPost(s, "Phase 1, take two");
|
||||||
@@ -338,7 +319,7 @@ test("a redraw keeps the place of the dashboard, the waiting screen and the fini
|
|||||||
s.post({ finish: { headline: "Phase 1 is done", body: longText(30), command: "/plan2code-3-implement specs/audit-export/overview.md" } });
|
s.post({ finish: { headline: "Phase 1 is done", body: longText(30), command: "/plan2code-3-implement specs/audit-export/overview.md" } });
|
||||||
await s.page.locator("#main").getByRole("heading", { name: "Phase 1 is done" }).waitFor();
|
await s.page.locator("#main").getByRole("heading", { name: "Phase 1 is done" }).waitFor();
|
||||||
const end = "#main > .card";
|
const end = "#main > .card";
|
||||||
await s.page.locator(end).evaluate((el) => (el.scrollTop = 300));
|
await scrollCard(s.page.locator(end), 300);
|
||||||
assert.equal(await scrollTopOf(s.page, end), 300, "the finished screen scrolls");
|
assert.equal(await scrollTopOf(s.page, end), 300, "the finished screen scrolls");
|
||||||
await unrelatedPost(s, "Phase 1, take three");
|
await unrelatedPost(s, "Phase 1, take three");
|
||||||
assert.equal(await scrollTopOf(s.page, end), 300, "the finished screen lost its place");
|
assert.equal(await scrollTopOf(s.page, end), 300, "the finished screen lost its place");
|
||||||
@@ -350,7 +331,7 @@ test("a redraw keeps the place of the dashboard, the waiting screen and the fini
|
|||||||
workflow: "plan",
|
workflow: "plan",
|
||||||
payload: { items: [{ id: "q1", kind: "text", title: "What to call it", body: longText(40) }] },
|
payload: { items: [{ id: "q1", kind: "text", title: "What to call it", body: longText(40) }] },
|
||||||
});
|
});
|
||||||
await itemCard(s.page, "q1").evaluate((el) => (el.scrollTop = 400));
|
await scrollCard(itemCard(s.page, "q1"), 400);
|
||||||
s.post({ items: [{ id: "q2", kind: "text", title: "Who uses it", body: longText(40) }] });
|
s.post({ items: [{ id: "q2", kind: "text", title: "Who uses it", body: longText(40) }] });
|
||||||
await itemCard(s.page, "q2").waitFor();
|
await itemCard(s.page, "q2").waitFor();
|
||||||
assert.equal(await itemCard(s.page, "q2").evaluate((el) => el.scrollTop), 0, "the new question opened part-way down");
|
assert.equal(await itemCard(s.page, "q2").evaluate((el) => el.scrollTop), 0, "the new question opened part-way down");
|
||||||
@@ -367,19 +348,6 @@ const accentOf = (page) =>
|
|||||||
probe.remove();
|
probe.remove();
|
||||||
return color;
|
return color;
|
||||||
});
|
});
|
||||||
// The computed `props` of the element `locator` names. A redraw can replace the
|
|
||||||
// element between Playwright finding it and the read, and an element off the
|
|
||||||
// page reads "" for every style, so a read of one is taken again.
|
|
||||||
async function stylesOf(locator, props) {
|
|
||||||
const deadline = Date.now() + 5000;
|
|
||||||
for (;;) {
|
|
||||||
const got = await locator.evaluate((x, ps) => (x.isConnected ? Object.fromEntries(ps.map((p) => [p, getComputedStyle(x)[p]])) : null), props);
|
|
||||||
if (got) return got;
|
|
||||||
if (Date.now() > deadline) throw new Error(`${props.join(", ")}: the element never stayed on the page long enough to read`);
|
|
||||||
await new Promise((r) => setTimeout(r, 50));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const styleOf = async (locator, prop) => (await stylesOf(locator, [prop]))[prop];
|
|
||||||
const outlineOf = (button) => styleOf(button, "borderTopColor");
|
const outlineOf = (button) => styleOf(button, "borderTopColor");
|
||||||
const warnOf = (page) =>
|
const warnOf = (page) =>
|
||||||
page.evaluate(() => {
|
page.evaluate(() => {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import fs from "node:fs";
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import test from "node:test";
|
import test from "node:test";
|
||||||
import assert from "node:assert/strict";
|
import assert from "node:assert/strict";
|
||||||
import { pageSuite, openSession, tempProject, textOf } from "./page-test-helpers.mjs";
|
import { pageSuite, openSession, tempProject, textOf, styleOf } from "./page-test-helpers.mjs";
|
||||||
import { cli, until, CONSOLE_CLI, HOME } from "./web-console-test-helpers.mjs";
|
import { cli, until, CONSOLE_CLI, HOME } from "./web-console-test-helpers.mjs";
|
||||||
|
|
||||||
const suite = pageSuite(test);
|
const suite = pageSuite(test);
|
||||||
@@ -153,7 +153,7 @@ test("a fixed bug is hidden while unavailable workflows are, dimmed when they sh
|
|||||||
assert.match(await textOf(bug), /Bug fixed/i, "the chip names its state");
|
assert.match(await textOf(bug), /Bug fixed/i, "the chip names its state");
|
||||||
assert.doesNotMatch(await textOf(bug), /bug fixed\s+bug fixed/i, "the scan's detail does not repeat the label");
|
assert.doesNotMatch(await textOf(bug), /bug fixed\s+bug fixed/i, "the scan's detail does not repeat the label");
|
||||||
assert.equal(await bug.getAttribute("aria-current"), "false", "the fixed bug is not picked");
|
assert.equal(await bug.getAttribute("aria-current"), "false", "the fixed bug is not picked");
|
||||||
const opacity = await bug.evaluate((b) => Number(getComputedStyle(b).opacity));
|
const opacity = Number(await styleOf(bug, "opacity"));
|
||||||
assert.ok(opacity < 1, `the fixed bug's chip is dimmed (opacity ${opacity})`);
|
assert.ok(opacity < 1, `the fixed bug's chip is dimmed (opacity ${opacity})`);
|
||||||
assert.equal(await demo.getAttribute("aria-current"), "true", "the plan stays picked");
|
assert.equal(await demo.getAttribute("aria-current"), "true", "the plan stays picked");
|
||||||
});
|
});
|
||||||
@@ -317,7 +317,7 @@ test("a handoff shows as a dashed Handoff chip even with no spec, and picking it
|
|||||||
const { main, chip } = await openHandoffMenu(t);
|
const { main, chip } = await openHandoffMenu(t);
|
||||||
assert.match(await textOf(chip), /Handoff/i, "the chip is labeled Handoff");
|
assert.match(await textOf(chip), /Handoff/i, "the chip is labeled Handoff");
|
||||||
assert.equal(await chip.getAttribute("aria-current"), "false", "a handoff is offered, not picked for you");
|
assert.equal(await chip.getAttribute("aria-current"), "false", "a handoff is offered, not picked for you");
|
||||||
assert.equal(await chip.evaluate((b) => getComputedStyle(b).borderTopStyle), "dashed", "the chip's border is dashed");
|
assert.equal(await styleOf(chip, "borderTopStyle"), "dashed", "the chip's border is dashed");
|
||||||
assert.ok(await lightOf(main, "/plan2code-1-plan").isVisible(), "the cards show before a handoff is picked");
|
assert.ok(await lightOf(main, "/plan2code-1-plan").isVisible(), "the cards show before a handoff is picked");
|
||||||
|
|
||||||
await chip.click();
|
await chip.click();
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import fs from "node:fs";
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import test from "node:test";
|
import test from "node:test";
|
||||||
import assert from "node:assert/strict";
|
import assert from "node:assert/strict";
|
||||||
import { pageSuite, openSession, drawn } from "./page-test-helpers.mjs";
|
import { pageSuite, openSession, drawn, styleOf } from "./page-test-helpers.mjs";
|
||||||
import { JPEG, backdate, cli, until } from "./web-console-test-helpers.mjs";
|
import { JPEG, backdate, cli, until } from "./web-console-test-helpers.mjs";
|
||||||
import {
|
import {
|
||||||
LEGACY_TAB_ID,
|
LEGACY_TAB_ID,
|
||||||
@@ -249,7 +249,7 @@ test("the editor breaks no content-security rule, and hostile Markdown runs noth
|
|||||||
assert.equal(result.styleTags, 0, "the editor added no <style> element");
|
assert.equal(result.styleTags, 0, "the editor added no <style> element");
|
||||||
assert.deepEqual(consoleErrors.filter((e) => /Content.Security.Policy|Refused to/i.test(e)), []);
|
assert.deepEqual(consoleErrors.filter((e) => /Content.Security.Policy|Refused to/i.test(e)), []);
|
||||||
// The heading is styled from the stylesheet the page ships.
|
// The heading is styled from the stylesheet the page ships.
|
||||||
const h1 = await s.page.locator("#notepad-editor .cm-h1").evaluate((el) => getComputedStyle(el).fontWeight);
|
const h1 = await styleOf(s.page.locator("#notepad-editor .cm-h1"), "fontWeight");
|
||||||
assert.ok(Number(h1) >= 600 || h1 === "bold", `the heading is bold (${h1})`);
|
assert.ok(Number(h1) >= 600 || h1 === "bold", `the heading is bold (${h1})`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -704,6 +704,9 @@ test("a workflow page uses its modules: the full footer, the session meter, @ su
|
|||||||
await s.page.locator("#meter-pill").waitFor();
|
await s.page.locator("#meter-pill").waitFor();
|
||||||
assert.ok((await textOf(s.page.locator("#meter-words"))).length, "the meter pill has no words");
|
assert.ok((await textOf(s.page.locator("#meter-words"))).length, "the meter pill has no words");
|
||||||
// mentions.js: an @ in a text box offers the workspace's folders.
|
// mentions.js: an @ in a text box offers the workspace's folders.
|
||||||
|
// The @ list is the workspace frame, which can land after the page draws;
|
||||||
|
// the footer has one label per width tier once it has.
|
||||||
|
await s.page.waitForFunction(() => (document.getElementById("footer-where").dataset.key || "").includes("\n"));
|
||||||
const box = itemCard(s.page, "q1").locator("textarea");
|
const box = itemCard(s.page, "q1").locator("textarea");
|
||||||
await box.click();
|
await box.click();
|
||||||
await box.pressSequentially("See @");
|
await box.pressSequentially("See @");
|
||||||
|
|||||||
Reference in new issue
Block a user