mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 04:45:33 -08:00
Make the Ask send self-healing and let the page go quiet before scrolling in tests, so late redraws stop failing them
AI Assisted
This commit is contained in:
1 parent
fc2921c848
commit
959554d127
4 files changed
+51
-26
No files matched your search
@@ -200,6 +200,48 @@ export async function fillBox(locator, text) {
|
||||
}, text);
|
||||
}
|
||||
|
||||
// Waits until nothing inside the element has changed for `quietMs`. A late redraw (state that
|
||||
// rides an event, a scan that lands after the page is drawn) replaces what a test has just
|
||||
// scrolled or opened, and the test then fails on a slow runner: let the page go quiet first.
|
||||
export async function settled(page, selector, quietMs = 500) {
|
||||
await page.locator(selector).first().evaluate(
|
||||
(n, ms) =>
|
||||
new Promise((resolve) => {
|
||||
let timer;
|
||||
const done = () => {
|
||||
observer.disconnect();
|
||||
resolve();
|
||||
};
|
||||
const observer = new MutationObserver(() => {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(done, ms);
|
||||
});
|
||||
observer.observe(n, { subtree: true, childList: true, attributes: true, characterData: true });
|
||||
timer = setTimeout(done, ms);
|
||||
}),
|
||||
quietMs
|
||||
);
|
||||
}
|
||||
|
||||
// Types a message in the Ask box and presses Send. The composer is rebuilt whenever the page's
|
||||
// view of the agent changes, and a box filled just before a rebuild can come back empty with Send
|
||||
// off: fill again until Send is on, and when it never is, fail with the composer's own reason
|
||||
// (its disabled note) instead of a minute-long click timeout.
|
||||
export async function sendAsk(page, text) {
|
||||
const send = page.locator(".ask-composer").getByRole("button", { name: "Send", exact: true });
|
||||
let on = false;
|
||||
for (let attempt = 0; attempt < 6 && !on; attempt++) {
|
||||
await fillBox(page.locator("#ask-input"), text);
|
||||
on = await send.isEnabled().catch(() => false);
|
||||
if (!on) await page.waitForTimeout(500);
|
||||
}
|
||||
if (!on) {
|
||||
const note = await page.locator(".ask-composer .ask-disabled-note").innerText().catch(() => "no disabled note");
|
||||
throw new Error(`Send in the Ask box stayed off after typing ${text.length} characters: ${note}`);
|
||||
}
|
||||
await send.click();
|
||||
}
|
||||
|
||||
// The text a box holds: a Markdown field through its facade, a real input
|
||||
// through its value.
|
||||
export const boxValue = (locator) => locator.first().evaluate((n) => (n.field ? n.field.value : n.value));
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { pageSuite, openSession, itemCard, textOf , fillBox, boxValue} from "./page-test-helpers.mjs";
|
||||
import { pageSuite, openSession, itemCard, textOf , fillBox, boxValue, sendAsk, settled } from "./page-test-helpers.mjs";
|
||||
import { reportedHelper } from "./web-console-test-helpers.mjs";
|
||||
import { readChat } from "../src/web-console/inbox.mjs";
|
||||
|
||||
@@ -56,9 +56,7 @@ async function openAsk(s) {
|
||||
|
||||
// Types a question and presses Send in the Ask pane.
|
||||
async function askQuestion(s, text) {
|
||||
const box = s.page.locator("#ask-input");
|
||||
await fillBox(box, text);
|
||||
await s.page.locator(".ask-composer").getByRole("button", { name: "Send", exact: true }).click();
|
||||
await sendAsk(s.page, text);
|
||||
}
|
||||
|
||||
// What a person sees break: a question typed in Ask that never reaches the
|
||||
@@ -199,22 +197,7 @@ test("a picture thumbnail opens the picview from the note tray and a sent Ask me
|
||||
await aside.locator(".attach-thumb.is-ready").waitFor();
|
||||
// The tray can redraw a moment after an upload lands (the state it rides on arrives by event),
|
||||
// and a redraw after Esc would take the restored focus with the old button: let it go quiet first.
|
||||
await aside.evaluate(
|
||||
(n) =>
|
||||
new Promise((resolve) => {
|
||||
let timer;
|
||||
const done = () => {
|
||||
observer.disconnect();
|
||||
resolve();
|
||||
};
|
||||
const observer = new MutationObserver(() => {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(done, 500);
|
||||
});
|
||||
observer.observe(n, { subtree: true, childList: true, attributes: true });
|
||||
timer = setTimeout(done, 500);
|
||||
})
|
||||
);
|
||||
await settled(s.page, "#aside");
|
||||
|
||||
await aside.locator(".attach-open").click();
|
||||
await s.page.locator("#picview[open]").waitFor();
|
||||
@@ -234,8 +217,7 @@ test("a picture thumbnail opens the picview from the note tray and a sent Ask me
|
||||
const comp = s.page.locator(".ask-composer");
|
||||
await comp.locator('input[type="file"]').setInputFiles({ name: "shot2.png", mimeType: "image/png", buffer: PNG });
|
||||
await comp.locator(".attach-thumb.is-ready").waitFor();
|
||||
await fillBox(box, "See the screenshot.");
|
||||
await s.page.locator(".ask-composer").getByRole("button", { name: "Send", exact: true }).click();
|
||||
await sendAsk(s.page, "See the screenshot.");
|
||||
const sent = s.page.locator(".ask-row.person .attach-thumb").last();
|
||||
await sent.waitFor();
|
||||
await sent.locator(".attach-open").click();
|
||||
|
||||
@@ -11,7 +11,7 @@ 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} from "./page-test-helpers.mjs";
|
||||
import { pageSuite, openSession, tempProject, sendAndCollect, itemCard, scrollTopOf, scrollCard, stylesOf, styleOf , fillBox, boxValue, settled } from "./page-test-helpers.mjs";
|
||||
|
||||
const suite = pageSuite(test);
|
||||
|
||||
@@ -319,6 +319,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" });
|
||||
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");
|
||||
@@ -334,6 +335,7 @@ test("a redraw keeps the place of the dashboard, the waiting screen and the fini
|
||||
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");
|
||||
|
||||
@@ -11,7 +11,7 @@ import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { pageSuite, openSession, itemCard, drawn, textOf, tempProject , fillBox, boxValue} from "./page-test-helpers.mjs";
|
||||
import { pageSuite, openSession, itemCard, drawn, textOf, tempProject , fillBox, boxValue, sendAsk } from "./page-test-helpers.mjs";
|
||||
import { cli, until } from "./web-console-test-helpers.mjs";
|
||||
import { STOP_HANDOFF_REPLY, HOME_REPLY } from "../src/web-console/public/answers.js";
|
||||
import { CHAT_OFFLINE_TEXT } from "../src/web-console/public/chat.js";
|
||||
@@ -757,8 +757,7 @@ test("answers a working agent has not collected bring up the saved-and-waiting l
|
||||
test("a card sent while the agent answers an Ask message says it is answering, and not running only after ten minutes", async (t) => {
|
||||
const s = await openSession(await suite.browser(), { t, workflow: "plan", clock: true, payload: PLAN_QUESTION });
|
||||
await s.page.locator("nav").getByRole("button", { name: "Ask", exact: true }).click();
|
||||
await fillBox(s.page.locator("#ask-input"), "What does the export include?");
|
||||
await s.page.locator(".ask-composer").getByRole("button", { name: "Send", exact: true }).click();
|
||||
await sendAsk(s.page, "What does the export include?");
|
||||
const got = s.wait(10);
|
||||
assert.equal(got.code, 0, `the Ask message was not handed over (wait exit ${got.code})`);
|
||||
await s.page.locator("#views").getByRole("button", { name: /^Questions/ }).click();
|
||||
|
||||
Reference in new issue
Block a user