diff --git a/scripts/page-test-helpers.mjs b/scripts/page-test-helpers.mjs index ca8aeb0..09d17f0 100644 --- a/scripts/page-test-helpers.mjs +++ b/scripts/page-test-helpers.mjs @@ -177,3 +177,21 @@ export async function stylesOf(locator, props) { } } export const styleOf = async (locator, prop) => (await stylesOf(locator, [prop]))[prop]; + +// Fills an answer box on the page, whether it is a plain input or a Markdown +// field (.md-host). fill() cannot reach the editor inside the field's shadow +// root, so the field is driven through its facade: the same "input" path a +// keystroke takes (drafts, staging, counters) runs off the assignment. +export async function fillBox(locator, text) { + const box = locator.first(); + const isField = await box.evaluate((n) => Boolean(n.field)).catch(() => false); + if (!isField) return box.fill(text); + await box.evaluate((n, t) => { + n.field.value = t; + n.field.emitInput(); + }, text); +} + +// 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)); diff --git a/scripts/test-web-console-page-activities.mjs b/scripts/test-web-console-page-activities.mjs index 1ef6e21..414b488 100644 --- a/scripts/test-web-console-page-activities.mjs +++ b/scripts/test-web-console-page-activities.mjs @@ -22,7 +22,7 @@ import fs from "node:fs"; import path from "node:path"; import test from "node:test"; import assert from "node:assert/strict"; -import { pageSuite, openSession, drawn, itemCard } from "./page-test-helpers.mjs"; +import { pageSuite, openSession, drawn, itemCard , boxValue} from "./page-test-helpers.mjs"; import { until, HOME } from "./web-console-test-helpers.mjs"; const suite = pageSuite(test); @@ -783,7 +783,7 @@ test("the die works on a skill screen and on a finished screen", async (t) => { test("arrows and space with the window open neither scroll the page nor reach the answer box behind it", async (t) => { const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION }); - const box = itemCard(s.page, "q1").locator("textarea, input[type=text]").first(); + const box = itemCard(s.page, "q1").locator(".md-host, input[type=text]").first(); await box.click(); await s.page.evaluate(() => { window.__leaked = 0; @@ -796,7 +796,7 @@ test("arrows and space with the window open neither scroll the page nor reach th } const after = await s.page.evaluate(() => ({ y: scrollY, main: document.getElementById("main").scrollTop })); assert.deepEqual(after, before, "nothing scrolled"); - assert.equal(await box.inputValue(), "", "nothing was typed into the answer box"); + assert.equal(await boxValue(box), "", "nothing was typed into the answer box"); assert.equal(await s.page.evaluate(() => window.__leaked), 0, "no game key reached the page"); }); @@ -905,6 +905,9 @@ test("Ghoul Rush's secondary weapon, with real keys in the window: a double tap // The stage code: a practice round in the Foyer, its bag full, straight in. for (const k of ["ArrowUp", "ArrowDown", "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "ArrowLeft", "ArrowRight", "s"]) await s.page.keyboard.press(k); await s.page.keyboard.press(" "); + // The stage's intro card first: fire only moves it on after a moment. + await step(s, 25, 60); + await s.page.keyboard.press(" "); const now = () => s.page.evaluate(() => { const g = window.__ghoul; const r = g.round; @@ -1268,9 +1271,9 @@ test("a game with music has its own Music slider, at its default until moved, ke await s.page.waitForFunction(() => !document.getElementById("activities-modal").open); await openActivities(s, "ghoul"); assert.equal(await slider.isVisible(), true, "Ghoul Rush has one"); - assert.equal(await slider.inputValue(), "65", "at its default"); + assert.equal(await boxValue(slider), "65", "at its default"); assert.equal(await slider.isDisabled(), false); - await slider.fill("80"); + await fillBox(slider, "80"); await s.page.waitForFunction(async () => ((await (await fetch("/looks")).json()).looks || {}).activityMusicGhoul === 80); assert.equal((await pageLooks(s)).activityMusicDrive, 70, "another game keeps its own"); await s.page.keyboard.press("Escape"); @@ -1280,7 +1283,7 @@ test("a game with music has its own Music slider, at its default until moved, ke looks.gameMusic = false; }); await openActivities(s, "ghoul"); - assert.equal(await slider.inputValue(), "80", "kept"); + assert.equal(await boxValue(slider), "80", "kept"); assert.equal(await slider.isDisabled(), true, "Play game music off: dimmed"); assert.match(await s.page.locator("#activities-music").getAttribute("title"), /Play game music/, "and says why"); }); @@ -2401,6 +2404,12 @@ test("Ghoul Rush plays in the real window: its board's shape and Planny big enou // Enter starts a round and has no release: it must not leave fire on. await s.page.keyboard.press("Enter"); assert.equal(await overlay(s), "", "Enter starts a round"); + await step(s, 4, 16); + assert.equal((await you()).phase, "story", "a run opens on the intro story"); + // Holding space for a second skips it, and shoots nothing at it. + await s.page.keyboard.down(" "); + await step(s, 70, 16); + await s.page.keyboard.up(" "); await step(s, 20, 16); let me = await you(); assert.deepEqual([me.fire, me.shots, me.phase], [false, 0, "play"], "the start leaves fire off and shoots nothing"); @@ -2503,10 +2512,10 @@ test("Ghoul Rush plays in the real window: its board's shape and Planny big enou }, 5000); }); -test("the server serves the activities' scripts, golf's seventeen, Light Trails, Bug Hunt, Sunset Drive, Stack Deploy, Bumper Ring's two, Rapids Run's two, Hot Potato's two, Crossing Rush's two, Bounce Road's seven, Ghoul Rush's sixty-six, every game's sound effects and the shared pills included", () => { +test("the server serves the activities' scripts, golf's seventeen, Light Trails, Bug Hunt, Sunset Drive, Stack Deploy, Bumper Ring's two, Rapids Run's two, Hot Potato's two, Crossing Rush's two, Bounce Road's seven, Ghoul Rush's eighty-three, every game's sound effects and the shared pills included", () => { const server = fs.readFileSync(new URL("../src/web-console/static.mjs", import.meta.url), "utf8"); const servable = server.slice(server.indexOf("const SERVABLE = new Set(["), server.indexOf("]);", server.indexOf("const SERVABLE = new Set(["))); - for (const file of ["activities.js", "tones.js", "music.js", "activities/snake.js", "screens/activities.js", "activities/golf.js", "activities/golf-holes.js", "activities/golf-draw.js", "activities/golf-decor.js", "activities/golf-kit.js", "activities/golf-paint.js", "activities/golf-looks.js", "activities/golf-course-pirate.js", "activities/golf-course-cave.js", "activities/golf-course-dino.js", "activities/golf-course-candy.js", "activities/golf-course-space.js", "activities/golf-course-frost.js", "activities/golf-look-dino.js", "activities/golf-look-candy.js", "activities/golf-look-space.js", "activities/golf-look-frost.js", "activities/trails.js", "activities/bugs.js", "activities/drive.js", "activities/stack.js", "activities/bumper.js", "activities/bumper-draw.js", "activities/rapids.js", "activities/rapids-draw.js", "activities/fuse.js", "activities/fuse-draw.js", "activities/hop.js", "activities/hop-draw.js", "activities/bounce.js", "activities/bounce-draw.js", "activities/bounce-roads.js", "activities/bounce-road.js", "activities/bounce-rivals.js", "activities/bounce-scenery.js", "activities/bounce-cars.js", "activities/ghoul.js", "activities/ghoul-draw.js", "activities/ghoul-rooms.js", "activities/ghoul-bones.js", "activities/ghoul-bones-draw.js", "activities/ghoul-graveyard.js", "activities/ghoul-graveyard-draw.js", "activities/ghoul-grounds.js", "activities/ghoul-grounds-draw.js", "activities/ghoul-chapel.js", "activities/ghoul-chapel-draw.js", "activities/ghoul-sanatorium.js", "activities/ghoul-sanatorium-draw.js", "activities/ghoul-village.js", "activities/ghoul-village-draw.js", "activities/ghoul-village-world.js", "activities/ghoul-village-wolf.js", "activities/ghoul-mine.js", "activities/ghoul-mine-draw.js", "activities/ghoul-mine-world.js", "activities/ghoul-mine-tommy.js", "activities/ghoul-cart.js", "activities/ghoul-cart-draw.js", "activities/ghoul-sled.js", "activities/ghoul-sled-draw.js", "activities/ghoul-carnival.js", "activities/ghoul-carnival-draw.js", "activities/ghoul-carnival-world.js", "activities/ghoul-frozen.js", "activities/ghoul-frozen-draw.js", "activities/ghoul-frozen-world.js", "activities/ghoul-flare.js", "activities/ghoul-picker-draw.js", "activities/ghoul-powers.js", "activities/ghoul-arms.js", "activities/ghoul-arms-draw.js", "activities/ghoul-rockets.js", "activities/ghoul-rockets-draw.js", "activities/ghoul-pans.js", "activities/ghoul-sfx-arms.js", "activities/ghoul-run.js", "activities/ghoul-dice.js", "activities/ghoul-dice-draw.js", "activities/ghoul-gameover-draw.js", "activities/ghoul-bonus.js", "activities/ghoul-bonus-draw.js", "activities/ghoul-monsters-draw.js", "activities/pills.js", "activities/snake-sfx.js", "activities/golf-sfx.js", "activities/trails-sfx.js", "activities/bugs-sfx.js", "activities/drive-sfx.js", "activities/stack-sfx.js", "activities/bumper-sfx.js", "activities/rapids-sfx.js", "activities/fuse-sfx.js", "activities/hop-sfx.js", "activities/bounce-sfx.js", "activities/ghoul-sfx.js", "activities/ghoul-sfx-graveyard.js", "activities/ghoul-sfx-grounds.js", "activities/ghoul-sfx-chapel.js", "activities/ghoul-sfx-sanatorium.js", "activities/ghoul-sfx-village.js", "activities/ghoul-sfx-mine.js", "activities/ghoul-sfx-carnival.js", "activities/ghoul-sfx-frozen.js", "activities/ghoul-sfx-sled.js", "activities/ghoul-ride-core.js", "activities/ghoul-ride-scenes.js", "activities/ghoul-ride.js", "activities/ghoul-ride-gfx.js", "activities/ghoul-ride-draw-kinds.js", "activities/ghoul-ride-draw-sets.js", "activities/ghoul-ride-draw-hud.js", "activities/ghoul-ride-draw.js", "activities/ghoul-ride-voices.js", "activities/ghoul-sfx-ride.js"]) { + for (const file of ["activities.js", "tones.js", "music.js", "activities/snake.js", "screens/activities.js", "activities/golf.js", "activities/golf-holes.js", "activities/golf-draw.js", "activities/golf-decor.js", "activities/golf-kit.js", "activities/golf-paint.js", "activities/golf-looks.js", "activities/golf-course-pirate.js", "activities/golf-course-cave.js", "activities/golf-course-dino.js", "activities/golf-course-candy.js", "activities/golf-course-space.js", "activities/golf-course-frost.js", "activities/golf-look-dino.js", "activities/golf-look-candy.js", "activities/golf-look-space.js", "activities/golf-look-frost.js", "activities/trails.js", "activities/bugs.js", "activities/drive.js", "activities/stack.js", "activities/bumper.js", "activities/bumper-draw.js", "activities/rapids.js", "activities/rapids-draw.js", "activities/fuse.js", "activities/fuse-draw.js", "activities/hop.js", "activities/hop-draw.js", "activities/bounce.js", "activities/bounce-draw.js", "activities/bounce-roads.js", "activities/bounce-road.js", "activities/bounce-rivals.js", "activities/bounce-scenery.js", "activities/bounce-cars.js", "activities/ghoul.js", "activities/ghoul-draw.js", "activities/ghoul-rooms.js", "activities/ghoul-bones.js", "activities/ghoul-bones-draw.js", "activities/ghoul-graveyard.js", "activities/ghoul-graveyard-draw.js", "activities/ghoul-grounds.js", "activities/ghoul-grounds-draw.js", "activities/ghoul-chapel.js", "activities/ghoul-chapel-draw.js", "activities/ghoul-sanatorium.js", "activities/ghoul-sanatorium-draw.js", "activities/ghoul-village.js", "activities/ghoul-village-draw.js", "activities/ghoul-village-world.js", "activities/ghoul-village-wolf.js", "activities/ghoul-mine.js", "activities/ghoul-mine-draw.js", "activities/ghoul-mine-world.js", "activities/ghoul-mine-tommy.js", "activities/ghoul-cart.js", "activities/ghoul-cart-draw.js", "activities/ghoul-sled.js", "activities/ghoul-sled-draw.js", "activities/ghoul-gurney.js", "activities/ghoul-gurney-draw.js", "activities/ghoul-banister.js", "activities/ghoul-banister-draw.js", "activities/ghoul-sfx-banister.js", "activities/ghoul-hearse.js", "activities/ghoul-hearse-draw.js", "activities/ghoul-wagon.js", "activities/ghoul-wagon-draw.js", "activities/ghoul-pew.js", "activities/ghoul-pew-draw.js", "activities/ghoul-pew-course.js", "activities/ghoul-pew-world.js", "activities/ghoul-mower.js", "activities/ghoul-mower-draw.js", "activities/ghoul-tray.js", "activities/ghoul-tray-draw.js", "activities/ghoul-carnival.js", "activities/ghoul-carnival-draw.js", "activities/ghoul-carnival-world.js", "activities/ghoul-frozen.js", "activities/ghoul-frozen-draw.js", "activities/ghoul-frozen-world.js", "activities/ghoul-flare.js", "activities/ghoul-bog.js", "activities/ghoul-bog-draw.js", "activities/ghoul-bogboat.js", "activities/ghoul-bogboat-draw.js", "activities/ghoul-picker-draw.js", "activities/ghoul-powers.js", "activities/ghoul-arms.js", "activities/ghoul-arms-draw.js", "activities/ghoul-rockets.js", "activities/ghoul-rockets-draw.js", "activities/ghoul-pans.js", "activities/ghoul-sfx-arms.js", "activities/ghoul-run.js", "activities/ghoul-dice.js", "activities/ghoul-dice-draw.js", "activities/ghoul-gameover-draw.js", "activities/ghoul-intros.js", "activities/ghoul-intro-draw.js", "activities/ghoul-boss-intros.js", "activities/ghoul-bossintro-draw.js", "activities/ghoul-story.js", "activities/ghoul-story-draw.js", "activities/ghoul-sfx-story.js", "activities/ghoul-bonus.js", "activities/ghoul-bonus-draw.js", "activities/ghoul-monsters-draw.js", "activities/pills.js", "activities/snake-sfx.js", "activities/golf-sfx.js", "activities/trails-sfx.js", "activities/bugs-sfx.js", "activities/drive-sfx.js", "activities/stack-sfx.js", "activities/bumper-sfx.js", "activities/rapids-sfx.js", "activities/fuse-sfx.js", "activities/hop-sfx.js", "activities/bounce-sfx.js", "activities/ghoul-sfx.js", "activities/ghoul-sfx-graveyard.js", "activities/ghoul-sfx-grounds.js", "activities/ghoul-sfx-chapel.js", "activities/ghoul-sfx-sanatorium.js", "activities/ghoul-sfx-village.js", "activities/ghoul-sfx-mine.js", "activities/ghoul-sfx-carnival.js", "activities/ghoul-sfx-frozen.js", "activities/ghoul-sfx-sled.js", "activities/ghoul-sfx-gurney.js", "activities/ghoul-sfx-hearse.js", "activities/ghoul-sfx-bog.js", "activities/ghoul-sfx-bogboat.js", "activities/ghoul-sfx-wagon.js", "activities/ghoul-sfx-pew.js", "activities/ghoul-sfx-mower.js", "activities/ghoul-sfx-tray.js", "activities/ghoul-ride-core.js", "activities/ghoul-ride-scenes.js", "activities/ghoul-ride.js", "activities/ghoul-ride-gfx.js", "activities/ghoul-ride-draw-kinds.js", "activities/ghoul-ride-draw-sets.js", "activities/ghoul-ride-draw-hud.js", "activities/ghoul-ride-draw.js", "activities/ghoul-ride-voices.js", "activities/ghoul-sfx-ride.js"]) { assert.ok(servable.includes(`"${file}"`), `SERVABLE includes ${file}`); } }); diff --git a/scripts/test-web-console-page-ask.mjs b/scripts/test-web-console-page-ask.mjs index 3c0046e..8378f68 100644 --- a/scripts/test-web-console-page-ask.mjs +++ b/scripts/test-web-console-page-ask.mjs @@ -9,7 +9,7 @@ import test from "node:test"; import assert from "node:assert/strict"; -import { pageSuite, openSession, itemCard, textOf } from "./page-test-helpers.mjs"; +import { pageSuite, openSession, itemCard, textOf , fillBox, boxValue} from "./page-test-helpers.mjs"; import { reportedHelper } from "./web-console-test-helpers.mjs"; import { readChat } from "../src/web-console/inbox.mjs"; @@ -57,7 +57,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 box.fill(text); + await fillBox(box, text); await s.page.locator(".ask-composer").getByRole("button", { name: "Send", exact: true }).click(); } @@ -76,7 +76,7 @@ test("a Quick question typed in Ask reaches the agent under chat, and the agent' assert.match(got.reply, /^Quick question \(\d+\): Where does the export live\?$/m); // The question is in the pane, and the box is empty for the next one. await s.page.locator(".ask-row.person").getByText("Where does the export live?").waitFor(); - assert.equal(await s.page.locator("#ask-input").inputValue(), ""); + assert.equal(await boxValue(s.page.locator("#ask-input")), ""); s.post({ chat: { replies: [{ id: "r1", re: asked.seq, conversation: 1, md: "It lives in `exports/`." }] } }); const reply = s.page.locator(".ask-row.agent"); @@ -120,7 +120,7 @@ test("an empty Ask offers starters, a click only fills the box, and nothing is s assert.ok((await starters.count()) >= 1, "no starter questions are offered"); const first = (await textOf(starters.first())).trim(); await starters.first().click(); - assert.equal(await box.inputValue(), first, "the starter fills the box"); + assert.equal(await boxValue(box), first, "the starter fills the box"); assert.equal(s.wait(1).code === 0, false, "a starter click sent something"); await s.page.locator(".ask-composer").getByRole("button", { name: "Send", exact: true }).click(); @@ -177,7 +177,7 @@ test("a picture attached to a note uploads, and the send carries it in the note' const aside = s.page.locator("#aside"); await aside.locator('input[type="file"]').setInputFiles({ name: "shot.png", mimeType: "image/png", buffer: PNG }); await aside.locator(".attach-thumb.is-ready").waitFor(); - await aside.locator("#thread-q1").fill("See the screenshot."); + await fillBox(aside.locator("#thread-q1"), "See the screenshot."); await s.page.click("#btn-send"); const got = collect(s); @@ -216,7 +216,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 box.fill("See the screenshot."); + await fillBox(box, "See the screenshot."); await s.page.locator(".ask-composer").getByRole("button", { name: "Send", exact: true }).click(); const sent = s.page.locator(".ask-row.person .attach-thumb").last(); await sent.waitFor(); diff --git a/scripts/test-web-console-page-cards.mjs b/scripts/test-web-console-page-cards.mjs index 72b3b08..903fca3 100644 --- a/scripts/test-web-console-page-cards.mjs +++ b/scripts/test-web-console-page-cards.mjs @@ -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 } from "./page-test-helpers.mjs"; +import { pageSuite, openSession, tempProject, sendAndCollect, itemCard, scrollTopOf, scrollCard, stylesOf, styleOf , fillBox, boxValue} from "./page-test-helpers.mjs"; const suite = pageSuite(test); @@ -29,7 +29,7 @@ test("a text answer typed on the page reaches the agent as it was typed", async workflow: "plan", payload: { items: [{ id: "q1", kind: "text", title: "What to call it", body: "A short name for the export." }] }, }); - await itemCard(s.page, "q1").locator("textarea, input[type=text]").first().fill("audit-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( @@ -39,6 +39,24 @@ test("a text answer typed on the page reaches the agent as it was typed", async 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"); + 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) { @@ -70,7 +88,7 @@ test("every kind of question card sends the answer shape the agent reads", async 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 card.locator("textarea").fill("A shared drive"); + 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"); @@ -78,7 +96,7 @@ test("every kind of question card sends the answer shape the agent reads", async 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 card.locator("textarea").fill("and the IP"); + 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"); @@ -87,11 +105,11 @@ test("every kind of question card sends the answer shape the agent reads", async 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 field.inputValue(), "audit-export"); - await field.fill("Audit Export"); + 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 field.fill("audit-export"); + 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"); @@ -132,7 +150,7 @@ test("every kind of question card sends the answer shape the agent reads", async 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 card.locator("input[type=text]").first().fill("Read the audit log"); + 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]), @@ -183,7 +201,7 @@ test("a sign-off card opens its document, and each verdict reaches the agent", a card = await ask(s, signoff("so2")); await card.getByRole("button", { name: "I want changes" }).click(); - await card.locator("textarea").fill("Keep the header row."); + 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." }); }); @@ -214,15 +232,16 @@ test("a redraw keeps your place: the scroll and the focused field survive an age 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. - const field = itemCard(s.page, "q1").locator("textarea, input[type=text]").first(); - await field.click(); - await field.pressSequentially("audit-ex"); - await field.evaluate((el) => el.setSelectionRange(3, 3)); + // 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("textarea, input[type=text]").first(); - assert.deepEqual(await after.evaluate((el) => [el === document.activeElement, el.value, el.selectionStart]), [true, "audit-ex", 3]); + 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. @@ -280,7 +299,7 @@ test("an answer typed over several lines reaches the agent under its title, neve workflow: "plan", payload: { items: [{ id: "q1", kind: "text", title: "What to call it", body: "A short name for the export." }] }, }); - await itemCard(s.page, "q1").locator("textarea").fill("audit-export\nIdea name: not a heading"); + 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)}`); @@ -456,11 +475,11 @@ test("a list rename is staged as it is typed, so Ctrl+Enter or an agent post nev 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 first.fill("Read the audit log"); + 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 itemCard(s.page, "l1").locator("input.row-title").first().inputValue(), "Read the audit log", "the agent post kept the typed name"); + 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); @@ -483,11 +502,11 @@ test("a send made before the last collection is never shown as still with the ag ); const lock = card.getByText(/Plan2Code is working on it|Waiting for Plan2Code to pick this up/); await lock.waitFor(); - assert.equal(await card.locator("textarea").count(), 0, "before the agent collects it, the card is locked"); + 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("textarea").waitFor(); + await card.locator(".md-host").waitFor(); assert.equal(await lock.count(), 0, "after the collection, it is not shown as sent"); }); @@ -509,7 +528,7 @@ test("a note box over the git board grows no box, and the card flows at its own await git.page.getByRole("tablist").waitFor(); const gitCard = itemCard(git.page, "y1"); await gitCard.waitFor(); - const note = gitCard.locator("textarea").first(); + 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}`); @@ -517,9 +536,9 @@ test("a note box over the git board grows no box, and the card flows at its own // 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"] textarea').first(); + const planBox = plan.page.locator('[data-item="y1"] .md-host').first(); await planBox.waitFor(); - await plan.page.waitForFunction(() => document.querySelector('[data-item="y1"] textarea').offsetHeight >= 160); + 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"); }); @@ -552,9 +571,9 @@ test("Skip this one on an optional card moves on, and the skip reaches the agent 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 itemCard(s.page, "q2").locator("textarea").fill("Ana"); + 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 itemCard(s.page, "q3").locator("textarea").fill("Bo"); + 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 })), @@ -579,7 +598,7 @@ test("a settled card is a record: your answer in words, the options as marks, an 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").count(), 0, "a record has no inputs"); + 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 @@ -587,15 +606,15 @@ test("a settled card is a record: your answer in words, the options as marks, an 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 card.locator("textarea").fill("Ana"); + 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("textarea").count(), 0, "no form while the agent has it"); + 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("textarea").waitFor(); + await card.locator(".md-host").waitFor(); assert.equal(await lock.count(), 0, "the next post gives the card back"); }); @@ -607,11 +626,11 @@ test("Something else in your own words replaces the pick, and picking an option await card.getByLabel("Email").check(); const other = card.getByRole("radio", { name: "Something else, in your own words" }); await other.check(); - await card.locator("textarea.other-text").fill("A shared drive"); + 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 card.locator("textarea.other-text").inputValue(), "A shared drive", "the words survive a switch"); + 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" }); }); @@ -623,10 +642,10 @@ test("Clear on a one-answer question takes back the pick and the words, and a se 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 card.locator("textarea.other-text").fill("A shared drive"); + 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 card.locator("textarea.other-text").inputValue(), "", "the words go too"); + 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")); @@ -642,7 +661,7 @@ test("Clear on a one-answer question takes back the pick and the words, and a se 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 card.getByLabel("Anything to add?").fill("Only on weekdays."); + 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." }); @@ -650,7 +669,7 @@ test("a note's comment field rides along with the answer, typed before or after card = await ask(s, { id: "y2", kind: "confirm", title: "And this", body: "Also?" }); await card.getByRole("button", { name: "No" }).click(); - await card.getByLabel("Anything to add?").fill("Not this quarter."); + 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." }); }); diff --git a/scripts/test-web-console-page-git.mjs b/scripts/test-web-console-page-git.mjs index 17807cd..44d2ed5 100644 --- a/scripts/test-web-console-page-git.mjs +++ b/scripts/test-web-console-page-git.mjs @@ -14,7 +14,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, tempProject, textOf, itemCard, scrollCard } from "./page-test-helpers.mjs"; +import { pageSuite, openSession, tempProject, textOf, itemCard, scrollCard , fillBox} from "./page-test-helpers.mjs"; import { until } from "./web-console-test-helpers.mjs"; const suite = pageSuite(test); @@ -296,10 +296,10 @@ test("Publish names a remote only when there is exactly one", async (t) => { test("over the git board a note box grows with its text, and the no-repo note only points above when a card is there", async (t) => { const s = await openSession(await suite.browser(), { t, workflow: "git", project: gitProject(), payload: READY }); s.post({ items: [confirmCard], agent: { status: "waiting" } }); - const note = itemCard(s.page, "y1").locator("textarea").first(); + const note = itemCard(s.page, "y1").locator(".md-host").first(); await note.waitFor(); const before = await note.evaluate((el) => el.offsetHeight); - await note.fill(Array.from({ length: 8 }, (_, n) => `Line ${n + 1} of a longer note.`).join("\n")); + await fillBox(note, Array.from({ length: 8 }, (_, n) => `Line ${n + 1} of a longer note.`).join("\n")); const after = await note.evaluate((el) => el.offsetHeight); assert.ok(after > before + 40, `the note box grew with its text: ${before} to ${after}`); diff --git a/scripts/test-web-console-page-help.mjs b/scripts/test-web-console-page-help.mjs index 8a528e1..e42c561 100644 --- a/scripts/test-web-console-page-help.mjs +++ b/scripts/test-web-console-page-help.mjs @@ -11,7 +11,7 @@ import fs from "node:fs"; import path from "node:path"; import test from "node:test"; import assert from "node:assert/strict"; -import { pageSuite, openSession, tempProject, textOf, drawn } from "./page-test-helpers.mjs"; +import { pageSuite, openSession, tempProject, textOf, drawn , fillBox} from "./page-test-helpers.mjs"; import { HOME, cli, until } from "./web-console-test-helpers.mjs"; import { HELP_TABS } from "../src/web-console/public/help.js"; import { CATALOG_GROUPS, SKILL_CATALOG } from "../src/web-console/public/answers.js"; @@ -151,7 +151,7 @@ test("a click on Help's backdrop closes it, and a click inside it does not", asy test("Ctrl+Enter does not send while Help is open, and sends once it is closed", async (t) => { savedLooks(t, { welcomeSeen: true }); const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION }); - await s.page.locator('[data-item="q1"]').first().locator("textarea, input[type=text]").first().fill("audit-export"); + await fillBox(s.page.locator('[data-item="q1"]').first().locator(".md-host, input[type=text]").first(), "audit-export"); await openHelp(s); await s.page.keyboard.press("Control+Enter"); await s.page.keyboard.press("Meta+Enter"); diff --git a/scripts/test-web-console-page-send.mjs b/scripts/test-web-console-page-send.mjs index 06bf36a..3162ae8 100644 --- a/scripts/test-web-console-page-send.mjs +++ b/scripts/test-web-console-page-send.mjs @@ -12,7 +12,7 @@ import fs from "node:fs"; import path from "node:path"; import test from "node:test"; import assert from "node:assert/strict"; -import { pageSuite, openSession, tempProject, drawn, sendAndCollect, itemCard } from "./page-test-helpers.mjs"; +import { pageSuite, openSession, tempProject, drawn, sendAndCollect, itemCard , fillBox, boxValue} from "./page-test-helpers.mjs"; import { cli, until, CONSOLE_CLI } from "./web-console-test-helpers.mjs"; import { addImage, createTab, deleteTab, listTabs, readNotepad, removeImage, saveNote } from "../src/web-console/notepads.mjs"; @@ -139,9 +139,9 @@ for (const c of CASES) { assert.equal(sentOf(s.project, tab), null, "Start alone marks nothing"); s.post(BOX); - await until(async () => (await boxOf(s).inputValue()) === TEXT, 10000); + await until(async () => (await boxValue(boxOf(s))) === TEXT, 10000); await until(async () => (await readyPictures(s).count()) === 5, 15000); - assert.equal(await boxOf(s).isEditable(), true, "the filled box stays editable"); + assert.equal(await boxOf(s).locator(".cm-content").isEditable(), true, "the filled box stays editable"); // Still nothing for the agent before Send. const result = path.join(s.session, "result.json"); @@ -167,7 +167,7 @@ test("a pictures-only tab arrives as an empty box with its pictures, and its Sen await startWith(s, main, { chip: "Start from scratch", command: "/plan2code-1-plan", tabName: "Shots" }); s.post(BOX); await until(async () => (await readyPictures(s).count()) === 2, 15000); - assert.equal(await boxOf(s).inputValue(), ""); + assert.equal(await boxValue(boxOf(s)), ""); const got = await sendAndCollect(s); const note = got.actions.find((a) => a.i === "idea" && a.type === "comment"); assert.equal(note && note.images.length, 2, "the pictures go on their own"); @@ -183,7 +183,7 @@ test("a picture deleted between Start and the box is skipped, and the rest still const first = readNotepad(s.project, tab).images[0].id; removeImage(s.project, tab, first); s.post(BOX); - await until(async () => (await boxOf(s).inputValue()) === TEXT, 10000); + await until(async () => (await boxValue(boxOf(s))) === TEXT, 10000); await until(async () => (await readyPictures(s).count()) === 2, 15000); assert.equal(await itemCard(s.page, "idea").locator(".attach-thumb").count(), 2, "no failed or empty slot for the missing one"); }); @@ -194,7 +194,7 @@ test("Back to the dashboard after the box fills takes the box with it, as its di const main = await toTheMenu(s); await startWith(s, main, { chip: "Start from scratch", command: "/plan2code-0-pathfinder", tabName: "Idea" }); s.post(BOX); - await until(async () => (await boxOf(s).inputValue()) === TEXT, 10000); + await until(async () => (await boxValue(boxOf(s))) === TEXT, 10000); await s.page.click("#btn-home"); await s.page.locator("#home-modal[open]").waitFor(); await s.page.click("#home-go"); @@ -212,18 +212,18 @@ test("the box is filled once: a redraw or a reload keeps what the person typed, await startWith(s, main, { chip: "Start from scratch", command: "/plan2code-0-pathfinder", tabName: "Idea" }); s.post(BOX); await until(async () => (await readyPictures(s).count()) === 3, 15000); - await boxOf(s).fill("My own words now."); + await fillBox(boxOf(s), "My own words now."); s.post({ agent: { status: "waiting", activity: "Still here" } }); await s.page.reload({ waitUntil: "domcontentloaded" }); await drawn(s.page); await boxOf(s).waitFor(); - assert.equal(await boxOf(s).inputValue(), "My own words now."); + assert.equal(await boxValue(boxOf(s)), "My own words now."); await until(async () => (await readyPictures(s).count()) === 3, 5000); // A second marked box later in the session is left alone. s.post({ items: [{ id: "idea2", kind: "text", title: "Anything else", fill: "note" }] }); await s.page.locator("#text-idea2").waitFor(); - assert.equal(await s.page.locator("#text-idea2").inputValue(), ""); + assert.equal(await boxValue(s.page.locator("#text-idea2")), ""); }); test("a launch that goes back to the dashboard before Send marks nothing", async (t) => { @@ -232,7 +232,7 @@ test("a launch that goes back to the dashboard before Send marks nothing", async const main = await toTheMenu(s); await startWith(s, main, { chip: "Start from scratch", command: "/plan2code-quick-task", tabName: "Idea" }); s.post(BOX); - await until(async () => (await boxOf(s).inputValue()) === TEXT, 10000); + await until(async () => (await boxValue(boxOf(s))) === TEXT, 10000); const r = cli(["open", "--resume", s.sid, "--no-open", "--workflow", "dashboard"], { cwd: s.project }); assert.equal(r.status, 0, `resume failed: ${r.stderr}`); s.post(MENU); @@ -248,6 +248,6 @@ test("a tab deleted between Start and the box leaves the box empty, with a banne deleteTab(s.project, tab); s.post(BOX); await s.page.locator("#banner", { hasText: "That Notebook tab is gone; the box starts empty." }).waitFor(); - assert.equal(await boxOf(s).inputValue(), ""); + assert.equal(await boxValue(boxOf(s)), ""); assert.equal(await readyPictures(s).count(), 0); }); diff --git a/scripts/test-web-console-page-session.mjs b/scripts/test-web-console-page-session.mjs index d6cfacc..80f0662 100644 --- a/scripts/test-web-console-page-session.mjs +++ b/scripts/test-web-console-page-session.mjs @@ -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 } from "./page-test-helpers.mjs"; +import { pageSuite, openSession, itemCard, drawn, textOf, tempProject , fillBox, boxValue} 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"; @@ -455,8 +455,8 @@ test("the wrapping-up dialog says Done when the stop lands, and stays until clos test("a page that loses its server goes offline, and after a resume it shows the session again with the unsent answer still typed", async (t) => { const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION }); - const field = () => itemCard(s.page, "q1").locator("textarea, input[type=text]").first(); - await field().fill("audit-export"); + const field = () => itemCard(s.page, "q1").locator(".md-host, input[type=text]").first(); + await fillBox(field(), "audit-export"); // Typed, not sent: the page mirrors it to the server's draft.json, which // is what a page on a new port reads back (localStorage is per origin). const draftFile = path.join(s.session, "draft.json"); @@ -478,7 +478,7 @@ test("a page that loses its server goes offline, and after a resume it shows the await s.page.goto(resumed.url, { waitUntil: "domcontentloaded" }); await drawn(s.page); await itemCard(s.page, "q1").getByText("What to call it").first().waitFor(); - assert.equal(await field().inputValue(), "audit-export", "the unsent answer was lost across the resume"); + assert.equal(await boxValue(field()), "audit-export", "the unsent answer was lost across the resume"); assert.equal(await s.page.locator("#planny").evaluate((n) => n.classList.contains("is-gone")), false); }); @@ -528,7 +528,7 @@ test("the quiet, not running and not connected lines offer What to check, openin // Answered and sent, never collected, and nobody listening: the saved line. await s.page.clock.setSystemTime(Date.now()); s.post({ agent: { status: "waiting" } }); - await itemCard(s.page, "q1").locator("textarea, input[type=text]").first().fill("audit-export"); + await fillBox(itemCard(s.page, "q1").locator(".md-host, input[type=text]").first(), "audit-export"); await s.page.click("#btn-send"); await lineSays(s, /^Sent\. Waiting for Plan2Code\./); assert.equal(await whatToCheck(s).count(), 0, "the sent line is plain"); @@ -551,7 +551,7 @@ test("the quiet, not running and not connected lines offer What to check, openin // nothing is listening: the wake-up help shows then, not after three minutes. test("answers a waiting agent never collects bring up the saved-and-waiting line after a minute of silence, not before", async (t) => { const s = await openSession(await suite.browser(), { t, workflow: "plan", clock: true, payload: PLAN_QUESTION }); - await itemCard(s.page, "q1").locator("textarea, input[type=text]").first().fill("audit-export"); + await fillBox(itemCard(s.page, "q1").locator(".md-host, input[type=text]").first(), "audit-export"); await s.page.click("#btn-send"); await lineSays(s, /^Sent\. Waiting for Plan2Code\./); await s.page.clock.fastForward(30_000); @@ -566,7 +566,7 @@ test("answers a waiting agent never collects bring up the saved-and-waiting line // longer quiet allowance it gave itself before it went. test("answers a working agent has not collected bring up the saved-and-waiting line after three minutes, not its long quiet allowance", async (t) => { const s = await openSession(await suite.browser(), { t, workflow: "implement", clock: true, payload: PLAN_QUESTION }); - await itemCard(s.page, "q1").locator("textarea, input[type=text]").first().fill("audit-export"); + await fillBox(itemCard(s.page, "q1").locator(".md-host, input[type=text]").first(), "audit-export"); await s.page.click("#btn-send"); await lineSays(s, /^Sent\. Waiting for Plan2Code\./); // Its last word before it went quiet: working, with half an hour to spare. @@ -585,12 +585,12 @@ 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 s.page.locator("#ask-input").fill("What does the export include?"); + 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(); 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(); - await itemCard(s.page, "q1").locator("textarea, input[type=text]").first().fill("audit-export"); + await fillBox(itemCard(s.page, "q1").locator(".md-host, input[type=text]").first(), "audit-export"); await s.page.click("#btn-send"); await lineSays(s, /^Plan2Code is answering your Ask message\./); await s.page.clock.fastForward(70_000); @@ -610,7 +610,7 @@ test("a card sent while the agent answers an Ask message says it is answering, a // the real state only showing once the page's own timers catch up. test("a Send that finds the server gone says so at once, with the reconnect help", async (t) => { const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION }); - await itemCard(s.page, "q1").locator("textarea, input[type=text]").first().fill("audit-export"); + await fillBox(itemCard(s.page, "q1").locator(".md-host, input[type=text]").first(), "audit-export"); await stopServer(s); await s.page.click("#btn-send"); await s.page.waitForFunction(() => document.getElementById("planny").classList.contains("is-gone"), null, { timeout: 3000 }); @@ -624,7 +624,7 @@ test("a Send the server refuses shows the server's reason", async (t) => { await s.page.route("**/submit", (route) => route.fulfill({ status: 500, contentType: "application/json", body: JSON.stringify({ error: "the disk is full" }) }) ); - await itemCard(s.page, "q1").locator("textarea, input[type=text]").first().fill("audit-export"); + await fillBox(itemCard(s.page, "q1").locator(".md-host, input[type=text]").first(), "audit-export"); await s.page.click("#btn-send"); await s.page.waitForFunction(() => /the disk is full/.test(document.getElementById("banner").textContent), null, { timeout: 3000 }); assert.match(await s.page.locator("#banner").innerText(), /Nothing was lost/); @@ -635,7 +635,7 @@ test("a Send the server refuses as too large says to remove an attachment, not t await s.page.route("**/submit", (route) => route.fulfill({ status: 413, contentType: "application/json", body: JSON.stringify({ error: "too large" }) }) ); - await itemCard(s.page, "q1").locator("textarea, input[type=text]").first().fill("audit-export"); + await fillBox(itemCard(s.page, "q1").locator(".md-host, input[type=text]").first(), "audit-export"); await s.page.click("#btn-send"); await s.page.waitForFunction(() => /remove an attachment/.test(document.getElementById("banner").textContent), null, { timeout: 3000 }); assert.doesNotMatch(await s.page.locator("#banner").innerText(), /try Send again/); @@ -644,7 +644,7 @@ test("a Send the server refuses as too large says to remove an attachment, not t test("a Send lost on the way, with the server still up, says the console is there and to send again", async (t) => { const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION }); await s.page.route("**/submit", (route) => route.abort()); - await itemCard(s.page, "q1").locator("textarea, input[type=text]").first().fill("audit-export"); + await fillBox(itemCard(s.page, "q1").locator(".md-host, input[type=text]").first(), "audit-export"); await s.page.click("#btn-send"); await s.page.waitForFunction(() => /console is still up/.test(document.getElementById("banner").textContent), null, { timeout: 3000 }); assert.equal(await s.page.locator("#planny").evaluate((n) => n.classList.contains("is-gone")), false, "not called gone"); @@ -671,7 +671,7 @@ test("an answered finish offer comes back unanswered on a later finish, once the test("a finished session never puts a sent answer back on its form", async (t) => { const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION }); - await itemCard(s.page, "q1").locator("textarea").fill("audit-export"); + await fillBox(itemCard(s.page, "q1").locator(".md-host"), "audit-export"); await s.page.click("#btn-send"); collect(s); // Collected and left open, then the session ends: nothing more can be sent, @@ -686,8 +686,8 @@ test("a finished session never puts a sent answer back on its form", async (t) = await itemCard(s.page, "q1").waitFor(); const mark = q1.locator(".rail-mark"); assert.notEqual(await mark.getAttribute("title"), "ready to send", "the sent answer came back on the form"); - const box = itemCard(s.page, "q1").locator("textarea"); - assert.notEqual((await box.count()) ? await box.inputValue() : "", "audit-export", "the sent answer is back in its box"); + const box = itemCard(s.page, "q1").locator(".md-host"); + assert.notEqual((await box.count()) ? await boxValue(box) : "", "audit-export", "the sent answer is back in its box"); }); test("the footer keeps its workspace label on the dashboard, and the label opens the Workspace dialog", async (t) => { @@ -735,9 +735,10 @@ test("a workflow page uses its modules: the full footer, the session meter, @ su // 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"); - await box.click(); - await box.pressSequentially("See @"); + const box = itemCard(s.page, "q1").locator(".md-host"); + const ed = box.locator(".cm-content"); + await ed.click(); + await ed.pressSequentially("See @"); await s.page.locator("#mention-pop").waitFor(); assert.match(await textOf(s.page.locator("#mention-pop")), new RegExp(name)); // favicon.js: the person's move puts a bar on the tab icon. @@ -959,7 +960,7 @@ test("under the app, a gone session's review and dashboard fallbacks name the te // finish-style stop instead of the way home. test("the top bar's back triangle asks first, then sends __dashboard with the typed answers and the home reply", async (t) => { const s = await openSession(await suite.browser(), { t, workflow: "plan", payload: PLAN_QUESTION }); - await itemCard(s.page, "q1").locator("textarea, input[type=text]").first().fill("audit-export"); + await fillBox(itemCard(s.page, "q1").locator(".md-host, input[type=text]").first(), "audit-export"); await s.page.click("#btn-home"); const modal = s.page.locator("#home-modal"); await modal.waitFor(); @@ -1032,6 +1033,48 @@ test("Back to default in Preferences returns the theme to follow the system and assert.equal(await s.page.locator('input[name="looks-theme"][value="system"]').isChecked(), true, "the system choice is ticked again"); }); +// What a person sees break: during a build the waiting pane's "follow along" +// link must open the phase file tab (phase-N.md), which carries the same task +// list plus the rest of the file. An older install's tasks doc arriving +// beside it does not take the link back. +test("the build's waiting link opens the phase file tab and prefers it over an old tasks list", async (t) => { + const s = await openSession(await suite.browser(), { + t, + workflow: "implement", + payload: { + headline: { stage: "Phase 3: API endpoints", cleared: 5, total: 11 }, + docs: [{ id: "phasefile", title: "phase-3.md", blocks: [{ id: "body", state: "settled", md: "# Phase 3: API endpoints\n\n- [x] **Task 3.1:** Register the routes\n- [ ] **Task 3.2:** Add paging" }] }], + agent: { status: "working", activity: "Task 6 of 11: deleting a task" }, + }, + }); + const main = s.page.locator("#main"); + const jump = main.locator("button.waiting-jump", { hasText: "phase-3.md" }); + await jump.waitFor(); + s.post({ docs: [{ id: "phase", title: "Phase 3 tasks", blocks: [{ id: "tasks", state: "settled", md: "- [x] **Task 3.1:** Register the routes" }] }] }); + await jump.waitFor(); + await jump.click(); + await s.page.locator(".view-tab[aria-current='true']", { hasText: "phase-3.md" }).waitFor(); + await main.getByRole("heading", { name: "Phase 3: API endpoints" }).waitFor(); +}); + +// What a person sees break: a build still on the old contract keeps its link; +// the posted tasks list opens its own tab. +test("a build still on the old contract keeps its waiting link on the tasks list", async (t) => { + const s = await openSession(await suite.browser(), { + t, + workflow: "implement", + payload: { + headline: { stage: "Phase 3: API endpoints", cleared: 5, total: 11 }, + docs: [{ id: "phase", title: "Phase 3 tasks", blocks: [{ id: "tasks", state: "settled", md: "- [x] **Task 3.1:** Register the routes" }] }], + agent: { status: "working", activity: "Task 6 of 11: deleting a task" }, + }, + }); + const jump = s.page.locator("#main").locator("button.waiting-jump", { hasText: "Phase 3 tasks" }); + await jump.waitFor(); + await jump.click(); + await s.page.locator(".view-tab[aria-current='true']", { hasText: "Phase 3 tasks" }).waitFor(); +}); + // Planny's own spoken line said "close this tab": under the app there is no // tab, only the one window. test("under the app, Planny's finished line says to close the window, not the tab", async (t) => { diff --git a/scripts/test-web-console-page-workspace.mjs b/scripts/test-web-console-page-workspace.mjs index 953ffc7..edccfa6 100644 --- a/scripts/test-web-console-page-workspace.mjs +++ b/scripts/test-web-console-page-workspace.mjs @@ -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, textOf } from "./page-test-helpers.mjs"; +import { pageSuite, openSession, itemCard, textOf , fillBox, boxValue} from "./page-test-helpers.mjs"; import { tempFolder } from "./web-console-test-helpers.mjs"; const suite = pageSuite(test); @@ -33,7 +33,7 @@ function datasetsFolder() { async function addFolderFromDialog(s, dir) { await s.page.locator("#footer-where").click(); await s.page.locator("#workspace-modal[open]").waitFor(); - await s.page.locator("#workspace-path").fill(dir); + await fillBox(s.page.locator("#workspace-path"), dir); await s.page.locator("#workspace-add").click(); await s.page.locator("#workspace-add-msg.is-good").waitFor(); } @@ -53,11 +53,11 @@ test("a folder added in Workspace is listed with its @name, and the next send te assert.equal(await textOf(added.locator(".ws-path")), dir); assert.equal(await added.locator(".ws-original").count(), 0, "only the first folder is the original"); assert.equal(await rows.first().locator(".ws-original").count(), 1); - assert.equal(await s.page.locator("#workspace-path").inputValue(), "", "the path box empties after an add"); + assert.equal(await boxValue(s.page.locator("#workspace-path")), "", "the path box empties after an add"); await s.page.locator("#workspace-done").click(); await s.page.locator("#workspace-modal[open]").waitFor({ state: "detached" }); - await itemCard(s.page, "q1").locator("textarea, input[type=text]").first().fill("audit-export"); + await fillBox(itemCard(s.page, "q1").locator(".md-host, input[type=text]").first(), "audit-export"); await s.page.click("#btn-send"); const got = s.wait(10); assert.equal(got.code, 0, `nothing was sent (wait exit ${got.code})`); @@ -79,18 +79,19 @@ test("an @ in a note offers the workspace's folders, and picking one writes its await s.page.waitForFunction(() => (document.getElementById("footer-where").dataset.key || "").includes("+ 1 folder")); const note = s.page.locator("#aside #thread-q1"); - await note.click(); - await note.pressSequentially("Look in @da"); + const ed = note.locator(".cm-content"); + await ed.click(); + await ed.pressSequentially("Look in @da"); const pop = s.page.locator("#mention-pop"); await pop.waitFor(); const options = pop.locator(".mention-opt"); assert.deepEqual(await options.allTextContents(), ["@datasets"], "only the folder that matches what was typed"); await options.first().click(); await pop.waitFor({ state: "detached" }); - assert.equal(await note.inputValue(), "Look in @datasets "); + assert.equal(await boxValue(note), "Look in @datasets "); // A bare @ lists every folder, the project's own first. - await note.pressSequentially("and @"); + await ed.pressSequentially("and @"); await pop.waitFor(); assert.equal(await pop.locator(".mention-opt").count(), 2); await s.page.keyboard.press("Escape"); diff --git a/scripts/vendor-codemirror.mjs b/scripts/vendor-codemirror.mjs index e9ace59..e08f436 100644 --- a/scripts/vendor-codemirror.mjs +++ b/scripts/vendor-codemirror.mjs @@ -44,11 +44,12 @@ export const HEADER = .join(", ") + " */\n"; -// What the page may import: exactly what notepad-editor.js uses, since an -// entry export is never tree-shaken. indentWithTab is left out on purpose: it -// would trap the Tab key and keyboard users could not leave the editor. +// What the page may import: exactly what notepad-editor.js and md-field.js +// use, since an entry export is never tree-shaken. indentWithTab is left out +// on purpose: it would trap the Tab key and keyboard users could not leave +// the editor. export const ENTRY = `export { Compartment, EditorState } from "@codemirror/state"; -export { Decoration, EditorView, ViewPlugin, WidgetType, keymap } from "@codemirror/view"; +export { Decoration, EditorView, ViewPlugin, WidgetType, keymap, placeholder } from "@codemirror/view"; export { markdown, markdownLanguage } from "@codemirror/lang-markdown"; export { syntaxTree } from "@codemirror/language"; export { defaultKeymap, history, historyKeymap, redo } from "@codemirror/commands"; diff --git a/src/web-console/public/md-field.css b/src/web-console/public/md-field.css new file mode 100644 index 0000000..6e06de0 --- /dev/null +++ b/src/web-console/public/md-field.css @@ -0,0 +1,20 @@ +/* The frame a Markdown field (md-field.js) wears inside its shadow root; + linked beside notepad-editor.css, which carries the mark looks. The page's + own CSS cannot reach in, so a field's size, border and rounding are set + from outside on .md-host, and these rules only fill the host and draw what + CodeMirror needs. The chain is flex rather than height: 100%: a percentage + of a host whose height comes from min-height is never definite, and an + inherited min-height inside a bordered host counts the border twice. The + height: auto resets cut notepad-editor.css's height: 100% rules, which this + sheet is loaded beside and must never inherit sizing from. */ +:host { display: flex; flex-direction: column; height: auto; } +.md-field { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; } +.cm-editor { flex: 1 1 auto; min-height: 0; height: auto; background: transparent; color: var(--ink); font: inherit; } +div.cm-editor.cm-focused { outline: none; } +div.cm-editor .cm-scroller { overflow: auto; font-family: inherit; } +div.cm-editor .cm-content { padding: 10px 12px; caret-color: var(--accent); } +div.cm-editor .cm-cursor { border-left-color: var(--accent); } +div.cm-editor .cm-selectionBackground, +div.cm-editor.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground { background: color-mix(in srgb, var(--accent) 25%, transparent) !important; } +div.cm-editor .cm-line { padding: 0; } +.cm-placeholder { color: var(--ink-3); } diff --git a/src/web-console/public/md-field.js b/src/web-console/public/md-field.js new file mode 100644 index 0000000..c7c8b3e --- /dev/null +++ b/src/web-console/public/md-field.js @@ -0,0 +1,182 @@ +// Plan2Code Web Console - a Markdown answer field, on CodeMirror 6. +// +// Every multiline box the person types into (question answers, the +// something-else and note fields on cards, the Ask composer and its reply +// box, the subagents instruction) is one of these, so Markdown looks like it +// does in the Notebook everywhere: marks hide off the cursor's line, bullets +// become dots, headings grow. Like notepad-editor.js the editor sits in a +// shadow root, where CodeMirror's own