mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-29 13:21:18 -08:00
Let the app bar's update line use the room the bar has
AI Assisted
This commit is contained in:
1 parent
834b71e82d
commit
97f65edd84
4 files changed
+132
-4
No files matched your search
+113
-1
@@ -9,6 +9,7 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import http from "node:http";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
import { looksFromMessage, terminalFontStep, TERMINAL_FONT_DEFAULT, TERMINAL_FONT_MIN, TERMINAL_FONT_MAX, splitterFraction, splitterAria, terminalTitle, barFit, terminalAnsi, TERMINAL_ANSI, hexToRgba, helloRetryAction, retryLabel, RETRY_AFTER_SECONDS, attentionSignal, commandSegments, plainCommandText, menuStep, pageNotShownView, pageDetailsLine, redactSessionUrl, barNextSteps, continueKeys, defaultRightFraction, folderName, folderPickerRows, pickDefaultAgent, taskbarSwitch, windowTitleFor, deadConsoleAction, loopBanner, loopRunText, loopLocks, loopStopLabels, loopWindowTitle, CONSOLE_ASIDE_BREAKPOINT_PX, NEXT_STEP_LABELS, NEW_RELEASE_COMMAND, STILL_WAITING_MS, STILL_WAITING_TEXT, waitingView, friendlyError, endedView, confirmButtons, trapTab, SHORTCUTS, shortcutAction, shortcutLabel, tipWithShortcut, shortcutFromMessage, clipboardAction, releaseAfterCheck, releaseNotesUrl, reasonSentence, UPDATE_RECHECK_MS } from "../plan2code-app/ui/meter.js";
|
||||
@@ -1135,11 +1136,122 @@ test("barFit drops the model text first, then the status line, and only when the
|
||||
assert.deepEqual(barFit({ available: 500, needed: 800 }), { model: false, status: false }, "no parts measured, none claimed");
|
||||
});
|
||||
|
||||
// The app's ui/ folder over HTTP on a free local port, for a test that needs app.js to run.
|
||||
function serveFolder(dir) {
|
||||
const TYPES = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".woff2": "font/woff2" };
|
||||
const server = http.createServer((req, res) => {
|
||||
const file = path.join(dir, decodeURIComponent(new URL(req.url, "http://x").pathname));
|
||||
if (!file.startsWith(dir) || !fs.existsSync(file) || !fs.statSync(file).isFile()) {
|
||||
res.writeHead(404).end();
|
||||
return;
|
||||
}
|
||||
res.writeHead(200, { "content-type": TYPES[path.extname(file)] || "application/octet-stream" });
|
||||
fs.createReadStream(file).pipe(res);
|
||||
});
|
||||
return new Promise((resolve) => server.listen(0, "127.0.0.1", () => resolve(server)));
|
||||
}
|
||||
|
||||
test("the bar's step text uses the room the row has; model and status drop before it is cut, and its buttons never shrink", async (t) => {
|
||||
if (!findBrowser()) return t.skip("no Chrome or Edge installed");
|
||||
const browser = await launchBrowser();
|
||||
try {
|
||||
const page = await browser.newPage({ viewport: { width: 1800, height: 600 } });
|
||||
// Later start-up steps trip over the stub's nulls; the bar is wired before them,
|
||||
// and "the model alone drops" below shows fitBar() ran.
|
||||
page.on("pageerror", () => {});
|
||||
// Enough of __TAURI__ for app.js to run, so its real fitBar() lays out the row:
|
||||
// every command answers null (platform_info a platform), every window call resolves.
|
||||
await page.addInitScript(() => {
|
||||
const resolved = () => Promise.resolve();
|
||||
const win = new Proxy({}, { get: () => resolved });
|
||||
const known = {
|
||||
core: { invoke: (cmd) => Promise.resolve(cmd === "platform_info" ? { os: "linux" } : null), Channel: class {} },
|
||||
window: { getCurrentWindow: () => win },
|
||||
event: { listen: () => Promise.resolve(() => {}) },
|
||||
};
|
||||
window.__TAURI__ = new Proxy(known, { get: (all, key) => all[key] || new Proxy({}, { get: () => resolved }) });
|
||||
});
|
||||
// app.js is a module, which Chrome will not load from file://: serve the folder.
|
||||
const server = await serveFolder(path.dirname(INDEX_HTML_PATH));
|
||||
t.after(() => server.close());
|
||||
await page.goto(`http://127.0.0.1:${server.address().port}/index.html`, { waitUntil: "networkidle" });
|
||||
await page.evaluate(() => {
|
||||
const show = (id, text) => {
|
||||
const el = document.getElementById(id);
|
||||
el.hidden = false;
|
||||
if (text !== undefined) el.textContent = text;
|
||||
};
|
||||
document.getElementById("agent-none").hidden = true;
|
||||
show("project-menu-button");
|
||||
document.getElementById("project-name").textContent = "plan2code";
|
||||
show("agent-restart");
|
||||
show("agent-menu-button");
|
||||
document.getElementById("agent-name").textContent = "Claude Code";
|
||||
show("agent-model", "opus 5.5 xhigh");
|
||||
document.getElementById("agent-status").textContent = "Working: reading the plan and every phase file";
|
||||
show("next-step");
|
||||
const text = document.getElementById("next-step-text");
|
||||
text.textContent = "npx fetches it quietly first, which can take a minute or two.";
|
||||
text.className = "is-warn is-busy";
|
||||
show("next-step-button", "Update and restart");
|
||||
show("next-step-more", "+1 more");
|
||||
show("next-step-notes");
|
||||
});
|
||||
const settle = () => page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
|
||||
const measure = () =>
|
||||
page.evaluate(() => {
|
||||
const row = document.getElementById("bar-row");
|
||||
const text = document.getElementById("next-step-text");
|
||||
const box = (id) => document.getElementById(id).getBoundingClientRect();
|
||||
const menu = box("app-menu-button");
|
||||
const buttons = ["next-step-button", "next-step-more", "next-step-notes"].map(box);
|
||||
return {
|
||||
noModel: row.classList.contains("no-model"),
|
||||
noStatus: row.classList.contains("no-status"),
|
||||
cut: text.scrollWidth > text.clientWidth,
|
||||
textWidth: text.clientWidth,
|
||||
buttonWidths: buttons.map((b) => Math.round(b.width)),
|
||||
overlap: buttons.some((b) => b.right > menu.left + 0.5),
|
||||
menuInside: menu.width > 0 && menu.right <= row.getBoundingClientRect().right + 0.5,
|
||||
};
|
||||
});
|
||||
await settle();
|
||||
const wide = await measure();
|
||||
assert.deepEqual([wide.noModel, wide.noStatus, wide.cut], [false, false, false], "a wide window shows everything, the whole line included");
|
||||
assert.ok(wide.textWidth > 320, `wider than the old 320px cap (${wide.textWidth}px)`);
|
||||
const seen = new Set();
|
||||
// Down to the app's minimum width (tauri.conf.json minWidth 960).
|
||||
for (let width = 1800; width >= 960; width -= 20) {
|
||||
await page.setViewportSize({ width, height: 600 });
|
||||
await settle();
|
||||
const at = await measure();
|
||||
if (at.cut) assert.ok(at.noModel && at.noStatus, `${width}px: the line is cut only after the model and status dropped`);
|
||||
if (at.noStatus) assert.ok(at.noModel, `${width}px: the model drops before the status`);
|
||||
assert.deepEqual(at.buttonWidths, wide.buttonWidths, `${width}px: the step buttons keep their width`);
|
||||
assert.equal(at.overlap, false, `${width}px: no step button runs under the menu button`);
|
||||
assert.equal(at.menuInside, true, `${width}px: the menu button stays inside the row`);
|
||||
seen.add(`${at.noModel}/${at.noStatus}/${at.cut}`);
|
||||
}
|
||||
assert.ok(seen.has("true/false/false"), `the model alone drops at some width (${[...seen]})`);
|
||||
assert.ok(seen.has("true/true/true"), `the line is cut at the narrowest widths (${[...seen]})`);
|
||||
assert.equal(await page.evaluate(() => getComputedStyle(document.getElementById("next-step-text")).textOverflow), "ellipsis");
|
||||
// Below the minimum, the row runs out at its end as it always did: the text
|
||||
// has shrunk to nothing, but its buttons are never squeezed under the menu.
|
||||
await page.setViewportSize({ width: 400, height: 600 });
|
||||
await settle();
|
||||
const tight = await measure();
|
||||
assert.deepEqual(tight.buttonWidths, wide.buttonWidths, "400px: the step buttons keep their width");
|
||||
assert.equal(tight.overlap, false, "400px: no step button runs under the menu button");
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
});
|
||||
|
||||
test("the top bar collapses instead of scrolling, and +N more is a button that lists the other steps", () => {
|
||||
assert.doesNotMatch(INDEX_HTML, /#bar-row \{[^}]*overflow-x: auto/, "no sideways scrolling row");
|
||||
assert.match(INDEX_HTML, /#bar-row\.no-model #agent-model, #bar-row\.no-status #agent-status \{ display: none; \}/);
|
||||
assert.match(APP_JS, /new ResizeObserver\(scheduleFitBar\)\.observe\(barRowEl\);/);
|
||||
assert.match(APP_JS, /barFit\(\{ available: barRowEl\.clientWidth, needed: barRowEl\.scrollWidth, model, status \}\)/);
|
||||
assert.match(APP_JS, /barFit\(\{ available: barRowEl\.clientWidth, needed: barRowEl\.scrollWidth \+ stepCut, model, status \}\)/);
|
||||
assert.doesNotMatch(APP_JS, /barRowEl\.addEventListener\('scroll'/);
|
||||
assert.match(INDEX_HTML, /<button id="next-step-more" type="button" aria-haspopup="menu" aria-expanded="false" aria-controls="more-menu" hidden><\/button>/);
|
||||
assert.match(INDEX_HTML, /<div id="more-menu" class="bar-dropdown" role="menu"[^>]*tabindex="-1" hidden><\/div>/);
|
||||
|
||||
Reference in new issue
Block a user