Files

994 lines
55 KiB
JavaScript
Raw Permalink Normal View History

// Page tests for question cards: every kind answered on the page and sent, the
// sign-off card, and a redraw keeping your place. Run with:
// node --test scripts/test-web-console-page-cards.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 fs from "node:fs";
import path from "node:path";
import { gitInit } from "./skill-script-helpers.mjs";
import { pageSuite, openSession, tempProject, sendAndCollect, itemCard, scrollTopOf, scrollCard, stylesOf, styleOf , fillBox, boxValue, settled } from "./page-test-helpers.mjs";
const suite = pageSuite(test);
test("a session with nothing posted yet shows its starting screen, and stop ends its server", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan" });
assert.match(await s.page.innerText("#main"), /Starting Plan/);
assert.equal(await s.page.locator("#main .pose-stage").count(), 1);
await s.stop();
assert.equal(await s.answers(), false, "the server still answers after stop()");
});
test("a text answer typed on the page reaches the agent as it was typed", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "plan",
payload: { items: [{ id: "q1", kind: "text", title: "What to call it", body: "A short name for the export." }] },
});
await fillBox(itemCard(s.page, "q1").locator(".md-host, input[type=text]").first(), "audit-export");
const got = await sendAndCollect(s);
assert.equal(got.type, "submit");
assert.deepEqual(
got.actions.map(({ i, type, text }) => ({ i, type, text })),
[{ i: "q1", type: "answer", text: "audit-export" }]
);
assert.match(got.reply, /audit-export/);
});
test("the answer box renders Markdown live, like the Notebook", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "plan",
payload: { items: [{ id: "q1", kind: "text", title: "What to build", body: "Describe it." }] },
});
const card = itemCard(s.page, "q1");
const content = card.locator(".md-host .cm-content");
await content.waitFor({ timeout: 15000 });
assert.equal(await card.locator("textarea").count(), 0, "the answer box is the Markdown editor, not a textarea");
// A redraw that lands while the box is typed in sends the caret back to the start (seen on
// slow runners as "plain**bold**"): let the page go quiet before typing.
await settled(s.page, "#main");
await content.click();
await content.pressSequentially("**bold**\nplain");
await card.locator(".cm-strong", { hasText: "bold" }).waitFor();
assert.equal(await content.innerText(), "bold\nplain", "the marks hide off the cursor's line");
const got = await sendAndCollect(s);
assert.deepEqual(answerTo(got, "q1"), { text: "**bold**\nplain" });
});
// The agent's side of one question: settle what came before, post `item`
// alone, and wait for its card.
async function ask(s, item) {
s.post({ settle: true, items: [item] });
const card = itemCard(s.page, item.id);
await card.waitFor();
return card;
}
// The answer an agent reads for item `id`, without the routing fields.
function answerTo(got, id) {
const action = got.actions.find((a) => a.i === id);
assert.ok(action, `the send carries an answer to ${id}: ${JSON.stringify(got.actions)}`);
const { i, type, kind, ...answer } = action;
assert.equal(type, "answer");
return answer;
}
const opt = (k, text) => ({ k, text, detail: `The ${text.toLowerCase()} option.` });
test("every kind of question card sends the answer shape the agent reads", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan" });
let card = await ask(s, { id: "c1", kind: "choice", title: "Export format", body: "Which format?", options: [opt("A", "CSV"), opt("B", "JSON")] });
await card.getByLabel("JSON").check();
let got = await sendAndCollect(s);
assert.deepEqual(answerTo(got, "c1"), { k: "B" });
assert.equal(got.reply, "Export format: B");
card = await ask(s, { id: "c2", kind: "choice", title: "Where it goes", body: "Where?", allowOther: true, options: [opt("A", "Email"), opt("B", "Slack")] });
await card.getByRole("radio", { name: "Something else, in your own words" }).check();
await fillBox(card.locator(".md-host"), "A shared drive");
got = await sendAndCollect(s);
assert.deepEqual(answerTo(got, "c2"), { text: "A shared drive" });
assert.equal(got.reply, "Where it goes: A shared drive");
card = await ask(s, { id: "m1", kind: "multi", title: "Columns", body: "Which?", options: [opt("1", "Date"), opt("2", "User"), opt("3", "Action")], presets: [{ label: "Date and user", ks: ["1", "2"] }] });
await card.getByRole("button", { name: "Date and user" }).click();
await card.getByLabel("Action").check();
await fillBox(card.locator(".md-host"), "and the IP");
got = await sendAndCollect(s);
assert.deepEqual(answerTo(got, "m1"), { ks: ["1", "2", "3"], text: "and the IP" });
assert.equal(got.reply, "Columns: 1, 2, 3; and the IP");
card = await ask(s, { id: "t1", kind: "text", title: "What to call it", body: "A name.", pattern: "^[a-z][a-z0-9-]*$", patternHint: "Lowercase letters, digits and hyphens.", placeholder: "For example: audit-export" });
const field = card.locator("input[type=text]");
// The suggestion is the placeholder without its "For example:" lead-in.
await card.getByRole("button", { name: "Autofill suggestion" }).click();
assert.equal(await boxValue(field), "audit-export");
await fillBox(field, "Audit Export");
await card.getByText("Lowercase letters, digits and hyphens.").waitFor();
assert.equal(await s.page.locator("#btn-send").isDisabled(), true, "a value that breaks the pattern is not sendable");
await fillBox(field, "audit-export");
got = await sendAndCollect(s);
assert.deepEqual(answerTo(got, "t1"), { text: "audit-export" });
assert.equal(got.reply, "What to call it: audit-export");
card = await ask(s, { id: "y1", kind: "confirm", title: "Keep going", body: "Carry on?" });
await card.getByRole("button", { name: "Yes" }).click();
got = await sendAndCollect(s);
assert.deepEqual(answerTo(got, "y1"), { yes: true });
assert.equal(got.reply, "Keep going: yes");
card = await ask(s, { id: "r1", kind: "recap", title: "What we decided", body: "Is this right?", summary: "- CSV\n- Mondays" });
await card.getByRole("button", { name: "Yes, that is right" }).click();
got = await sendAndCollect(s);
assert.deepEqual(answerTo(got, "r1"), { ok: true });
assert.equal(got.reply, "What we decided: confirmed");
card = await ask(s, { id: "k1", kind: "checklist", title: "Set up access", body: "Only you can do these.", steps: ["Create the app", "Paste its key"] });
await card.locator("input[type=checkbox]").first().check();
await card.getByRole("button", { name: "All done" }).click();
got = await sendAndCollect(s);
assert.deepEqual(answerTo(got, "k1"), { done: [0], state: "done" });
assert.equal(got.reply, "Set up access: all done; did steps 1");
card = await ask(s, { id: "n1", kind: "menu", title: "What next", body: "Pick one.", options: [opt("1", "Keep planning"), opt("2", "Stop here")] });
await card.getByLabel("Stop here").check();
got = await sendAndCollect(s);
assert.deepEqual(answerTo(got, "n1"), { k: "2" });
assert.equal(got.reply, "What next: 2");
const rows = [
{ id: "a", title: "Read the data", body: "x" },
{ id: "b", title: "Write the file", body: "y" },
];
card = await ask(s, { id: "l1", kind: "list", title: "The steps", body: "Reorder or rename.", rows });
await card.getByRole("button", { name: "No changes" }).click();
got = await sendAndCollect(s);
assert.deepEqual(answerTo(got, "l1"), { text: "no changes" });
assert.equal(got.reply, "The steps: no changes");
card = await ask(s, { id: "l2", kind: "list", title: "The steps again", body: "Reorder or rename.", rows });
await fillBox(card.locator("input[type=text]").first(), "Read the audit log");
got = await sendAndCollect(s);
assert.deepEqual(
answerTo(got, "l2").rows.map((r) => [r.id, r.title]),
[["a", "Read the audit log"], ["b", "Write the file"]]
);
assert.equal(got.reply, "The steps again: the list: Read the audit log, then Write the file; renamed Read the data to Read the audit log");
s.post({ settle: true, items: [{ id: "x1", kind: "notice", title: "Heads up", body: "The export runs **nightly**." }] });
await s.page.getByText("The export runs").waitFor();
assert.equal(await s.page.locator("#btn-send").isDisabled(), true, "a notice alone gives nothing to send");
});
test("a sign-off card opens its document, and each verdict reaches the agent", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "implement",
payload: {
docs: [{ id: "report", title: "Completion report", blocks: [{ id: "b1", state: "settled", md: "## Summary\n\nPhase 3 adds the /tasks endpoints." }] }],
},
});
const signoff = (id, extra = {}) => ({
id,
kind: "review",
title: "Approve this phase",
doc: "report",
body: "Read the report, then approve it or say what to change.",
verdicts: [
{ id: "approve", label: "Approve this phase" },
{ id: "changes", label: "I want changes" },
{ id: "discard", label: "Throw it away", danger: true },
],
...extra,
});
let card = await ask(s, signoff("so1"));
await card.getByRole("button", { name: /Read .*Completion report.* in full/ }).click();
await s.page.getByText("Phase 3 adds the /tasks endpoints.").waitFor();
assert.ok(await s.page.getByText("Phase 3 adds the /tasks endpoints.").isVisible(), "the report is on screen");
// The danger verdict is marked as such: here the class is the behavior.
await s.page.locator("#views").getByRole("button", { name: /^Questions/ }).click();
card = itemCard(s.page, "so1");
assert.match(await card.getByRole("button", { name: "Throw it away" }).getAttribute("class"), /danger/);
assert.doesNotMatch(await card.getByRole("button", { name: "Approve this phase" }).getAttribute("class"), /danger/);
await card.getByRole("button", { name: "Approve this phase" }).click();
let got = await sendAndCollect(s);
assert.deepEqual(answerTo(got, "so1"), { verdict: "approve" });
card = await ask(s, signoff("so2"));
await card.getByRole("button", { name: "I want changes" }).click();
await fillBox(card.locator(".md-host"), "Keep the header row.");
got = await sendAndCollect(s);
assert.deepEqual(answerTo(got, "so2"), { verdict: "changes", text: "Keep the header row." });
});
const longText = (n) => Array.from({ length: n }, (_, i) => `Paragraph ${i + 1}. The export runs every night and keeps a year of rows.`).join("\n\n");
// The agent posts something unrelated, and the page redraws: wait until the
// new title is drawn.
async function unrelatedPost(s, title) {
s.post({ title });
await s.page.waitForFunction((want) => document.getElementById("title").textContent.includes(want), title);
}
test("a redraw keeps your place: the scroll and the focused field survive an agent post", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "plan",
payload: {
items: [{ id: "q1", kind: "text", title: "What to call it", body: longText(40) }],
docs: [{ id: "map", title: "What we've agreed", blocks: [{ id: "b1", state: "settled", md: longText(80) }] }],
},
});
// The answer box's editor mounts after the first draw and may redraw the
// card: wait for it before scrolling, so no redraw can replace the card
// between the scroll and the agent's post.
await itemCard(s.page, "q1").locator(".md-host .cm-content").first().waitFor();
// Reading a question part-way down: the card scrolls itself.
const card = itemCard(s.page, "q1");
assert.equal(await scrollCard(card, 400), 400, "the question card scrolls");
await unrelatedPost(s, "Audit export, take two");
assert.equal(await itemCard(s.page, "q1").evaluate((el) => el.scrollTop), 400);
// Typing in its answer box: the box keeps the focus and the caret, and the
// card stays where it was. A Markdown field's own API is on its facade:
// document.activeElement is its host, its value and caret on .field.
const field = itemCard(s.page, "q1").locator(".md-host").first();
await field.locator(".cm-content").click();
await field.locator(".cm-content").pressSequentially("audit-ex");
await field.evaluate((el) => el.field.setSelectionRange(3, 3));
const typingAt = await itemCard(s.page, "q1").evaluate((el) => el.scrollTop);
await unrelatedPost(s, "Audit export, take three");
const after = itemCard(s.page, "q1").locator(".md-host").first();
assert.deepEqual(await after.evaluate((el) => [el === document.activeElement, el.field.value, el.field.selectionStart]), [true, "audit-ex", 3]);
assert.equal(await itemCard(s.page, "q1").evaluate((el) => el.scrollTop), typingAt);
// On a doc: the column scrolls.
await s.page.locator("#views").getByRole("button", { name: /What we've agreed/ }).click();
await s.page.getByText("Paragraph 80.").waitFor();
await scrollCard(s.page.locator("#main"), 900);
const docBefore = await scrollTopOf(s.page, "#main");
assert.ok(docBefore > 0, "the doc column scrolls");
await unrelatedPost(s, "Audit export, take four");
assert.equal(await scrollTopOf(s.page, "#main"), docBefore);
});
// The progress line under the title, once the page has drawn `want`.
async function progressSays(s, want) {
await s.page.waitForFunction((w) => document.getElementById("progress-text").textContent === w, want, { timeout: 5000 }).catch(() => {});
return (await s.page.innerText("#progress-text")).trim();
}
// One answered question, so a question workflow has something to count.
const answered = { id: "a1", kind: "text", title: "What to call it", body: "A name.", status: "answered", answer: { text: "audit-export" } };
const open = { id: "o1", kind: "text", title: "Who uses it", body: "Who?" };
test("a build's header counts its tasks, 0 done included, and a question workflow counts its answers", async (t) => {
for (const workflow of ["implement", "implement-review", "quick-task"]) {
const s = await openSession(await suite.browser(), {
t,
workflow,
payload: { headline: { stage: "Phase 3", cleared: 3, total: 9 }, items: [answered] },
});
assert.equal(await progressSays(s, "3 of 9 done"), "3 of 9 done", `${workflow} counts its tasks`);
s.post({ headline: { cleared: 0 } });
assert.equal(await progressSays(s, "0 of 9 done"), "0 of 9 done", `${workflow}: 0 done is 0 done, not the answered card`);
// A build between counts (a review starting at total 0) shows its stage.
s.post({ headline: { stage: "Reviewing the phase", cleared: 0, total: 0 }, items: [open] });
assert.equal(await progressSays(s, "Reviewing the phase"), "Reviewing the phase", `${workflow} shows its stage at total 0`);
assert.equal(await s.page.locator("#progress-bar").isHidden(), true, `${workflow}: no track for a stage`);
await s.stop();
}
// A question workflow that set a total and never moved `cleared` fills as
// cards are answered, and at total 0 counts its cards instead of the stage.
const s = await openSession(await suite.browser(), {
t,
workflow: "plan",
payload: { headline: { stage: "Charting", cleared: 0, total: 4 }, items: [answered] },
});
assert.equal(await progressSays(s, "1 of 4 answered"), "1 of 4 answered");
s.post({ headline: { total: 0 }, items: [open] });
assert.equal(await progressSays(s, "1 of 2 answered"), "1 of 2 answered");
});
test("an answer typed over several lines reaches the agent under its title, never as reply lines of its own", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "plan",
payload: { items: [{ id: "q1", kind: "text", title: "What to call it", body: "A short name for the export." }] },
});
await fillBox(itemCard(s.page, "q1").locator(".md-host"), "audit-export\nIdea name: not a heading");
const got = await sendAndCollect(s);
assert.equal(answerTo(got, "q1").text, "audit-export\nIdea name: not a heading");
assert.ok(got.reply.includes("What to call it: audit-export\n Idea name: not a heading"), `the second line is not indented under its title: ${JSON.stringify(got.reply)}`);
});
test("a redraw keeps the place of the dashboard, the waiting screen and the finished screen, and a new question starts at its top", async (t) => {
// The dashboard's menu scrolls itself.
let s = await openSession(await suite.browser(), { t, workflow: "dashboard" });
await s.page.setViewportSize({ width: 1280, height: 420 });
await s.page.getByRole("button", { name: "Skip the intro" }).click();
await s.page.locator("#main").getByRole("heading", { name: "What are we doing today?" }).waitFor();
const welcomeDone = s.page.getByRole("button", { name: "Start building" });
if (await welcomeDone.isVisible()) await welcomeDone.click();
await welcomeDone.waitFor({ state: "hidden" });
await settled(s.page, "#main > .dash");
await scrollCard(s.page.locator("#main > .dash"), 150);
assert.equal(await scrollTopOf(s.page, "#main > .dash"), 150, "the dashboard scrolls");
await unrelatedPost(s, "Dashboard, take two");
assert.equal(await scrollTopOf(s.page, "#main > .dash"), 150, "the dashboard lost its place");
await s.stop();
// A build with nothing to ask yet: the waiting screen, and then its finish.
s = await openSession(await suite.browser(), {
t,
workflow: "implement",
payload: { headline: { stage: "Phase 1", cleared: 0, total: 3 }, agent: { status: "working", activity: "Task 1 of 3: the reader" } },
});
await s.page.setViewportSize({ width: 1280, height: 300 });
const pane = "#main > .waiting-pane";
await s.page.locator(pane).waitFor();
await settled(s.page, pane);
await scrollCard(s.page.locator(pane), 60);
const waitingAt = await scrollTopOf(s.page, pane);
assert.ok(waitingAt > 0, "the waiting screen scrolls");
await unrelatedPost(s, "Phase 1, take two");
assert.equal(await scrollTopOf(s.page, pane), waitingAt, "the waiting screen lost its place");
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();
const end = "#main > .card";
await scrollCard(s.page.locator(end), 300);
assert.equal(await scrollTopOf(s.page, end), 300, "the finished screen scrolls");
await unrelatedPost(s, "Phase 1, take three");
assert.equal(await scrollTopOf(s.page, end), 300, "the finished screen lost its place");
await s.stop();
// Part-way down one question, a new one arrives: it starts at its top.
s = await openSession(await suite.browser(), {
t,
workflow: "plan",
payload: { items: [{ id: "q1", kind: "text", title: "What to call it", body: longText(40) }] },
});
await scrollCard(itemCard(s.page, "q1"), 400);
s.post({ items: [{ id: "q2", kind: "text", title: "Who uses it", body: longText(40) }] });
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");
});
// The accent color as the browser resolves it, and a button's outline color,
// so "wears the accent" is read off the screen, not off a class name.
const accentOf = (page) =>
page.evaluate(() => {
const probe = document.createElement("i");
probe.style.color = "var(--accent)";
document.body.appendChild(probe);
const color = getComputedStyle(probe).color;
probe.remove();
return color;
});
const outlineOf = (button) => styleOf(button, "borderTopColor");
const warnOf = (page) =>
page.evaluate(() => {
const probe = document.createElement("i");
probe.style.color = "var(--warn)";
document.body.appendChild(probe);
const color = getComputedStyle(probe).color;
probe.remove();
return color;
});
// What a person sees break: the way forward on a sign-off card looks like any
// other choice.
test("on a sign-off card, approve and yes are outlined in the accent until picked, and the others are not", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "implement" });
const accent = await accentOf(s.page);
const review = (id, verdicts) => ({ id, kind: "review", title: "Sign off " + id, body: "Read it.", verdicts });
let card = await ask(s, review("so1", [{ id: "approve", label: "Approve this phase" }, { id: "changes", label: "I want changes" }]));
const approve = card.getByRole("button", { name: "Approve this phase" });
assert.equal(await outlineOf(approve), accent, "an unpicked approve is outlined in the accent");
assert.notEqual(await outlineOf(card.getByRole("button", { name: "I want changes" })), accent, "the other verdict is not");
await approve.click();
await s.page.waitForFunction(() => document.querySelector("#btn-send:not(:disabled)"));
assert.equal(await styleOf(approve, "backgroundColor"), accent, "picked, approve fills with the accent");
card = await ask(s, review("so2", [{ id: "yes", label: "Build it" }, { id: "no", label: "Not yet" }]));
assert.equal(await outlineOf(card.getByRole("button", { name: "Build it" })), accent, "an unpicked yes is outlined too");
assert.notEqual(await outlineOf(card.getByRole("button", { name: "Not yet" })), accent);
});
// What a person hears break: a screen reader names the verdicts on a sign-off
// card but never says which one is picked.
test("a sign-off card's verdicts expose aria-pressed, kept in step with each click", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "implement" });
const card = await ask(s, {
id: "so1",
kind: "review",
title: "Sign off",
body: "Read it.",
verdicts: [{ id: "approve", label: "Approve this phase" }, { id: "changes", label: "I want changes" }],
});
const approve = card.getByRole("button", { name: "Approve this phase" });
const changes = card.getByRole("button", { name: "I want changes" });
const pressed = async () => [await approve.getAttribute("aria-pressed"), await changes.getAttribute("aria-pressed")];
assert.deepEqual(await pressed(), ["false", "false"], "nothing picked yet");
await approve.click();
await s.page.waitForFunction(() => document.querySelector("#btn-send:not(:disabled)"));
assert.deepEqual(await pressed(), ["true", "false"], "approve picked");
assert.equal(await card.getByRole("button", { name: "Approve this phase", pressed: true }).count(), 1);
await changes.click();
await s.page.waitForFunction(() => document.querySelector('[data-item="so1"] button[aria-pressed="true"]')?.textContent.includes("I want changes"));
assert.deepEqual(await pressed(), ["false", "true"], "the pick moved to changes");
await changes.click();
await s.page.waitForFunction(() => !document.querySelector('[data-item="so1"] button[aria-pressed="true"]'));
assert.deepEqual(await pressed(), ["false", "false"], "a second click takes the pick back");
});
// What a person sees break: Skip this one turns into a full-size button, or
// the quick answer under a note box does.
test("Skip this one and a comment box's quick answer are the same small accent button", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan" });
const rows = [{ id: "a", title: "Read the data", body: "x" }];
const card = await ask(s, { id: "l1", kind: "list", title: "The steps", body: "Rename.", required: false, rows });
const skip = card.getByRole("button", { name: "Skip this one" });
const quick = card.getByRole("button", { name: "No changes" });
const look = async (b) => Object.values(await stylesOf(b, ["fontSize", "paddingTop", "paddingLeft", "color"]));
assert.deepEqual(await look(skip), await look(quick), "the two chips look alike");
const [size, , , color] = await look(skip);
assert.equal(size, "12px", "small, not a full-size button");
assert.equal(color, await accentOf(s.page), "in the accent");
});
// What a person sees break: Combine phases is missing from a plan's breakdown,
// fills nothing, or shows on a list that is not phases.
test("a plan's breakdown offers Combine phases beside No changes, and other workflows do not", async (t) => {
const rows = [{ id: "a", title: "Read the data", body: "x" }];
let s = await openSession(await suite.browser(), { t, workflow: "plan" });
let card = await ask(s, { id: "l1", kind: "list", title: "Build order", body: "Reorder.", rows });
const quicks = card.locator(".quick-answer");
assert.deepEqual(await quicks.allTextContents(), ["No changes", "Combine phases"]);
await card.getByRole("button", { name: "Combine phases" }).click();
const got = await sendAndCollect(s);
assert.match(answerTo(got, "l1").text, /^Combine phases where possible/);
s = await openSession(await suite.browser(), { t, workflow: "quick-task" });
card = await ask(s, { id: "l2", kind: "list", title: "Steps", body: "Reorder.", rows });
assert.deepEqual(await card.locator(".quick-answer").allTextContents(), ["No changes"]);
});
// What a person sees break: a safe yes looks like any button, or a risky yes
// stops warning.
test("a confirm's safe yes and a recap's yes are outlined in the accent, and a dangerous yes stays red", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan" });
const accent = await accentOf(s.page);
const warn = await warnOf(s.page);
let card = await ask(s, { id: "y1", kind: "confirm", title: "Keep going", body: "Carry on?" });
const yes = card.getByRole("button", { name: "Yes" });
assert.equal(await outlineOf(yes), accent, "a safe, unpicked yes wears the accent");
assert.notEqual(await outlineOf(card.getByRole("button", { name: "No" })), accent, "the no does not");
await yes.click();
await s.page.waitForFunction(() => document.querySelector("#btn-send:not(:disabled)"));
assert.equal(await styleOf(yes, "backgroundColor"), accent, "picked, it fills");
card = await ask(s, { id: "y2", kind: "confirm", title: "Delete it", body: "Really?", danger: true });
assert.equal(await outlineOf(card.getByRole("button", { name: "Yes" })), warn, "a dangerous yes stays red");
card = await ask(s, { id: "r1", kind: "recap", title: "What we decided", body: "Right?", summary: "- CSV" });
assert.equal(await outlineOf(card.getByRole("button", { name: "Yes, that is right" })), accent, "the recap's yes wears the accent");
});
// What a person sees break: a long question runs off the window with nothing
// to say there is more, or the fade stays on at the very end.
test("a card cut by the window fades at its bottom edge while there is more below", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan" });
await s.page.setViewportSize({ width: 1280, height: 420 });
const card = await ask(s, { id: "q1", kind: "text", title: "What to call it", body: longText(40) });
const fades = async () => { const c = await stylesOf(card, ["maskImage", "webkitMaskImage"]); return (c.maskImage || c.webkitMaskImage || "none") !== "none"; };
await s.page.waitForFunction(() => { const c = document.querySelector("#main > .card"); return c && c.scrollHeight > c.clientHeight + 4; });
await s.page.waitForFunction(() => { const c = document.querySelector("#main > .card"); const m = getComputedStyle(c); return (m.maskImage || m.webkitMaskImage || "none") !== "none"; });
assert.equal(await fades(), true, "a cut card fades at the bottom");
await scrollCard(card, "end");
await s.page.waitForFunction(() => { const c = document.querySelector("#main > .card"); const m = getComputedStyle(c); return (m.maskImage || m.webkitMaskImage || "none") === "none"; });
assert.equal(await fades(), false, "at the end, the fade is gone");
});
// What a person sees break: a rename typed in a list is lost when the agent
// posts or Ctrl+Enter sends before the field was left.
test("a list rename is staged as it is typed, so Ctrl+Enter or an agent post never drops it", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan" });
const rows = [{ id: "a", title: "Read the data", body: "x" }, { id: "b", title: "Write the file", body: "y" }];
const card = await ask(s, { id: "l1", kind: "list", title: "The steps", body: "Rename.", rows });
const first = card.locator("input.row-title").first();
await first.click();
await fillBox(first, "Read the audit log");
// The field is still focused: it has not changed or blurred.
await s.page.waitForFunction(() => document.querySelector("#btn-send:not(:disabled)"));
await unrelatedPost(s, "Steps, take two");
assert.equal(await boxValue(itemCard(s.page, "l1").locator("input.row-title").first()), "Read the audit log", "the agent post kept the typed name");
await itemCard(s.page, "l1").locator("input.row-title").first().focus();
await s.page.keyboard.press("Control+Enter");
const got = s.wait(10);
assert.equal(got.code, 0, "Ctrl+Enter sent");
assert.deepEqual(answerTo(got, "l1").rows.map((r) => [r.id, r.title]), [["a", "Read the audit log"], ["b", "Write the file"]]);
});
// What a person sees break: a send the agent already collected still shows as
// being with the agent, locking a question it left open.
test("a send made before the last collection is never shown as still with the agent", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan" });
const card = await ask(s, { id: "q1", kind: "text", title: "What to call it", body: "A name." });
// Sent from another tab: this page never learns of it except from the session.
await s.page.evaluate(() =>
fetch("/submit", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ actions: [{ i: "q1", type: "answer", kind: "text", text: "audit-export" }], reply: "What to call it: audit-export" }),
})
);
const lock = card.getByText(/Plan2Code is working on it|Waiting for Plan2Code to pick this up/);
await lock.waitFor();
assert.equal(await card.locator(".md-host").count(), 0, "before the agent collects it, the card is locked");
// The agent collects it, leaves the question open and waits again.
assert.equal(s.wait(10).code, 0);
s.post({ agent: { status: "waiting" } });
await card.locator(".md-host").waitFor();
assert.equal(await lock.count(), 0, "after the collection, it is not shown as sent");
});
// What a person sees break: a note box on a card above the git board grows and
// squeezes the board, or the card is cut short under it.
test("a note box over the git board grows no box, and the card flows at its own height", async (t) => {
const dir = tempProject({ "README.md": "# Sample\n", "src/app.js": "export const app = 1;\n" });
const g = gitInit(dir);
g("add", "-A");
g("commit", "-q", "-m", "First commit");
fs.appendFileSync(path.join(dir, "src", "app.js"), "export const more = 2;\n");
const confirm = { id: "y1", kind: "confirm", title: "Save these changes", body: "Commit them?" };
const git = await openSession(await suite.browser(), {
t,
workflow: "git",
project: dir,
payload: { reread: true, board: { describe: "export-more" }, items: [confirm] },
});
await git.page.getByRole("tablist").waitFor();
const gitCard = itemCard(git.page, "y1");
await gitCard.waitFor();
const note = gitCard.locator(".md-host").first();
const gitBox = await note.evaluate((el) => ({ min: el.style.minHeight, height: el.offsetHeight }));
assert.equal(gitBox.min, "", "no height was filled in for the note box");
assert.ok(gitBox.height < 120, `the note box keeps its ordinary height over the board: ${gitBox.height}`);
assert.ok(await gitCard.evaluate((el) => el.scrollHeight <= el.clientHeight + 1), "the card is not shrunk under the board");
// The same card away from the board does fill the free height of the card.
const plan = await openSession(await suite.browser(), { t, workflow: "plan", payload: { items: [confirm] } });
const planBox = plan.page.locator('[data-item="y1"] .md-host').first();
await planBox.waitFor();
await plan.page.waitForFunction(() => document.querySelector('[data-item="y1"] .md-host').offsetHeight >= 160);
assert.ok((await planBox.evaluate((el) => el.offsetHeight)) > gitBox.height, "away from the board, the note box grows");
});
const three = ["First", "Second", "Third"].map((name, n) => ({ id: `q${n + 1}`, kind: "text", title: `${name} question`, body: `Body ${n + 1}.` }));
// What a person sees break: Previous and Next stop walking the open questions.
test("Previous and Next walk the questions still waiting, and the ends have no button", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: { items: three } });
const pager = s.page.getByRole("navigation", { name: "Move between the questions waiting" });
const shown = () => s.page.locator("#main [data-item]").first().getAttribute("data-item");
await pager.getByText("1 of 3 waiting").waitFor();
assert.equal(await pager.getByRole("button", { name: /Previous/ }).count(), 0, "nothing before the first");
await pager.getByRole("button", { name: /Next.*Second question/ }).click();
await pager.getByText("2 of 3 waiting").waitFor();
assert.equal(await shown(), "q2");
await pager.getByRole("button", { name: /Next.*Third question/ }).click();
await pager.getByText("3 of 3 waiting").waitFor();
assert.equal(await pager.getByRole("button", { name: /Next/ }).count(), 0, "nothing after the last");
await pager.getByRole("button", { name: /Previous.*Second question/ }).click();
await pager.getByText("2 of 3 waiting").waitFor();
assert.equal(await shown(), "q2");
});
// What a person sees break: Skip this one does nothing, or leaves you on the
// card you skipped.
test("Skip this one on an optional card moves on, and the skip reaches the agent", async (t) => {
const items = three.map((q, n) => ({ ...q, required: n !== 2 ? false : true }));
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: { items } });
const card = itemCard(s.page, "q1");
await card.getByRole("button", { name: "Skip this one" }).click();
await s.page.waitForFunction(() => document.querySelector("#main [data-item]")?.dataset.item === "q2");
assert.equal(await itemCard(s.page, "q3").getByRole("button", { name: "Skip this one" }).count(), 0, "a required card cannot be skipped");
await fillBox(itemCard(s.page, "q2").locator(".md-host"), "Ana");
await s.page.getByRole("navigation", { name: "Move between the questions waiting" }).getByRole("button", { name: /Next/ }).click();
await fillBox(itemCard(s.page, "q3").locator(".md-host"), "Bo");
const got = await sendAndCollect(s);
assert.deepEqual(
got.actions.map(({ i, type, text }) => ({ i, type, text })),
[{ i: "q1", type: "skip", text: undefined }, { i: "q2", type: "answer", text: "Ana" }, { i: "q3", type: "answer", text: "Bo" }]
);
});
// What a person sees break: an answered question can be edited again, or says
// nothing about what was answered.
test("a settled card is a record: your answer in words, the options as marks, and no form", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan" });
s.post({
settle: true,
items: [
{ id: "c1", kind: "choice", title: "Export format", body: "Which?", options: [opt("A", "CSV"), opt("B", "JSON")], status: "answered", answer: { k: "B" } },
{ id: "q9", kind: "text", title: "Still open", body: "Next." },
],
});
await s.page.locator("#sidebar").getByRole("button", { name: /Export format/ }).click();
const card = itemCard(s.page, "c1");
await card.waitFor();
const record = card.locator(".answered");
assert.match(await record.innerText(), /Your answer[\s\S]*JSON/i);
assert.match(await record.innerText(), /Locked\./);
assert.equal(await card.locator("input, textarea, .md-host").count(), 0, "a record has no inputs");
});
// What a person sees break: a card still takes edits after Send, or never
// opens again when the agent hands it back.
test("a sent card locks, and the agent's next post on it unlocks it", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: { items: [three[0]] } });
const card = itemCard(s.page, "q1");
await fillBox(card.locator(".md-host"), "Ana");
await s.page.click("#btn-send");
const lock = card.getByText(/Plan2Code is working on it|Waiting for Plan2Code to pick this up/);
await lock.waitFor();
assert.match(await card.locator(".answered").innerText(), /Sent[\s\S]*Ana/i);
assert.equal(await card.locator(".md-host").count(), 0, "no form while the agent has it");
s.wait(10);
s.post({ items: [{ id: "q1", status: "reopened", thread: [{ who: "agent", text: "Which Ana?" }] }], agent: { status: "waiting" } });
await card.locator(".md-host").waitFor();
assert.equal(await lock.count(), 0, "the next post gives the card back");
});
// What a person sees break: the "something else" box takes the words but the
// pick sent is still the listed option, or the pick is lost on a switch back.
test("Something else in your own words replaces the pick, and picking an option again drops the words", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan" });
const card = await ask(s, { id: "c1", kind: "choice", title: "Where", body: "Where?", options: [opt("A", "Email"), opt("B", "Slack")] });
await card.getByLabel("Email").check();
const other = card.getByRole("radio", { name: "Something else, in your own words" });
await other.check();
await fillBox(card.locator(".md-host.other-text"), "A shared drive");
assert.equal(await card.getByLabel("Email").isChecked(), false, "the options and the other share one group");
await card.getByLabel("Slack").check();
await other.check();
assert.equal(await boxValue(card.locator(".md-host.other-text")), "A shared drive", "the words survive a switch");
const got = await sendAndCollect(s);
assert.deepEqual(answerTo(got, "c1"), { text: "A shared drive" });
});
// What a person sees break: a stray pick on a one-answer question can only be
// swapped for another, never taken back, or Clear shows on a card already sent.
test("Clear on a one-answer question takes back the pick and the words, and a sent card has no Clear", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan" });
const card = await ask(s, { id: "c1", kind: "choice", title: "Where", body: "Where?", options: [opt("A", "Email"), opt("B", "Slack")] });
const clear = card.getByRole("button", { name: "Clear your answer to this question" });
await card.getByRole("radio", { name: "Something else, in your own words" }).check();
await fillBox(card.locator(".md-host.other-text"), "A shared drive");
await clear.click();
await s.page.waitForFunction(() => !document.querySelector("#main .card.is-staged"));
assert.equal(await boxValue(card.locator(".md-host.other-text")), "", "the words go too");
await card.getByLabel("Slack").check();
await clear.click();
await s.page.waitForFunction(() => !document.querySelector("#main .card.is-staged"));
assert.equal(await card.locator("input[type=radio]:checked").count(), 0, "no pick is left");
await card.getByLabel("Email").check();
await s.page.click("#btn-send");
await card.getByText(/Plan2Code is working on it|Waiting for Plan2Code to pick this up/).waitFor();
assert.equal(await clear.count(), 0, "a sent card cannot be cleared");
});
// What a person sees break: on a question taller than the window, Clear sat at
// the card's foot, out of sight until the options were scrolled past.
test("Clear on a tall question reads \"Clear answer\" and stays on screen while the options scroll", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan" });
await s.page.setViewportSize({ width: 1280, height: 520 });
const options = Array.from({ length: 14 }, (_, i) => opt(String.fromCharCode(65 + i), `Choice ${i + 1}`));
const card = await ask(s, { id: "c1", kind: "choice", title: "Which", body: "Which one?", options });
const clear = card.getByRole("button", { name: "Clear your answer to this question" });
assert.equal((await clear.innerText()).trim(), "Clear answer");
assert.equal(await clear.locator("svg").count(), 1, "an icon leads the label");
const visible = () => clear.evaluate((b) => {
const c = b.getBoundingClientRect();
const card = b.closest(".card").getBoundingClientRect();
return c.top >= card.top && c.bottom <= card.bottom + 1 && c.bottom <= window.innerHeight;
});
assert.equal(await visible(), true, "in view with the card scrolled to the top");
await scrollCard(card, "end");
assert.equal(await visible(), true, "still in view at the foot of the card");
});
// What a person sees break: a note typed on a card is dropped by the verdict,
// or is lost when the verdict comes first.
test("a note's comment field rides along with the answer, typed before or after the pick", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan" });
let card = await ask(s, { id: "y1", kind: "confirm", title: "Keep going", body: "Carry on?" });
await fillBox(card.getByLabel("Anything to add?"), "Only on weekdays.");
await card.getByRole("button", { name: "Yes" }).click();
let got = await sendAndCollect(s);
assert.deepEqual(answerTo(got, "y1"), { yes: true, text: "Only on weekdays." });
assert.equal(got.reply, "Keep going: yes; Only on weekdays.");
card = await ask(s, { id: "y2", kind: "confirm", title: "And this", body: "Also?" });
await card.getByRole("button", { name: "No" }).click();
await fillBox(card.getByLabel("Anything to add?"), "Not this quarter.");
got = await sendAndCollect(s);
assert.deepEqual(answerTo(got, "y2"), { yes: false, text: "Not this quarter." });
});
/* ----------------------------------------------------------------- docs */
// What a person sees break: a guess reads like a decision, or a draft does.
test("a doc tags an assumed block and a draft block, and shows a file block's text", async (t) => {
const project = tempProject({ "notes/facts.md": "The export keeps **a year** of rows.\n" });
const s = await openSession(await suite.browser(), {
t,
workflow: "plan",
project,
payload: {
docs: [
{
id: "map",
title: "What we've agreed",
blocks: [
{ id: "b1", state: "settled", md: "Runs nightly." },
{ id: "b2", state: "assumed", md: "Output is CSV." },
{ id: "b3", state: "draft", md: "Maybe a weekly digest." },
{ id: "b4", file: "notes/facts.md" },
],
},
],
},
});
await s.page.locator("#views").getByRole("button", { name: /What we've agreed/ }).click();
const block = (id) => s.page.locator(`#main [data-block="${id}"]`);
await block("b4").waitFor();
assert.equal(await block("b1").innerText(), "Runs nightly.", "a settled block has no tag");
assert.match(await block("b2").innerText(), /^assumed for now, still open\s+Output is CSV\.$/i);
assert.match(await block("b3").innerText(), /^draft\s+Maybe a weekly digest\.$/i);
assert.match(await block("b4").innerText(), /The export keeps a year of rows\./, "the file's text is on the page");
});
// What a person sees break: Download hands over something other than the
// document, or loses which parts are still guesses.
test("Download offers a Markdown file with the doc's title, blocks and marks", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "plan",
payload: {
docs: [{ id: "map", title: "What we've agreed", blocks: [{ id: "b1", state: "settled", md: "Runs nightly." }, { id: "b2", state: "assumed", md: "Output is CSV." }] }],
},
});
await s.page.locator("#views").getByRole("button", { name: /What we've agreed/ }).click();
const [download] = await Promise.all([s.page.waitForEvent("download"), s.page.getByRole("button", { name: "Download" }).click()]);
assert.equal(download.suggestedFilename(), "what-we-ve-agreed.md");
const chunks = [];
for await (const c of await download.createReadStream()) chunks.push(c);
assert.equal(Buffer.concat(chunks).toString("utf8"), "# What we've agreed\n\nRuns nightly.\n\n> **Assumed for now, still open.**\n\nOutput is CSV.");
});
// What a person sees break: a long document has no way home but the first
// tab, or its header scrolls away with the text.
test("a document's header stays on screen and its Back to Questions button returns to the questions", async (t) => {
const blocks = Array.from({ length: 60 }, (_, i) => ({ id: "b" + i, state: "settled", md: `Paragraph ${i}. ` + "More words. ".repeat(40) }));
const s = await openSession(await suite.browser(), {
t,
workflow: "plan",
payload: {
items: [{ id: "q1", kind: "text", title: "A question", body: "Say something." }],
docs: [{ id: "map", title: "What we've agreed", blocks }],
},
});
await s.page.locator("#views").getByRole("button", { name: /What we've agreed/ }).click();
const back = s.page.getByRole("button", { name: "Back to Questions" });
await back.waitFor();
await s.page.evaluate(() => { document.getElementById("main").scrollTop = 4000; });
const box = await back.boundingBox();
const main = await s.page.locator("#main").boundingBox();
assert.ok(box && box.y >= main.y - 1 && box.y < main.y + 80, "the header row is still at the top of the pane after scrolling");
await back.click();
await s.page.getByText("Say something.").waitFor();
assert.equal(await s.page.getByRole("button", { name: "Back to Questions" }).count(), 0, "the questions view has no Back button");
});
// What a person sees break: the brief button turns up where no playbook
// answers it, or sends a different range than the one picked.
test("a pathfinder session offers Write a brief, and the picked range reaches the agent", async (t) => {
const plain = await openSession(await suite.browser(), { t, workflow: "plan" });
assert.equal(await plain.page.locator("#btn-brief").isHidden(), true, "no brief button outside pathfinder");
await plain.stop();
const s = await openSession(await suite.browser(), { t, workflow: "pathfinder", payload: { agent: { status: "waiting" } } });
await s.page.getByRole("button", { name: "Write a brief" }).first().click();
const dialog = s.page.locator("#brief-modal");
await dialog.getByLabel("This week").check();
await dialog.getByRole("button", { name: "Write the brief" }).click();
await dialog.waitFor({ state: "hidden" });
const got = s.wait(10);
assert.equal(got.code, 0, "a brief request was sent");
assert.deepEqual(got.actions.map(({ i, type, range }) => ({ i, type, range })), [{ i: "__brief", type: "brief", range: "this week" }]);
assert.equal(got.reply, "Write a brief for this week.");
});
// What a person sees break: the agent answers a note in the thread and the
// card says nothing, so the question looks as current as before the reply.
test("a noted card with a trailing agent reply shows the check tag, and an un-noted one does not", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "plan",
payload: {
items: [
{ id: "q1", kind: "text", title: "What to call it", body: "A short name." },
{ id: "q2", kind: "text", title: "Who uses it", body: "Who, and for what?" },
],
},
});
const aside = s.page.locator("#aside");
const tag = aside.locator(".noted-tag");
await itemCard(s.page, "q1").waitFor();
assert.equal(await tag.count(), 0, "no tag before any note");
await fillBox(s.page.locator("#thread-q1"), "Maybe two names?");
await sendAndCollect(s);
s.post({ items: [{ id: "q1", thread: [{ who: "agent", text: "Two names fit, I will ask." }] }, { id: "q2", thread: [{ who: "agent", text: "A plain reply, no note from you." }] }] });
await aside.getByText("Two names fit, I will ask.").waitFor();
await tag.waitFor();
assert.equal((await tag.innerText()).trim(), "Plan2Code replied, check this still fits");
assert.equal(await tag.getAttribute("role"), "note", "the tag has an accessible role");
assert.notEqual(await styleOf(tag, "backgroundColor"), "rgba(0, 0, 0, 0)", "the tag is drawn, not bare text");
await s.page.locator("#sidebar .rail-item", { hasText: "Who uses it" }).click();
await aside.getByText("A plain reply, no note from you.").waitFor();
assert.equal(await aside.locator(".noted-tag").count(), 0, "a reply on a question nobody noted gets no tag");
});
// What a person sees break: a question arrives while they type, the notice
// vanishes after 8 seconds, and the question stays buried in the list.
test("a question arriving while a note is typed keeps its notice and a New mark until it is opened", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "plan",
clock: true,
payload: { items: [{ id: "q1", kind: "text", title: "What to call it", body: "A short name." }] },
});
const note = s.page.locator("#thread-q1");
await itemCard(s.page, "q1").waitFor();
await fillBox(note, "my half-written thought");
await note.click();
await s.page.waitForFunction(() => Boolean(document.activeElement && document.activeElement.field));
s.post({ items: [{ id: "q2", kind: "text", title: "Who uses it", body: "Who, and for what?" }] });
const banner = s.page.locator("#banner");
await s.page.getByText("A new question from Plan2Code").waitFor();
const entry = s.page.locator("#sidebar .rail-item", { hasText: "Who uses it" });
await entry.locator(".rail-new").waitFor();
await s.page.clock.fastForward(20000);
assert.equal(await banner.isVisible(), true, "the notice is still up after 20 seconds");
assert.match(await banner.innerText(), /new question/);
assert.equal(await boxValue(note), "my half-written thought", "the draft is untouched");
assert.equal(await s.page.evaluate(() => Boolean(document.activeElement && document.activeElement.field)), true, "focus is still in the note box");
assert.equal(await itemCard(s.page, "q1").isVisible(), true, "the selection did not move");
// By keyboard, so no pointer press clears the notice first: only the prune can.
await entry.focus();
await s.page.keyboard.press("Enter");
await itemCard(s.page, "q2").waitFor();
assert.equal(await s.page.locator("#sidebar .rail-new").count(), 0, "the mark is gone once the question is opened");
assert.equal(await banner.isVisible(), false, "the notice goes with the last mark");
});
test("opening the marked question from the pager clears its New mark", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "plan",
payload: { items: [{ id: "q1", kind: "text", title: "What to call it", body: "A short name." }] },
});
const note = s.page.locator("#thread-q1");
await itemCard(s.page, "q1").waitFor();
await fillBox(note, "half a thought");
await note.click();
await s.page.waitForFunction(() => Boolean(document.activeElement && document.activeElement.field));
s.post({ items: [{ id: "q2", kind: "text", title: "Who uses it", body: "Who, and for what?" }] });
const entry = s.page.locator("#sidebar .rail-item", { hasText: "Who uses it" });
await entry.locator(".rail-new").waitFor();
const pager = s.page.getByRole("navigation", { name: "Move between the questions waiting" });
await pager.getByRole("button", { name: /Next.*Who uses it/ }).click();
await itemCard(s.page, "q2").waitFor();
assert.equal(await s.page.locator("#sidebar .rail-new").count(), 0, "the mark is gone once the pager opens the question");
});
test("a staying arrival notice survives typing, goes on Escape, and the New mark outlasts it", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "plan",
payload: { items: [{ id: "q1", kind: "text", title: "What to call it", body: "A short name." }] },
});
const note = s.page.locator("#thread-q1");
await itemCard(s.page, "q1").waitFor();
await note.click();
await s.page.waitForFunction(() => Boolean(document.activeElement && document.activeElement.field));
s.post({ items: [{ id: "q2", kind: "text", title: "Who uses it", body: "Who, and for what?" }] });
const banner = s.page.locator("#banner");
await s.page.getByText("A new question from Plan2Code").waitFor();
await s.page.keyboard.press("a");
assert.equal(await banner.isVisible(), true, "a letter typed in the note does not clear the notice");
await s.page.keyboard.press("Escape");
await banner.waitFor({ state: "hidden" });
assert.equal(await s.page.locator("#sidebar .rail-item", { hasText: "Who uses it" }).locator(".rail-new").count(), 1, "the New mark stays after the notice is dismissed");
});
2026-11-13 23:28:59 -08:00
test("a long pick list draws group headings, opens a row, holds a locked row and counts picks and rounds live", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "plan" });
const card = await ask(s, {
id: "deps",
kind: "multi",
title: "Updates to apply",
body: "Tick the updates to apply.",
counter: { rounds: "check rounds" },
presets: [{ label: "All safe", ks: ["S1", "S2"] }],
options: [
{ k: "S1", text: "react 18.3.1 to 18.3.2", group: "Safe", batch: "npm-root" },
{ k: "S2", text: "vite 6.0.1 to 6.0.3", group: "Safe", batch: "npm-root" },
{ k: "C1", text: "zod 3.23.0 to 3.24.1", group: "Check first", more: "**Changed:** `z.string().email()` is stricter." },
{ k: "W1", text: "eslint 8.57.0 to 9.0.0", group: "Warning", locked: true, detail: "Needs Node 20." },
],
});
// Headings in the order sent, one per run.
await card.locator(".option-group", { hasText: "Warning" }).waitFor();
assert.deepEqual(await card.locator(".option-group").allTextContents(), ["Safe", "Check first", "Warning"]);
// The row that opens: closed at first, opened by its button, and the tick stays as it was.
assert.equal(await card.locator(".option-more").count(), 0, "closed by default");
const more = card.getByRole("button", { name: /^More about zod/ });
assert.equal(await more.getAttribute("aria-expanded"), "false");
// From the keyboard: focus stays on the rebuilt button, now named for its visible word.
// The "Plan2Code is back" notice takes the first key and moves focus to the pane: let it go first.
await s.page.locator(".arrival").waitFor({ state: "detached" });
await settled(s.page, "#main");
await more.press("Enter");
await card.locator(".option-more", { hasText: "is stricter" }).waitFor();
const less = card.getByRole("button", { name: /^Less about zod/ });
assert.equal(await less.getAttribute("aria-expanded"), "true");
assert.equal(await s.page.evaluate(() => document.activeElement && document.activeElement.textContent), "Less", "focus stays on the toggle");
assert.equal(await card.getByLabel("C1: zod").isChecked(), false, "opening a row does not tick it");
// The locked row cannot be ticked.
const locked = card.getByLabel("W1: eslint");
assert.equal(await locked.isDisabled(), true);
assert.equal(await locked.getAttribute("aria-disabled"), "true");
// The counter: two Safe picks in one batch are one round; a Check first row adds one.
await card.getByRole("button", { name: "All safe" }).click();
await card.locator(".option-counter", { hasText: "2 picked, 1 check rounds" }).waitFor();
await card.getByLabel("C1: zod").check();
await card.locator(".option-counter", { hasText: "3 picked, 2 check rounds" }).waitFor();
// The fixed live node beside the footer speaks the same count.
assert.equal(await s.page.locator("#pick-count-live").textContent(), "3 picked, 2 check rounds");
// The opened row stayed open through the redraws the ticks set off.
await card.locator(".option-more", { hasText: "is stricter" }).waitFor();
await card.getByLabel("S2: vite").uncheck();
await card.locator(".option-counter", { hasText: "2 picked, 2 check rounds" }).waitFor();
const got = await sendAndCollect(s);
assert.deepEqual(answerTo(got, "deps").ks.sort(), ["C1", "S1"], "the locked row never reaches the agent");
});