mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 20:45:33 -08:00
Split the web console into by-job files, add page tests and a docs-table test, plus docs
AI Assisted
This commit is contained in:
1 parent
699a827cae
commit
3edb4468a8
121 files changed
+25603
-20145
No files matched your search
@@ -34,8 +34,9 @@ import {
|
||||
STRAY_GRACE_MS,
|
||||
staleSessions,
|
||||
terminalLine,
|
||||
validate,
|
||||
} from "../src/web-console/lib.mjs";
|
||||
} from "../src/web-console/sessions.mjs";
|
||||
import { validate } from "../src/web-console/patches.mjs";
|
||||
import { joinedCss } from "./css-helpers.mjs";
|
||||
import {
|
||||
ROOT,
|
||||
HANDOFFS_DIR,
|
||||
@@ -528,7 +529,7 @@ test("cleanup lists the project's completed specs untouched for 30 days, and rem
|
||||
|
||||
test("User Preferences: wider, its body scrolls and the button bar stays put, without touching dialogs that borrow .looks", () => {
|
||||
const html = fs.readFileSync(path.join(ROOT, "src", "web-console", "public", "index.html"), "utf8");
|
||||
const css = fs.readFileSync(path.join(ROOT, "src", "web-console", "public", "app.css"), "utf8");
|
||||
const css = joinedCss();
|
||||
const dialog = html.match(/<dialog class="modal looks prefs" id="looks-modal"[^>]*>([\s\S]*?)<\/dialog>/);
|
||||
assert.ok(dialog, "the Preferences dialog carries the prefs class");
|
||||
const body = dialog[1].indexOf('<div class="prefs-body">');
|
||||
@@ -722,12 +723,6 @@ test("notes/quick-task.md has a quick-task build tick the Plan tab's steps live"
|
||||
assert.ok(section.includes("- [x] **1.** Step one"));
|
||||
});
|
||||
|
||||
test("the waiting pane points a quick-task build at its Plan tab", () => {
|
||||
const js = fs.readFileSync(path.join(ROOT, "src", "web-console", "public", "app.js"), "utf8");
|
||||
const fn = js.slice(js.indexOf("function renderWaiting("), js.indexOf("function renderNotice("));
|
||||
assert.ok(fn.includes('S.workflow === "quick-task" && docs().find((d) => d.id === "plan")'));
|
||||
});
|
||||
|
||||
test("notes/quick-task.md has the finished quick task offer Back to the dashboard as well as the review", () => {
|
||||
const md = fs.readFileSync(path.join(ROOT, "src", "web-console", "notes", "quick-task.md"), "utf8");
|
||||
const section = md.slice(md.indexOf("## Quick task (`quick-task`)"));
|
||||
@@ -791,3 +786,61 @@ test("an image block under the session's shots folder round-trips, and /shots/ s
|
||||
cli(["stop", "--session", res.json.sid]);
|
||||
}
|
||||
});
|
||||
|
||||
// /app.css is the files under public/styles/ joined in CSS_ORDER (one newline
|
||||
// after each), then the accent rules. The files themselves are never served.
|
||||
test("/app.css is the style files joined in CSS_ORDER with the accent rules last", async () => {
|
||||
const { CSS_ORDER, asset, etagOf } = await import("../src/web-console/static.mjs");
|
||||
const dir = path.join(ROOT, "src", "web-console", "public", "styles");
|
||||
const res = cli(["open", "--workflow", "review", "--no-open"]);
|
||||
const m = res.json.url.match(/^(http:\/\/127\.0\.0\.1:\d+)\/s\/([^/]+)\//);
|
||||
const cookie = cookieFor(m[1], m[2]);
|
||||
try {
|
||||
const r = await fetch(m[1] + "/app.css", { headers: { cookie } });
|
||||
assert.equal(r.status, 200);
|
||||
assert.match(r.headers.get("content-type"), /^text\/css/);
|
||||
const body = await r.text();
|
||||
// One newline between files: each file's own last newline is that one.
|
||||
const joined = CSS_ORDER.map((f) => fs.readFileSync(path.join(dir, f), "utf8").replace(/\n$/, "")).join("\n") + "\n";
|
||||
assert.ok(body.startsWith(joined), "the body opens with the files, in CSS_ORDER, one newline between");
|
||||
const accents = body.slice(joined.length);
|
||||
assert.match(accents, /^\n*\/\* Generated by server\.mjs from palette\.js/, "the accent rules come last");
|
||||
assert.ok(accents.includes(`:root[data-looks-accent="violet"]`));
|
||||
// The tests' helper joins through the server's own function, so the two agree.
|
||||
assert.equal(body, joinedCss() + accents, "joinedCss() plus the accent rules is the body the server returns");
|
||||
// The ETag is a hash of the whole body, so a change to any one file moves it.
|
||||
assert.equal(r.headers.get("etag"), etagOf(Buffer.from(body)));
|
||||
assert.equal(asset("app.css").etag, etagOf(Buffer.from(body)));
|
||||
for (const f of CSS_ORDER) {
|
||||
const text = fs.readFileSync(path.join(dir, f), "utf8").replace(/\n$/, "");
|
||||
assert.notEqual(etagOf(Buffer.from(body.replace(text, text + "\n/* changed */"))), r.headers.get("etag"), `a change to ${f} moves the ETag`);
|
||||
}
|
||||
for (const f of CSS_ORDER) {
|
||||
const own = await fetch(m[1] + "/styles/" + f, { headers: { cookie } });
|
||||
assert.equal(own.status, 404, `/styles/${f} is not served on its own`);
|
||||
await own.arrayBuffer();
|
||||
}
|
||||
} finally {
|
||||
cli(["stop", "--session", res.json.sid]);
|
||||
}
|
||||
});
|
||||
|
||||
// The skills the build writes carry public/styles/ with every file in CSS_ORDER,
|
||||
// and a console started from that tree serves the same /app.css as this one.
|
||||
test("the built skills tree serves the same /app.css as the source console", async (t) => {
|
||||
const { CSS_ORDER, asset } = await import("../src/web-console/static.mjs");
|
||||
const built = path.join(ROOT, "skills", "plan2code", "references", "web-console");
|
||||
// npm test builds first; a bare run of this file may not have.
|
||||
if (!fs.existsSync(path.join(built, "console.mjs"))) return t.skip("skills/ is not built: run npm run build:skills");
|
||||
for (const f of CSS_ORDER) assert.ok(fs.existsSync(path.join(built, "public", "styles", f)), `the build is missing public/styles/${f}`);
|
||||
const out = execFileSync(process.execPath, [path.join(built, "console.mjs"), "open", "--workflow", "review", "--no-open"], { env: ENV, encoding: "utf8", cwd: ROOT });
|
||||
const json = JSON.parse(out.trim().split("\n").pop());
|
||||
const m = json.url.match(/^(http:\/\/127\.0\.0\.1:\d+)\/s\/([^/]+)\//);
|
||||
try {
|
||||
const res = await fetch(m[1] + "/app.css", { headers: { cookie: cookieFor(m[1], m[2]) } });
|
||||
assert.equal(res.status, 200);
|
||||
assert.equal(await res.text(), asset("app.css").body.toString("utf8"));
|
||||
} finally {
|
||||
execFileSync(process.execPath, [path.join(built, "console.mjs"), "stop", "--session", json.sid], { env: ENV, cwd: ROOT });
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user