RuneStone 1.0.0

This commit is contained in:
Knotty Wyvern
2026-11-16 04:21:21 -07:00
commit b52eeb14a1
827 changed files with 241421 additions and 0 deletions
+228
View File
@@ -0,0 +1,228 @@
// The native Background feature (src/lib/features/background/): a folder slideshow with mocked host commands, a fade,
// reduced motion, Next and Pause from the command palette, the targets, translucent menus and hover fills with an image,
// opaque menus and hover fills with Background off, a browser window, the settings section in both themes and at
// 360 pixels, the image source, and the first-start migration from seeded plugin settings and from a seeded image.
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import path from "node:path";
import { mockTauri, openPage, outputDir, repoRoot, runSmoke, smokeUrl } from "../_harness/index.mjs";
const SETTINGS_FILE = "runestone.smoke.settings-file";
const PNG = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jM1sAAAAASUVORK5CYII=";
/**
* The host commands of the image folder (src-tauri/src/backgrounds.rs). Each image is a PNG of one color.
* The mock runs this function in the page, so it uses only `test`. `test.state.legacy` is an old plugin package.
*/
function folderCommands(test) {
const snapshot = { profiles: [{ id: "user", name: "User" }], tabs: [], bookmarks: [], settings: { search: "duckduckgo", adblock: true, linkDestination: "internal", personalRules: "", homepage: "", filterLists: [] } };
return {
...test.workspace({ root: "C:\\background-feature", files: { "note.md": "# Note\n\nText.", "other.md": "# Other" } }),
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
"plugin:window|is_maximized": () => false,
spelling_menu_install: () => null,
spelling_menu_uninstall: () => null,
background_folder: () => test.state.folder,
background_choose_folder: () => test.state.folder,
background_clear_folder: () => { test.state.folder = null; return null; },
background_list: () => test.state.names,
background_read: async ({ name }) => {
const [width, height] = name.startsWith("portrait") ? [300, 600] : [640, 400];
const canvas = new OffscreenCanvas(width, height);
const context = canvas.getContext("2d");
context.fillStyle = test.state.colors[name] ?? "#808080"; context.fillRect(0, 0, width, height);
return (await canvas.convertToBlob({ type: "image/png" })).arrayBuffer();
},
background_read_sidecar: () => test.state.sidecar,
background_write_sidecar: ({ contents, expected }) => {
if (expected !== test.state.sidecar) throw "The sidecar file changed. Read it again before you save.";
test.state.sidecar = contents;
return null;
},
background_migrate: () => test.state.folder,
features_legacy: ({ ids }) => test.state.legacy ? ids.filter(id => id === test.state.legacy.id).map(() => test.state.legacy) : [],
browser_connect: () => "background-session",
browser_stop: () => null,
browser_request: () => structuredClone(snapshot),
};
}
const folderState = { folder: "D:\\Backgrounds", names: ["a.png", "b.png", "portrait.png"], colors: { "a.png": "#3a6ea5", "b.png": "#a5533a", "portrait.png": "#4f8a4b" }, sidecar: null };
const image = page => page.evaluate(() => document.body.style.getPropertyValue("--rs-background-image"));
const waitForChange = (page, old) => page.waitForFunction(old => { const value = document.body.style.getPropertyValue("--rs-background-image"); return value.includes("blob:") && value !== old; }, old, { timeout: 15000 });
async function command(page, title) {
await page.keyboard.press("Control+Shift+P");
const palette = page.getByRole("dialog", { name: "Commands", exact: true });
await palette.getByRole("textbox", { name: "Find a command", exact: true }).fill(title);
await palette.getByRole("button").filter({ hasText: title }).first().waitFor();
await page.keyboard.press("Enter");
}
// The open file shows the selection tint, so the hover check uses the other file.
async function hoverBackground(page) {
const row = page.locator('[data-tree-rel="other.md"]');
await row.hover();
return row.evaluate(node => getComputedStyle(node).backgroundColor);
}
async function menuBackground(page) {
await page.locator('[data-tree-rel="note.md"]').click({ button: "right" });
const menu = page.getByRole("menu", { name: "File actions", exact: true });
await menu.waitFor();
const color = await menu.evaluate(node => getComputedStyle(node).backgroundColor);
await page.keyboard.press("Escape");
return color;
}
await runSmoke("features/background", async ({ browser }) => {
const output = await outputDir("features/background");
// A folder slideshow of 2 seconds, from a settings file that exists before the start.
const context = await browser.newContext({ viewport: { width: 1200, height: 820 } });
await mockTauri(context, { state: folderState, commands: folderCommands });
await context.addInitScript(([key, file]) => { if (!localStorage.getItem(key)) localStorage.setItem(key, JSON.stringify(file)); }, [SETTINGS_FILE, {
schema: 1, revision: 1, features: { git: true, background: true },
background: { source: "folder", seconds: 2, order: "name", paused: false, targets: ["app"], overlay: 0.1, position: "center", size: "cover" },
}]);
const main = await openPage(context);
await main.goto(smokeUrl);
await main.locator('[data-tree-rel="note.md"]').waitFor();
await waitForChange(main, "");
const first = await image(main);
assert.match(first, /rgba\(0,0,0,0\.1\)/, "The folder overlay applies");
// The timer shows the next image with a fade of 2 seconds.
await waitForChange(main, first);
assert.equal(await main.locator(".workarea-background").evaluate(node => node.getAnimations({ subtree: true }).length), 1, "The image fades in");
assert.notEqual(await main.evaluate(() => document.body.style.getPropertyValue("--rs-background-previous-image")), "none");
await main.screenshot({ path: path.join(output, "folder-fade.png") });
// Pause keeps the image. Next still works. The same command resumes.
await command(main, "Pause background");
await main.waitForFunction(() => window.__TEST__.settings("background").paused === true);
const paused = await image(main);
await main.waitForTimeout(3000);
assert.equal(await image(main), paused, "A paused slideshow keeps its image");
await command(main, "Next background image");
await waitForChange(main, paused);
// The folder has a portrait image after b.png. It shows in full over a blurred fill.
await main.waitForFunction(() => document.body.style.getPropertyValue("--rs-background-layer-sizes") === "100% 100%, contain, cover", null, { timeout: 15000 });
await main.screenshot({ path: path.join(output, "portrait.png") });
await command(main, "Pause background");
await main.waitForFunction(() => window.__TEST__.settings("background").paused === false);
// Reduced motion: the next image shows without a fade.
await main.emulateMedia({ reducedMotion: "reduce" });
const before = await image(main);
await command(main, "Next background image");
await waitForChange(main, before);
assert.equal(await main.locator(".workarea-background").evaluate(node => node.getAnimations({ subtree: true }).length), 0, "Reduced motion has no fade");
await main.emulateMedia({ reducedMotion: "no-preference" });
// With an image, menus use the surface transparency (82% by default) and blur it. Hover fills and the workspace button
// are a thin veil, so the image stays visible (UI-061).
assert.match(await menuBackground(main), /0\.82/);
const translucent = /(\/ 0\.06\)|, 0\.06\))$/;
assert.match(await hoverBackground(main), translucent, "A hovered row keeps the image visible");
assert.match(await main.locator(".workspace-button").evaluate(node => getComputedStyle(node).backgroundColor), translucent, "The workspace button keeps the image visible");
await main.screenshot({ path: path.join(output, "hover-over-image.png") });
// Targets: only the boards removes the workspace frame. The frame of all boards stays for Project Management.
await main.evaluate(() => window.__TEST__.writeSettings("background", { ...window.__TEST__.settings("background"), targets: ["pm-all"] }));
await main.waitForFunction(() => document.body.style.getPropertyValue("--rs-background-image") === "");
assert.equal(await main.evaluate(async () => !!(await import("/src/lib/plugins/backgrounds.ts")).backgroundHub.get("pm-all")), true);
assert.match(await menuBackground(main), /^rgb\(/, "Without a workspace image, menus are opaque");
assert.match(await hoverBackground(main), /^rgb\(/, "Without a workspace image, hover fills are opaque");
await main.evaluate(() => window.__TEST__.writeSettings("background", { ...window.__TEST__.settings("background"), targets: ["app"] }));
await waitForChange(main, "");
// A browser window shows the background behind a blank tab, and calls only the commands that browser.json grants.
const browserPage = await openPage(context);
await mockTauri(browserPage, { label: "browser-background", state: folderState, commands: folderCommands });
await browserPage.goto(smokeUrl + "/?browserWindow=true");
await browserPage.getByRole("application", { name: "RuneStone browser" }).waitFor();
assert.equal(await browserPage.evaluate(() => window.__TEST__.label), "browser-background");
await browserPage.waitForFunction(() => getComputedStyle(document.querySelector(".workarea-background")).backgroundImage.includes("blob:"), null, { timeout: 15000 });
await browserPage.screenshot({ path: path.join(output, "browser-window.png") });
const granted = new Set(JSON.parse(await readFile(path.join(repoRoot, "src-tauri/capabilities/browser.json"), "utf8")).permissions);
const calls = await browserPage.evaluate(() => [...new Set(window.__TEST__.calls.map(call => call.command))]);
for (const call of calls.filter(name => name.startsWith("background_"))) assert(granted.has(`allow-${call.replaceAll("_", "-")}`), `browser.json grants ${call}`);
assert(calls.includes("background_read"), "The browser window reads the folder images");
await browserPage.close();
// The settings section in both themes and at 360 pixels.
const settings = await openPage(context);
await settings.goto(`${smokeUrl}/?settingsWindow=true`);
await settings.getByRole("button", { name: "Appearance", exact: true }).click();
const section = settings.locator(".background-settings");
await section.waitFor();
assert.equal(await settings.getByRole("button", { name: "Background source", exact: true }).innerText(), "Folder");
assert.equal(await settings.getByRole("textbox", { name: "Image folder", exact: true }).inputValue(), "D:\\Backgrounds");
await settings.getByRole("status").filter({ hasText: "3 images." }).waitFor();
assert.equal(await settings.evaluate(async () => (await import("/src/lib/features/loader.ts")).featureRequested("background")), true, "The section loads the feature module");
assert.equal(await settings.evaluate(() => document.body.style.getPropertyValue("--rs-background-image")), "", "The slideshow does not run in the settings window");
await settings.locator("summary").filter({ hasText: "Per-image appearance" }).click();
await settings.getByRole("button", { name: "Image fit", exact: true }).waitFor();
await settings.waitForFunction(() => !document.querySelector('button[aria-label="Image fit"]').disabled);
for (const theme of ["dark", "light"]) {
await settings.evaluate(async mode => { const { saveAppearance, readAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ ...readAppearance(), theme: "default", mode }); }, theme);
for (const width of [1100, 360]) {
// A tall window shows the whole section, also the targets below the per-image editor.
await settings.setViewportSize({ width, height: 1800 });
await section.scrollIntoViewIfNeeded();
assert.equal(await settings.locator(".content").evaluate(node => node.scrollWidth <= node.clientWidth + 1), true, `No horizontal scroll at ${width} pixels`);
await section.screenshot({ path: path.join(output, `settings-${theme}-${width}.png`) });
}
}
await settings.setViewportSize({ width: 1100, height: 900 });
// The per-image editor saves only the changed values of the selected image.
await settings.getByRole("button", { name: "Image fit", exact: true }).click();
await settings.getByRole("menuitemradio", { name: "Fit", exact: true }).click();
await settings.getByRole("button", { name: "Save image appearance", exact: true }).click();
await settings.getByRole("status").filter({ hasText: "Image appearance saved." }).waitFor();
assert.deepEqual(JSON.parse(await settings.evaluate(() => window.__TEST__.state.sidecar)), { schema: 1, images: { "a.png": { fit: "contain" } } });
// Off applies at once in every window: the image goes away, and menus are opaque again.
await settings.getByRole("button", { name: "Features", exact: true }).click();
await settings.getByRole("switch", { name: "Background", exact: true }).click();
await main.waitForFunction(() => document.body.style.getPropertyValue("--rs-background-image") === "");
assert.match(await menuBackground(main), /^rgb\(/, "With Background off, menus are opaque");
await settings.getByRole("button", { name: "Appearance", exact: true }).click();
await settings.getByText("Background is off. Turn it on in Settings → Features.", { exact: true }).waitFor();
await settings.screenshot({ path: path.join(output, "settings-off.png") });
await settings.getByRole("button", { name: "Features", exact: true }).click();
await settings.getByRole("switch", { name: "Background", exact: true }).click();
await waitForChange(main, "");
assert.deepEqual([...main.errors, ...settings.errors], []);
await context.close();
// The image source and the migration from a seeded image: the old image of Appearance shows without a timer.
const imageContext = await browser.newContext({ viewport: { width: 1000, height: 700 } });
await mockTauri(imageContext, { commands: test => ({ ...test.workspace({ root: "C:\\background-image", files: { "note.md": "# Note" } }), plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }) }) });
await imageContext.addInitScript(image => { if (!localStorage.getItem("runestone.smoke.settings-file")) localStorage.setItem("runestone.appearance", JSON.stringify({ theme: "default", mode: "dark", newTabBackground: { image, overlay: 0.2, position: "top", size: "contain" } })); }, `data:image/png;base64,${PNG}`);
const imagePage = await openPage(imageContext);
await imagePage.goto(smokeUrl);
await waitForChange(imagePage, "");
assert.deepEqual(await imagePage.evaluate(() => window.__TEST__.settings("background")), { source: "image", seconds: 60, order: "name", paused: false, targets: ["app"], overlay: 0, position: "center", size: "cover" });
assert.equal(await imagePage.evaluate(() => document.body.style.getPropertyValue("--rs-background-position")), "top", "The image keeps its own layout");
assert.equal(await imagePage.evaluate(() => window.__TEST__.calls.some(call => call.command === "background_migrate")), false, "Without a plugin grant, no folder migrates");
assert.deepEqual(imagePage.errors, []);
await imageContext.close();
// The migration from the kept settings of an enabled Background Slideshow plugin.
const migrationContext = await browser.newContext({ viewport: { width: 1000, height: 700 } });
const legacy = { id: "runestone.bg-slideshow", installed: true, enabled: true,
settings: { grant: "6f0c7a8e-5b1d-4c2e-9a3f-2d7b8e1c4a90", folder: "D:\\Old", enabled: true, seconds: 7, order: "random", targets: ["app", "pm-all"], overlay: 0.3, position: "top", size: "contain" } };
await mockTauri(migrationContext, { state: { ...folderState, folder: "D:\\Old", legacy }, commands: folderCommands });
const migrated = await openPage(migrationContext);
await migrated.goto(smokeUrl);
await waitForChange(migrated, "");
assert.deepEqual(await migrated.evaluate(() => window.__TEST__.settings("background")), { source: "folder", seconds: 7, order: "random", paused: false, targets: ["app", "pm-all"], overlay: 0.3, position: "top", size: "contain" });
// Each feature gets its switch. Background is on, and Git follows its old package (none here).
const switches = await migrated.evaluate(() => window.__TEST__.settings("features"));
assert.equal(switches.background, true);
assert.equal(switches.git, true);
assert.equal(await migrated.evaluate(() => window.__TEST__.calls.filter(call => call.command === "background_migrate").length), 1);
assert.deepEqual(migrated.errors, []);
await migrationContext.close();
console.log("PASS: folder slideshow, fade, pause and next, portrait fill, reduced motion, menus, targets, browser window, settings section, off switch, image source, and migrations.");
});
+115
View File
@@ -0,0 +1,115 @@
// The native Git feature: the module loads only at first need, the Source control pane stages, unstages, and commits,
// the diff and graph tabs open, errors show in the pane, and Off removes the feature at once.
// It replaces plugins/gitToolbar, which loaded the old Git plugin from its sibling checkout.
import assert from "node:assert/strict";
import path from "node:path";
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("features/git", async ({ page }) => {
const output = await outputDir("features/git");
await mockTauri(page, {
commands: test => {
// The handlers run in the page, so the history is defined here.
const commits = [
{ id: "c3".padEnd(40, "3"), parents: ["c1".padEnd(40, "1"), "c2".padEnd(40, "2")], refs: ["HEAD -> main"], summary: "Merge the feature", author: "Ada", date: "2026-10-29" },
{ id: "c2".padEnd(40, "2"), parents: ["c1".padEnd(40, "1")], refs: ["feature"], summary: "Add the feature", author: "Ada", date: "2026-10-28" },
{ id: "c1".padEnd(40, "1"), parents: [], refs: [], summary: "First commit", author: "Ada", date: "2026-10-27" },
];
test.git = { calls: [], changes: [
{ path: "staged.md", index: "M", worktree: " " },
{ path: "changed.md", index: " ", worktree: "M" },
{ path: "new.md", index: "?", worktree: "?" },
] };
const record = (command, value) => { test.git.calls.push([command, value]); return null; };
return {
...test.workspace({ root: "C:\\git-feature", files: { "staged.md": "A\n", "changed.md": "B\n", "new.md": "C\n" } }),
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
spelling_menu_install: () => null,
"plugin:window|is_maximized": () => false,
git_status: () => ({ available: true, repository: true, branch: "main", changes: test.git.changes }),
git_diff: ({ path, staged }) => `diff --git a/${path} b/${path}\n@@ -1 +1 @@\n-old line\n+new line${staged ? " (staged)" : ""}`,
git_stage: ({ paths }) => record("stage", paths),
git_unstage: ({ paths }) => record("unstage", paths),
git_commit: ({ message }) => record("commit", message),
git_push: () => { throw "The branch has no upstream branch."; },
git_pull: () => record("pull", null),
git_graph: () => ({ commits }),
git_commit_details: ({ commit }) => ({ id: commit, parents: commits.find(item => item.id === commit).parents, author: "Ada", date: "2026-10-29", message: "Details", files: [{ path: "one.md", status: "M" }, { path: "two.md", status: "A" }] }),
git_commit_diff: ({ path }) => `@@ -0,0 +1 @@\n+${path}`,
};
},
});
await page.goto(smokeUrl);
await page.locator('[data-tree-rel="staged.md"]').waitFor();
const loaded = () => page.evaluate(() => performance.getEntriesByType("resource").some(entry => new URL(entry.name).pathname === "/src/lib/features/git/index.ts"));
assert.equal(await loaded(), false, "The Git module does not load before first need");
const sourceControl = page.locator(".header-left").getByRole("button", { name: "Source control", exact: true });
await sourceControl.click();
const pane = page.locator(".source-control");
await pane.getByText("main", { exact: true }).waitFor();
assert.equal(await loaded(), true, "The Source control pane loads the Git module");
await pane.getByRole("heading", { name: "Staged changes (1)", exact: true }).waitFor();
await pane.getByRole("heading", { name: "Unstaged changes (2)", exact: true }).waitFor();
assert.equal(await pane.locator("summary").textContent(), "Changes (3)", "The section title counts all changes");
assert.equal(await pane.getByRole("heading", { name: "Changes (2)", exact: true }).count(), 0, "No group title repeats the section title");
await pane.getByRole("button", { name: "Stage new.md", exact: true }).click();
await page.waitForFunction(() => window.__TEST__.git.calls.some(([command]) => command === "stage"));
assert.deepEqual(await page.evaluate(() => window.__TEST__.git.calls.at(-1)), ["stage", ["new.md"]]);
await pane.getByRole("button", { name: "Unstage all", exact: true }).click();
await page.waitForFunction(() => window.__TEST__.git.calls.some(([command]) => command === "unstage"));
assert.deepEqual(await page.evaluate(() => window.__TEST__.git.calls.at(-1)), ["unstage", ["staged.md"]]);
const message = pane.getByRole("textbox", { name: "Commit message", exact: true });
const commit = pane.getByRole("button", { name: "Commit staged", exact: true });
assert.equal(await commit.isDisabled(), true, "Commit waits for a message");
await message.fill("Write the notes");
await message.press("Control+Enter");
await pane.getByText("Commit created.", { exact: true }).waitFor();
assert.deepEqual(await page.evaluate(() => window.__TEST__.git.calls.at(-1)), ["commit", "Write the notes"]);
await pane.getByRole("button", { name: "Push to the upstream branch", exact: true }).click();
await pane.locator(".notice.error", { hasText: "no upstream branch" }).waitFor();
for (const theme of ["dark", "light"]) {
await page.evaluate(async mode => { const { saveAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ theme: "default", mode }); }, theme);
await page.waitForTimeout(100);
await pane.screenshot({ path: path.join(output, `source-control-${theme}.png`) });
}
await pane.getByRole("button", { name: /^changed\.md — Modified$/ }).click();
const diff = page.locator(".git-diff");
await diff.getByText("changed.md · Working tree", { exact: true }).waitFor();
await diff.locator(".line.add", { hasText: "+new line" }).waitFor();
assert.equal(await diff.locator(".line.remove").count(), 1);
await page.screenshot({ path: path.join(output, "diff-tab.png") });
await pane.getByRole("button", { name: "Show Git graph", exact: true }).click();
const graph = page.locator(".git-graph");
const options = graph.getByRole("option");
await options.first().waitFor();
assert.equal(await options.count(), 3);
assert.equal(await options.first().getAttribute("aria-selected"), "true");
await graph.getByRole("button", { name: "one.md", exact: false }).first().waitFor();
await options.first().focus();
await page.keyboard.press("ArrowDown");
await page.waitForFunction(() => document.activeElement?.getAttribute("aria-selected") === "true" && document.activeElement?.textContent?.includes("Add the feature"));
await graph.locator(".line.add", { hasText: "+one.md" }).waitFor();
assert.equal(await graph.locator("path.boundary").count(), 0, "The full history has no dashed boundary line");
await page.screenshot({ path: path.join(output, "graph-tab.png") });
await page.setViewportSize({ width: 640, height: 720 });
await page.screenshot({ path: path.join(output, "graph-tab-640.png") });
await page.setViewportSize({ width: 1280, height: 800 });
// Off closes the Git tabs and the pane, and removes the button. The feature can start again.
await page.evaluate(() => window.__TEST__.writeSettings("features", { git: false }));
await sourceControl.waitFor({ state: "detached" });
await graph.waitFor({ state: "detached" });
await diff.waitFor({ state: "detached" });
await pane.waitFor({ state: "detached" });
await page.evaluate(() => window.__TEST__.writeSettings("features", { git: true }));
await sourceControl.click();
await pane.getByText("main", { exact: true }).waitFor();
console.log("PASS: Git loads at first need, stages, unstages, commits, shows errors, diffs, and the graph, and Off removes it");
}, { timeout: 60000 });
+317
View File
@@ -0,0 +1,317 @@
// The native PDF Viewer: the file tree marks PDF files without the module, the first PDF tab loads it, and each tab
// renders its pages in one column with selectable text, page controls, zoom, a typed zoom, rotation, scrolling by wheel and
// keyboard, and Reload. It also checks the opaque toolbar and the focus after Ctrl+Tab.
// It also checks two tabs, one worker for each open tab, a protected PDF, a damaged file, Off and On, no network request,
// no text read of a PDF, the owner ID of a tab transfer, a saved tab after a reload, both themes, and a narrow toolbar.
// It replaces tests/browser.mjs of the PDF Viewer plugin.
import assert from "node:assert/strict";
import path from "node:path";
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
import { passwordPdf, samplePdf } from "../../fixtures/pdf/fixtures.mjs";
await runSmoke("features/pdf", async ({ page }) => {
const output = await outputDir("features/pdf");
const origin = new URL(smokeUrl).origin;
const requests = [];
page.on("request", request => {
const url = request.url();
if (!url.startsWith(origin) && !/^(blob|data):/.test(url)) requests.push(url);
});
// Count the PDF.js workers that run (src/lib/features/pdf/engine.ts names them).
await page.addInitScript(() => {
const workers = new Set();
const NativeWorker = window.Worker;
window.Worker = class extends NativeWorker {
constructor(url, options) { super(url, options); if (options?.name === "PDF.js") workers.add(this); }
terminate() { workers.delete(this); super.terminate(); }
};
window.__PDF_WORKERS__ = workers;
});
await mockTauri(page, {
state: { sample: [...samplePdf()], password: [...passwordPdf()] },
commands: test => ({
...test.workspace({ root: "C:\\pdf-feature", files: { "Sample.pdf": "", "Other.PDF": "", "Broken.pdf": "", "Protected.pdf": "", "Slow.pdf": "", "note.md": "# Note\n" } }),
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
spelling_menu_install: () => null,
"plugin:window|is_maximized": () => false,
"plugin:window|destroy": () => null,
workspace_read_bytes: async ({ rel }) => {
if (rel === "Slow.pdf") await new Promise(resolve => setTimeout(resolve, 400));
const bytes = rel === "Broken.pdf" ? [1, 2, 3] : rel === "Protected.pdf" ? test.state.password : test.state.sample;
return new Uint8Array(bytes).buffer;
},
}),
});
// `window.requestClose()` sends the native close request, so the workbench saves its document tabs (tabs/lifecycle does the same).
await page.addInitScript(() => {
const internals = window.__TAURI_INTERNALS__;
const { transformCallback, invoke } = internals;
const callbacks = new Map(), handlers = [];
internals.transformCallback = (callback, once) => { const id = transformCallback(callback, once); callbacks.set(id, callback); return id; };
internals.invoke = (command, args = {}) => {
if (command === "plugin:event|listen" && args.event === "tauri://close-requested") handlers.push(args.handler);
return invoke(command, args);
};
window.requestClose = async () => {
for (const id of handlers) await callbacks.get(id)?.({ event: "tauri://close-requested", id, payload: null });
};
});
await page.goto(smokeUrl);
const row = name => page.locator(`[data-tree-rel="${name}"]`);
await row("Sample.pdf").waitFor();
await row("Sample.pdf").locator(".document-icon").waitFor();
assert.equal(await row("Other.PDF").locator(".document-icon").count(), 1, "Any letter case of the extension is a PDF");
assert.equal(await row("note.md").locator(".document-icon").count(), 0);
const loaded = () => page.evaluate(() => performance.getEntriesByType("resource").some(entry => {
const { pathname } = new URL(entry.name);
return pathname === "/src/lib/features/pdf/index.ts" || pathname.includes("pdfjs-dist");
}));
assert.equal(await loaded(), false, "The file tree marks PDF files without the module or PDF.js");
const workers = () => page.evaluate(() => window.__PDF_WORKERS__.size);
const active = page.locator(".plugin-editor-pane:visible");
const status = active.locator(".pdf-viewer .status");
const rendered = text => status.filter({ hasText: new RegExp(`^${text}$`) }).waitFor();
const button = name => active.getByRole("button", { name, exact: true });
const tab = name => page.getByRole("tab", { name, exact: true });
await row("Sample.pdf").click();
await rendered("Page 1 of 2");
assert.equal(await loaded(), true, "The first PDF tab loads the module");
await active.getByRole("img", { name: "PDF page 1", exact: true }).waitFor();
const sheet = number => active.locator(`.sheet[data-page="${number}"]`);
const scroll = active.locator(".scroll");
const scrollTop = () => scroll.evaluate(node => node.scrollTop);
await sheet(1).locator(".textLayer span").first().waitFor();
assert.match(await sheet(1).locator(".textLayer").innerText(), /Page one text selection/);
assert.equal(await active.locator(".sheet").count(), 2, "Each page has a sheet in the column");
assert.ok(await sheet(1).locator("canvas").evaluate(canvas => {
const data = canvas.getContext("2d").getImageData(0, 0, canvas.width, canvas.height).data;
let colored = 0;
for (let index = 0; index < data.length; index += 4) if (data[index] < 200 && data[index + 2] > 100) colored++;
return colored > 1000;
}), "The page shows its blue rectangle");
assert.equal(await active.getByRole("spinbutton", { name: "Page number", exact: true }).inputValue(), "1");
assert.equal(await button("Fit width").getAttribute("aria-pressed"), "true");
assert.equal(await button("Previous page").isDisabled(), true);
assert.equal(await workers(), 1);
// The toolbar and the status line are opaque, so a background image does not show through them.
for (const selector of [".toolbar", ".status"]) {
assert.match(await active.locator(selector).evaluate(node => getComputedStyle(node).backgroundColor), /^rgb\(/, `${selector} has an opaque fill`);
}
// Both themes. The page stays white paper.
for (const theme of ["dark", "light"]) {
await page.evaluate(async mode => { const { saveAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ theme: "default", mode }); }, theme);
await page.waitForTimeout(100);
await page.screenshot({ path: path.join(output, `viewer-${theme}.png`) });
}
// The tooltip of an icon button shows on keyboard focus.
await button("Rotate clockwise").focus();
await page.getByRole("tooltip", { name: "Rotate clockwise" }).waitFor();
await active.locator(".toolbar").screenshot({ path: path.join(output, "toolbar-focus.png") });
// A narrow window: the toolbar wraps and keeps every control inside the pane.
await page.setViewportSize({ width: 900, height: 720 });
await rendered("Page 1 of 2");
const toolbar = active.locator(".toolbar");
assert.equal(await toolbar.evaluate(node => node.scrollWidth > node.clientWidth), false, "No horizontal scroll in the toolbar");
const box = await toolbar.boundingBox();
for (const control of await toolbar.locator("button, input").all()) {
const item = await control.boundingBox();
assert.ok(item.x >= box.x - 1 && item.x + item.width <= box.x + box.width + 1, "Each control stays inside the toolbar");
}
await page.screenshot({ path: path.join(output, "viewer-900.png") });
await page.setViewportSize({ width: 1440, height: 1000 });
// Pages, zoom, rotation, and the keyboard.
await button("Next page").click();
await rendered("Page 2 of 2");
await active.getByRole("img", { name: "PDF page 2", exact: true }).waitFor();
assert.equal(await button("Next page").isDisabled(), true);
const zoomField = active.getByRole("textbox", { name: "Zoom percent", exact: true });
const zoomText = () => zoomField.inputValue();
const before = await zoomText();
await button("Zoom in").click();
await rendered("Page 2 of 2");
assert.notEqual(await zoomText(), before);
assert.equal(await button("Fit width").getAttribute("aria-pressed"), "false");
await button("Rotate clockwise").click();
await rendered("Page 2 of 2");
assert.ok(await sheet(2).locator("canvas").evaluate(canvas => canvas.width > canvas.height), "A rotated page is wider than high");
for (let turn = 0; turn < 3; turn++) await button("Rotate clockwise").click();
// A typed zoom.
await zoomField.fill("137");
await zoomField.press("Enter");
assert.equal(await zoomText(), "137%");
await zoomField.fill("text");
await zoomField.press("Enter");
assert.equal(await zoomText(), "137%", "Text that is not a number keeps the zoom");
await zoomField.fill("9000");
await zoomField.press("Enter");
assert.equal(await zoomText(), "400%", "A typed zoom stays in the limits");
const unfitted = button("Fit width").and(page.locator('[aria-pressed="false"]'));
await unfitted.waitFor();
const fitted = button("Fit width").and(page.locator('[aria-pressed="true"]'));
const input = active.getByRole("spinbutton", { name: "Page number", exact: true });
await input.fill("1");
await input.press("Enter");
await rendered("Page 1 of 2");
// Page Down and Page Up scroll. At 400%, a page is higher than the tab. They do not jump to the next page, and they do not draw a page again at the ends.
assert.equal(await scrollTop(), 0);
await scroll.focus();
const keepCanvas = number => sheet(number).locator("canvas").evaluate(canvas => { window.__PDF_CANVAS__ = canvas; });
const sameCanvas = number => sheet(number).locator("canvas").evaluate(canvas => window.__PDF_CANVAS__ === canvas);
await keepCanvas(1);
await page.keyboard.press("PageUp");
await page.waitForTimeout(300);
assert.equal(await scrollTop(), 0);
assert.equal(await sameCanvas(1), true, "Page Up at the start does not draw the page again");
await rendered("Page 1 of 2");
await page.keyboard.press("PageDown");
await page.waitForFunction(() => document.activeElement.scrollTop > 0);
await page.waitForTimeout(400);
assert.ok(await scrollTop() < await sheet(2).evaluate(node => node.offsetTop - node.previousElementSibling.offsetTop), "Page Down scrolls less than one page");
await rendered("Page 1 of 2");
assert.equal(await input.inputValue(), "1");
await page.keyboard.press("End");
await rendered("Page 2 of 2");
assert.equal(await input.inputValue(), "2", "The page field follows the scroll position");
await page.waitForTimeout(400);
const end = await scrollTop();
await keepCanvas(2);
await page.keyboard.press("PageDown");
await page.waitForTimeout(300);
assert.equal(await scrollTop(), end);
assert.equal(await sameCanvas(2), true, "Page Down at the end does not draw the page again");
await rendered("Page 2 of 2");
// The wheel shows the other pages.
await page.keyboard.press("Home");
await rendered("Page 1 of 2");
await scroll.hover();
await page.mouse.wheel(0, 5000);
await rendered("Page 2 of 2");
await active.getByRole("img", { name: "PDF page 2", exact: true }).waitFor();
// Ctrl and the wheel change the zoom.
await button("Fit width").click();
await fitted.waitFor();
await scroll.hover();
await page.keyboard.down("Control");
await page.mouse.wheel(0, -100);
await page.keyboard.up("Control");
await unfitted.waitFor();
await button("Fit width").click();
await rendered("Page 2 of 2");
await input.fill("1");
await input.press("Enter");
await rendered("Page 1 of 2");
await input.fill("99");
await input.press("Enter");
await rendered("Page 2 of 2");
assert.equal(await input.inputValue(), "2", "A page number above the count goes to the last page");
// A second tab, one tab for each file, and one worker for each open tab.
await row("Other.PDF").click();
await rendered("Page 1 of 2");
assert.equal(await workers(), 2);
await row("Other.PDF").click();
assert.equal(await tab("Other").count(), 1, "A second open selects the same tab");
// The tabs are New tab, Sample, and Other. Ctrl+Tab and Ctrl+Shift+Tab give the keyboard to the page area of the PDF tab.
const focused = () => page.waitForFunction(() => document.activeElement?.matches(".pdf-viewer .scroll") && document.activeElement.offsetParent !== null);
await page.keyboard.press("Control+Shift+Tab");
await focused();
assert.equal(await tab("Sample").getAttribute("aria-selected"), "true");
await input.fill("1");
await input.press("Enter");
await rendered("Page 1 of 2");
await page.keyboard.press("Control+Tab");
await focused();
await page.keyboard.press("Control+Shift+Tab");
await focused();
assert.equal(await tab("Sample").getAttribute("aria-selected"), "true");
await page.keyboard.press("PageDown");
await page.waitForFunction(() => document.activeElement.scrollTop > 0);
await page.keyboard.press("Control+Tab");
await rendered("Page 1 of 2");
assert.equal(await tab("Other").getAttribute("aria-selected"), "true");
await page.getByRole("button", { name: "Close Other", exact: true }).click();
await tab("Other").waitFor({ state: "detached" });
await page.waitForFunction(() => window.__PDF_WORKERS__.size === 1);
// A tab that closes before its file arrives starts no worker.
await row("Slow.pdf").click();
await tab("Slow").waitFor();
await page.getByRole("button", { name: "Close Slow", exact: true }).click();
await page.waitForTimeout(600);
assert.equal(await workers(), 1);
// A protected PDF.
await row("Protected.pdf").click();
const password = active.getByLabel("PDF password");
await password.waitFor();
await status.filter({ hasText: "This PDF needs a password." }).waitFor();
assert.equal(await password.evaluate(node => node === document.activeElement), true, "The password field takes focus");
await password.fill("incorrect");
await active.getByRole("button", { name: "Unlock", exact: true }).click();
await status.filter({ hasText: "Incorrect password. Try again." }).waitFor();
await page.screenshot({ path: path.join(output, "password.png") });
await password.fill("reader");
await password.press("Enter");
await rendered("Page 1 of 2");
await page.getByRole("button", { name: "Close Protected", exact: true }).click();
await page.waitForFunction(() => window.__PDF_WORKERS__.size === 1);
// A tab that closes while it asks for the password stops its worker.
await row("Protected.pdf").click();
await active.getByLabel("PDF password").waitFor();
await page.getByRole("button", { name: "Close Protected", exact: true }).click();
await page.waitForFunction(() => window.__PDF_WORKERS__.size === 1);
// Reload keeps the page and replaces the worker.
await tab("Sample").click();
await input.fill("2");
await input.press("Enter");
await rendered("Page 2 of 2");
await button("Reload PDF").click();
await rendered("Page 2 of 2");
assert.equal(await workers(), 1);
// A damaged file shows an error, and Reload stays available.
await row("Broken.pdf").click();
await active.getByRole("alert").filter({ hasText: "Cannot display this PDF." }).waitFor();
assert.equal(await button("Reload PDF").isDisabled(), false);
assert.equal(await button("Next page").isDisabled(), true);
await page.screenshot({ path: path.join(output, "damaged.png") });
// Off closes the PDF tabs, stops every worker, and removes the marks. On opens PDF files again.
const switches = await page.evaluate(() => window.__TEST__.settings("features"));
await page.evaluate(value => window.__TEST__.writeSettings("features", value), { ...switches, pdf: false });
await active.locator(".pdf-viewer").waitFor({ state: "detached" });
await page.waitForFunction(() => window.__PDF_WORKERS__.size === 0);
assert.equal(await page.locator(".pdf-viewer").count(), 0);
assert.equal(await tab("Sample").count(), 0);
await row("Sample.pdf").locator(".document-icon").waitFor({ state: "detached" });
await page.evaluate(value => window.__TEST__.writeSettings("features", value), { ...switches, pdf: true });
await row("Sample.pdf").locator(".document-icon").waitFor();
await row("Sample.pdf").click();
await rendered("Page 1 of 2");
assert.equal(await workers(), 1);
const textReads = await page.evaluate(() => window.__TEST__.calls.filter(call => call.command === "workspace_read" && /\.pdf$/i.test(call.args.rel)));
assert.deepEqual(textReads, [], "A PDF is never read as text");
// A tab transfer names the old package and the document type. A reload reopens the saved PDF tab from its path.
const transfer = await page.evaluate(async () => {
const external = await import("/src/lib/plugins/external.ts");
let editors = [];
external.pluginEditors.subscribe(value => { editors = value; })();
const { owner, id, document } = external.pluginTabState(editors.find(view => view.document));
return { owner, id, document };
});
assert.deepEqual(transfer, { owner: "runestone.pdf-viewer", id: "pdf", document: { id: "Sample.pdf", path: "Sample.pdf" } });
await page.evaluate(() => window.requestClose());
await page.reload();
await rendered("Page 1 of 2");
assert.equal(await tab("Sample").count(), 1);
assert.deepEqual(requests, [], "No network request leaves the app");
console.log("PASS: PDF Viewer loads at first need, renders text and pages, scrolls, zooms, rotates, reloads, unlocks, reports a damaged file, keeps one worker per tab, restores its tab, and Off removes it");
}, { timeout: 60000, viewport: { width: 1440, height: 1000 } });
+160
View File
@@ -0,0 +1,160 @@
// The native Project Management feature: no module loads before the first use, the ribbon button opens All tasks,
// the board scope opens a board in the same tab with the board name, a card moves to another list through the host menu,
// and a card edit saves to the hidden card file. Settings → Project Management saves the priority levels and the default
// board, and the ribbon button then opens that board. It also checks both themes and the shared tooltip of the ribbon button.
import assert from "node:assert/strict";
import path from "node:path";
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
const roadmap = "6f4c2a3e-6a0b-4d57-9a3e-1c2b3d4e5f60";
const bugs = "0c18bcdc-f41e-4a31-87f4-87c369f398c1";
const board = id => ({
schema: 1, kind: "board", id,
lists: [
{ id: "todo", name: "To do", status: "todo", collapsed: false },
{ id: "doing", name: "In progress", status: "doing", collapsed: false },
{ id: "done", name: "Done", status: "done", collapsed: false },
],
defaults: { todo: "todo", doing: "doing", done: "done" },
});
const cardPath = id => `.runestone/pm/cards/${Buffer.from(id).toString("hex")}.md`;
const card = (id, title, boardId, order) => [cardPath(id), [
"---", "runestone_pm:", " schema: 1", ` id: ${id}`, " kind: task", ` title: ${title}`, " createdAt: 2026-10-01T00:00:00.000Z",
` order: "${order}"`, " status: todo", " tags: []", " sessions: []", " archived: false", " placements:",
` ${boardId}:`, " listId: todo", ` order: "${order}"`, "---", `Body of ${title}.`, "",
].join("\n")];
const files = Object.fromEntries([
["note.md", "# Note\n"],
[".runestone/pm/.gitignore", "# RuneStone Project Management local data\n*\n"],
[".runestone/pm/cards/.gitignore", "*\n"],
[".runestone/pm/workspace.json", JSON.stringify({ schema: 1, boards: [{ name: "Roadmap", value: board(roadmap) }, { name: "Bugs", value: board(bugs) }] }, null, 2) + "\n"],
card("card-a", "Card A", roadmap, "a"),
card("card-b", "Card B", roadmap, "b"),
card("card-c", "Card C", bugs, "c"),
]);
await runSmoke("features/pm", async ({ browser }) => {
const output = await outputDir("features/pm");
const mock = {
state: { files },
commands: test => {
const workspace = test.workspace({ root: "C:\\pm-feature", files: test.state.files });
test.files = workspace.files;
return {
...workspace,
workspace_read: args => {
if (!workspace.files.has(args.rel) && args.missingOk) return null;
return workspace.workspace_read(args);
},
workspace_create: ({ rel, kind, contents }) => {
if (workspace.files.has(rel)) throw new Error("Destination exists");
if (kind === "file") workspace.files.set(rel, contents ?? "");
return null;
},
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
spelling_menu_install: () => null,
"plugin:window|is_maximized": () => false,
};
},
};
// One context, so the settings window shares the settings file of the main window.
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } });
await mockTauri(context, mock);
const page = await openPage(context);
await page.goto(smokeUrl);
await page.locator('[data-tree-rel="note.md"]').waitFor();
const loaded = () => page.evaluate(() => performance.getEntriesByType("resource").some(entry => {
const { pathname } = new URL(entry.name);
return pathname.startsWith("/src/lib/features/pm/") || /\/deps\/yaml\b|\/node_modules\/yaml\//.test(pathname);
}));
const ribbon = page.locator(".plugin-ribbon").getByRole("button", { name: "Project Management", exact: true });
await ribbon.waitFor();
assert.equal(await loaded(), false, "No Project Management module and no YAML parser load before the first use");
assert.equal(await page.locator('[data-tree-rel="note.md"] .document-icon').count(), 0, "The file tree marks no Markdown file for Project Management");
await ribbon.hover();
await page.getByRole("tooltip").filter({ hasText: /^Project Management$/ }).waitFor();
// The ribbon button opens All tasks: no default board is set.
await ribbon.click();
const pane = page.locator(".plugin-editor-pane:visible");
await pane.locator(".pm-board").waitFor();
await page.getByRole("tab", { name: "Project Management", exact: true }).waitFor();
await page.waitForFunction(() => document.querySelectorAll(".plugin-editor-pane .pm-card").length === 3);
assert.equal(await loaded(), true, "The first use loads the feature");
assert.equal(await ribbon.getAttribute("aria-pressed"), "true", "The ribbon button shows the open view");
// The board scope opens a board in the same tab, with the board name as its title.
await pane.getByRole("button", { name: /^Board scope:/ }).click();
await page.getByRole("menuitemradio", { name: "Roadmap", exact: true }).click();
await page.getByRole("tab", { name: "Roadmap", exact: true }).waitFor();
assert.equal(await page.getByRole("tab", { name: "Project Management", exact: true }).count(), 0, "The board replaces All tasks in its tab");
await page.waitForFunction(() => [...document.querySelectorAll(".plugin-editor-pane .pm-card")].filter(card => card.getClientRects().length).length === 2);
for (const theme of ["dark", "light"]) {
await page.evaluate(async mode => { const { saveAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ theme: "default", mode }); }, theme);
await page.waitForFunction(mode => document.documentElement.dataset.theme === mode, theme);
await page.screenshot({ path: path.join(output, `board-${theme}.png`) });
}
// Move a card to another list through the host action menu. The save writes only that card.
await pane.getByRole("button", { name: "Actions for Card A", exact: true }).click();
await page.getByRole("menuitem", { name: "Move to list", exact: true }).click();
await page.getByRole("menuitemradio", { name: "In progress", exact: true }).click();
await page.waitForFunction(path => /listId: doing/.test(window.__TEST__.files.get(path)), cardPath("card-a"));
const moved = await page.evaluate(path => window.__TEST__.files.get(path), cardPath("card-a"));
assert.match(moved, /status: doing/, "The list status applies to the card");
await pane.locator(".pm-column", { hasText: "In progress" }).locator(".pm-card", { hasText: "Card A" }).waitFor();
// Edit a card in its details and save it.
await pane.getByRole("button", { name: "Card B", exact: true }).click();
const editor = page.locator("dialog.pm-card-editor[open]");
await editor.waitFor();
await editor.getByRole("textbox", { name: "Title", exact: true }).fill("Card B edited");
await page.screenshot({ path: path.join(output, "card-editor-light.png") });
await editor.getByRole("button", { name: "Save card", exact: true }).click();
await editor.waitFor({ state: "detached" });
await page.waitForFunction(path => /title: Card B edited/.test(window.__TEST__.files.get(path)), cardPath("card-b"));
await pane.locator(".pm-card", { hasText: "Card B edited" }).waitFor();
assert.equal(await page.evaluate(path => window.__TEST__.files.get(path), cardPath("card-c")), files[cardPath("card-c")], "Other cards stay unchanged");
await page.screenshot({ path: path.join(output, "board-after-edit-light.png") });
// The board menu shows the same settings component as Settings → Project Management.
await pane.getByRole("button", { name: "More actions", exact: true }).click();
await page.getByRole("menuitem", { name: "Project Management settings", exact: true }).click();
const popup = page.getByRole("dialog", { name: "Project Management settings", exact: true });
await popup.getByRole("button", { name: "Priority levels", exact: true }).waitFor();
await popup.getByRole("button", { name: "Default board", exact: true }).waitFor();
await page.screenshot({ path: path.join(output, "board-settings-light.png") });
await page.keyboard.press("Escape");
await popup.waitFor({ state: "detached" });
// Settings → Project Management in the settings window. Each page of the mock has its own copy of the workspace files.
const settings = await openPage(context);
await settings.goto(`${smokeUrl}/?settingsWindow=true`);
await settings.getByRole("button", { name: "Project Management", exact: true }).click();
await settings.getByRole("heading", { name: "Project Management", exact: true }).waitFor();
const levels = settings.getByRole("button", { name: "Priority levels", exact: true });
assert.equal(await levels.innerText(), "3 — High, Medium, and Low");
await levels.click();
await settings.getByRole("menuitemradio", { name: "5 — Highest through Lowest", exact: true }).click();
await settings.waitForFunction(() => window.__TEST__.settings("projectManagement")?.priorityLevels === 5);
const defaultBoard = settings.getByRole("button", { name: "Default board", exact: true });
await settings.waitForFunction(() => !document.querySelector('[aria-label="Default board"]').disabled);
assert.equal(await defaultBoard.innerText(), "All tasks");
await defaultBoard.click();
assert.deepEqual(await settings.getByRole("menuitemradio").allInnerTexts(), ["All tasks", "Roadmap", "Bugs"]);
await settings.getByRole("menuitemradio", { name: "Roadmap", exact: true }).click();
await settings.waitForFunction(id => JSON.parse(window.__TEST__.files.get(".runestone/pm/workspace.json")).defaultBoardId === id, roadmap);
await settings.screenshot({ path: path.join(output, "settings-light.png") });
await settings.close();
// With a default board, the ribbon button opens it.
await page.evaluate(([board, catalog]) => {
const value = JSON.parse(catalog);
window.__TEST__.files.set(".runestone/pm/workspace.json", JSON.stringify({ ...value, defaultBoardId: board, defaultBoardPath: `pm-board:${board}` }));
}, [bugs, files[".runestone/pm/workspace.json"]]);
await ribbon.click();
await page.getByRole("tab", { name: "Bugs", exact: true }).waitFor();
await page.waitForFunction(() => [...document.querySelectorAll(".plugin-editor-pane .pm-card")].some(card => card.getClientRects().length && card.textContent.includes("Card C")));
assert.deepEqual([...page.errors, ...settings.errors], [], "No page errors");
await context.close();
});
+165
View File
@@ -0,0 +1,165 @@
// Project Management board state: list capacity and its warning (UI-033), compact list collapse (UI-036), the separate
// collapse state of All tasks, new cards from the list composer, a page reload that keeps the state, the fixed default
// board of the workspace (UI-038), and the first board of a workspace without boards.
// Ports list-limits.spec.ts, list-collapse-create.spec.ts, kanban-cards.spec.ts, board-view-state.spec.ts,
// october-cards.spec.ts (default board and onboarding), and host-board-state.smoke.mjs of RuneStone_Project_Management.
import assert from "node:assert/strict";
import path from "node:path";
import { openPage, outputDir, runSmoke } from "../_harness/index.mjs";
import { bugs, catalogPath, column, fileText, loadWorkspace, openBoard, pane, pmFiles, ribbon, roadmap, savedBoards, setTheme, waitForFile } from "../_harness/pmFixture.mjs";
const listOf = async (page, id, listId) => (await savedBoards(page)).find(item => item.value.id === id).value.lists.find(list => list.id === listId);
const width = async locator => (await locator.boundingBox()).width;
await runSmoke("features/pmBoard", async ({ browser, page }) => {
const output = await outputDir("features/pmBoard");
await loadWorkspace(page);
const catalog = await fileText(page, catalogPath);
// All tasks keeps its collapsed lists in the view state of the tab. The board files stay unchanged.
await openBoard(page);
const allTodo = column(page, "To do");
await allTodo.getByRole("button", { name: "Collapse To do", exact: true }).click();
await allTodo.getByRole("button", { name: "Expand To do", exact: true }).waitFor();
assert.equal(await focusedLabel(page), "Expand To do", "Focus stays on the collapse control");
assert(await width(allTodo) < 60, "A collapsed list is a narrow strip");
assert.equal(await allTodo.locator(".pm-card").count(), 0, "A collapsed list hides its cards");
assert.equal(await allTodo.locator(".pm-count").innerText(), "4", "The strip keeps the card count");
await page.waitForFunction(() => JSON.parse(localStorage.getItem("runestone.pm.viewStates") ?? "{}").planning?.collapsedLists?.includes("list:to do"));
assert.equal(await fileText(page, catalogPath), catalog, "A collapse in All tasks does not write the boards");
// UI-033: All tasks has no list actions and no capacity of a merged list.
assert.equal(await pane(page).locator(".pm-list-actions, .pm-list-limit").count(), 0, "All tasks has no list actions and no list limits");
// A board list starts expanded: the board has its own collapse state.
await openBoard(page, "Roadmap");
const todo = column(page, "To do");
assert.equal(await todo.locator(".pm-card").count(), 3);
// UI-033: a limit below the maximum shows the plain indicator.
const review = column(page, "Review");
assert.equal(await review.locator(".pm-count").innerText(), "0/2");
assert.equal(await review.locator(".pm-list-limit").count(), 1);
assert.equal(await review.locator(".pm-list-limit-reached").count(), 0);
// Set a limit through the list menu. At the maximum, the list shows the warning.
await todo.getByRole("button", { name: "List actions for To do", exact: true }).click();
await page.getByRole("menu", { name: "List actions", exact: true }).getByRole("menuitem", { name: "Set list limit", exact: true }).click();
const limitForm = page.getByRole("dialog", { name: "Set list limit", exact: true });
await limitForm.getByLabel("Maximum cards", { exact: true }).fill("3");
await limitForm.getByRole("button", { name: "Save limit", exact: true }).click();
await limitForm.waitFor({ state: "detached" });
await waitForFile(page, catalogPath, /"maxCards": 3/);
assert.equal(await todo.locator(".pm-count").innerText(), "3/3");
const warning = todo.locator(".pm-list-limit-reached");
assert.match(await warning.getAttribute("aria-label"), /^Active cards in To do: 3\. The maximum is 3\. The list is at the limit\.$/);
// The limit warns but does not block: the composer adds a fourth card.
await todo.getByRole("button", { name: "Add a card", exact: true }).click();
const composer = todo.getByRole("textbox", { name: "Card title", exact: true });
await composer.fill("Composer card");
await composer.press("Enter");
await todo.getByRole("button", { name: "Composer card", exact: true }).waitFor();
await page.waitForFunction(() => [...window.__TEST__.files.values()].some(text => /title: Composer card/.test(text)));
await page.waitForFunction(() => document.querySelector('.plugin-editor-pane .pm-column[aria-label="To do"] .pm-count')?.textContent === "4/3");
assert.match(await warning.getAttribute("aria-label"), /The list is over the limit\.$/);
for (const theme of ["dark", "light"]) {
await setTheme(page, theme);
await warning.focus();
await page.getByRole("tooltip").filter({ hasText: /over the limit/ }).waitFor();
await page.screenshot({ path: path.join(output, `limit-warning-${theme}.png`) });
}
// UI-036: a keyboard collapse saves the board file, keeps the count, and keeps focus on the control.
await todo.getByRole("button", { name: "Collapse To do", exact: true }).focus();
await page.keyboard.press("Enter");
await todo.getByRole("button", { name: "Expand To do", exact: true }).waitFor();
assert.equal(await focusedLabel(page), "Expand To do");
await waitForList(page, roadmap, "todo", list => list.collapsed === true);
assert(await width(todo) < 60);
assert.equal(await todo.locator(".pm-count").innerText(), "4/3", "The strip keeps the count and the limit");
assert.equal(await todo.locator(".pm-list-limit-reached").count(), 1, "The strip keeps the warning");
await column(page, "Done").getByRole("button", { name: "Collapse Done", exact: true }).click();
await waitForList(page, roadmap, "done", list => list.collapsed === true);
for (const theme of ["dark", "light"]) {
await setTheme(page, theme);
await page.screenshot({ path: path.join(output, `collapsed-board-${theme}.png`) });
}
// A reload keeps the board state, the limits, and the collapsed lists of All tasks.
await page.reload();
await page.locator('[data-tree-rel="note.md"]').waitFor();
await openBoard(page, "Roadmap");
await column(page, "To do").getByRole("button", { name: "Expand To do", exact: true }).waitFor();
assert.equal(await column(page, "To do").locator(".pm-count").innerText(), "4/3");
await column(page, "Done").getByRole("button", { name: "Expand Done", exact: true }).waitFor();
assert.equal(await column(page, "In progress").getByRole("button", { name: "Collapse In progress", exact: true }).count(), 1);
await column(page, "To do").getByRole("button", { name: "Expand To do", exact: true }).click();
await waitForList(page, roadmap, "todo", list => list.collapsed === false);
await column(page, "To do").getByRole("button", { name: "Composer card", exact: true }).waitFor();
// The limit indicator opens the limit form. An empty field removes the limit.
await column(page, "To do").locator(".pm-list-limit").click();
await limitForm.getByLabel("Maximum cards", { exact: true }).fill("");
await limitForm.getByRole("button", { name: "Save limit", exact: true }).click();
await waitForList(page, roadmap, "todo", list => list.maxCards === undefined);
assert.equal(await column(page, "To do").locator(".pm-list-limit").count(), 0);
assert.equal(await column(page, "To do").locator(".pm-count").innerText(), "4");
await pane(page).locator(".pm-scope").click();
await page.getByRole("menuitemradio", { name: "All tasks", exact: true }).click();
await column(page, "To do").getByRole("button", { name: "Expand To do", exact: true }).waitFor();
// UI-038: the settings save a default board. The ribbon button then opens it.
await pane(page).getByRole("button", { name: "More actions", exact: true }).click();
await page.getByRole("menuitem", { name: "Project Management settings", exact: true }).click();
const settings = page.getByRole("dialog", { name: "Project Management settings", exact: true });
const defaultBoard = settings.getByRole("button", { name: "Default board", exact: true });
await page.waitForFunction(() => document.querySelector('.pm-settings-popup [aria-label="Default board"]')?.disabled === false);
assert.equal(await defaultBoard.innerText(), "All tasks");
await defaultBoard.click();
await page.getByRole("menuitemradio", { name: "Bugs", exact: true }).click();
await waitForFile(page, catalogPath, new RegExp(`"defaultBoardId": "${bugs}"`));
await page.keyboard.press("Escape");
await settings.waitFor({ state: "detached" });
await ribbon(page).click();
await page.getByRole("tab", { name: "Bugs", exact: true, selected: true }).waitFor();
await pane(page).locator(".pm-card", { hasText: "Card C" }).waitFor();
// An unavailable default opens All tasks.
await page.evaluate(rel => {
const value = JSON.parse(window.__TEST__.files.get(rel));
window.__TEST__.files.set(rel, JSON.stringify({ ...value, defaultBoardId: "missing-board", defaultBoardPath: "pm-board:missing-board" }));
}, catalogPath);
await ribbon(page).click();
await page.getByRole("tab", { name: "Project Management", exact: true, selected: true }).waitFor();
await pane(page).locator(".pm-scope-label", { hasText: /^All tasks$/ }).waitFor();
console.log("PASS: list limits, collapse, reload, and the default board");
// UI-038: a workspace without boards shows a visible action that creates the first board.
const context = await browser.newContext({ viewport: { width: 1280, height: 860 } });
const empty = await openPage(context);
await loadWorkspace(empty, pmFiles({ boards: false }));
await openBoard(empty);
const welcome = empty.getByRole("region", { name: "Create your first board", exact: true });
await welcome.waitFor();
await welcome.getByRole("button", { name: "Create your first board", exact: true }).click();
await empty.getByRole("textbox", { name: "Board name", exact: true }).fill("First board");
await empty.getByRole("dialog", { name: "Create board", exact: true }).getByRole("button", { name: "Create board", exact: true }).click();
await empty.getByRole("tab", { name: "First board", exact: true, selected: true }).waitFor();
await waitForFile(empty, catalogPath, /"name": "First board"/);
await empty.screenshot({ path: path.join(output, "first-board-light.png") });
assert.deepEqual(empty.errors, [], "No page errors in the workspace without boards");
await context.close();
}, { timeout: 15000 });
function focusedLabel(page) {
return page.evaluate(() => document.activeElement?.getAttribute("aria-label"));
}
/** Wait until a list of a saved board matches `test`. */
async function waitForList(page, boardId, listId, test) {
for (let attempt = 0; attempt < 50; attempt++) {
if (test(await listOf(page, boardId, listId))) return;
await page.waitForTimeout(100);
}
throw new Error(`The list ${listId} of ${boardId} did not change`);
}
+135
View File
@@ -0,0 +1,135 @@
// Project Management cards: open and edit a card, description drafts with Save, Cancel, and the unsaved marker (UI-037),
// a list choice that saves at once, the creation time, labels, priority, and delete with a confirmation, in both themes.
// Ports october-cards.spec.ts, description-indicator.spec.ts, card-details.spec.ts, labels.spec.ts, delete-card.spec.ts,
// and kanban-editing.spec.ts of RuneStone_Project_Management.
import assert from "node:assert/strict";
import path from "node:path";
import { outputDir, runSmoke } from "../_harness/index.mjs";
import { cardPath, column, deletedPath, draftPath, fileText, focusedName, loadWorkspace, openBoard, pane, setTheme, waitForFile } from "../_harness/pmFixture.mjs";
const draft = async (page, id) => JSON.parse(await fileText(page, draftPath(id)) ?? "null")?.body;
await runSmoke("features/pmCards", async ({ page }) => {
const output = await outputDir("features/pmCards");
await loadWorkspace(page);
await openBoard(page, "Roadmap");
const editor = page.locator("dialog.pm-card-editor[open]");
// The source field is hidden outside edit mode, so select it by its label attribute.
const description = editor.locator('textarea[aria-label="Details (Markdown)"]');
const unsaved = editor.locator(".pm-description-unsaved");
const descriptionAction = name => editor.locator(".pm-description-actions").getByRole("button", { name, exact: true });
const openCard = async title => {
await pane(page).locator(".pm-card-title", { hasText: new RegExp(`^${title}$`) }).click();
await editor.waitFor();
};
const closeCard = async () => {
await editor.getByRole("button", { name: "Close card", exact: true }).click();
await editor.waitFor({ state: "detached" });
};
// The details show the saved creation time.
await openCard("Card A");
const created = editor.locator(".pm-created-at");
assert.match(await created.innerText(), /^Created: (?!Unknown)/);
assert.equal(await created.getAttribute("title"), "2026-10-01T08:30:00.000Z");
assert.equal(await editor.getByRole("textbox", { name: "Title", exact: true }).inputValue(), "Card A");
// UI-037: a description edit stays a draft when the card closes. The saved description does not change.
await editor.getByRole("button", { name: "Edit", exact: true }).click();
await description.fill("Draft text");
await unsaved.waitFor();
assert.equal(await unsaved.innerText(), "Unsaved changes");
await closeCard();
await page.waitForFunction(rel => /"body":"Draft text"/.test(window.__TEST__.files.get(rel) ?? ""), draftPath("card-a"));
assert.match(await fileText(page, cardPath("card-a")), /\nBody of Card A\.\n$/, "Close keeps the saved description");
const marker = pane(page).locator('.pm-card[data-task-id="card-a"] .pm-card-unsaved');
await marker.waitFor();
assert.equal(await marker.innerText(), "Unsaved description");
// The card opens with the saved description and the marker. Edit shows the draft. Cancel restores the saved text.
await openCard("Card A");
await unsaved.waitFor();
assert.equal(await editor.getByRole("region", { name: "Description preview", exact: true }).innerText(), "Body of Card A.");
await editor.getByRole("button", { name: "Edit", exact: true }).click();
assert.equal(await description.inputValue(), "Draft text");
await descriptionAction("Cancel").click();
await unsaved.waitFor({ state: "hidden" });
assert.equal((await description.inputValue()).trim(), "Body of Card A.");
assert.equal(await draft(page, "card-a"), null, "Cancel removes the draft");
// Save commits the description at once. The creation time does not change.
await editor.getByRole("button", { name: "Edit", exact: true }).click();
await description.fill("Saved description");
await descriptionAction("Save").click();
await waitForFile(page, cardPath("card-a"), /\nSaved description\n?$/);
await unsaved.waitFor({ state: "hidden" });
assert.match(await fileText(page, cardPath("card-a")), /createdAt: "?2026-10-01T08:30:00.000Z"?/);
assert.equal(await draft(page, "card-a"), null);
await closeCard();
await marker.waitFor({ state: "hidden" });
// UI-037: a list choice in the details saves at once, before Save card.
await openCard("Shared card");
await editor.getByRole("button", { name: "List", exact: true }).click();
await page.getByRole("menu", { name: "List", exact: true }).getByRole("menuitemradio", { name: "Done", exact: true }).click();
await waitForFile(page, cardPath("card-d"), /listId: done/);
assert.match(await fileText(page, cardPath("card-d")), /status: done/, "The list status applies at once");
await closeCard();
await column(page, "Done").locator(".pm-card-title", { hasText: "Shared card" }).waitFor();
// Title, labels, and priority save with Save card.
await openCard("Card B");
await editor.getByRole("textbox", { name: "Title", exact: true }).fill("Card B edited");
const details = editor.getByRole("group", { name: "Card details", exact: true });
await details.getByRole("button", { name: "Labels", exact: true }).click();
const labels = page.getByRole("dialog", { name: "Choose labels", exact: true });
await labels.getByRole("button", { name: "Add label Bug", exact: true }).click();
await editor.getByRole("button", { name: "Remove label Bug", exact: true }).waitFor({ state: "attached" });
await page.keyboard.press("Escape");
await labels.waitFor({ state: "hidden" });
assert.equal(await editor.count(), 1, "Escape closes only the label choices");
const priority = details.getByRole("button", { name: "Priority", exact: true });
await priority.click();
await page.getByRole("menu", { name: "Choose priority", exact: true }).getByRole("menuitemradio", { name: "High priority", exact: true }).click();
await details.getByRole("button", { name: "High priority", exact: true }).waitFor();
for (const theme of ["dark", "light"]) {
await setTheme(page, theme);
await page.screenshot({ path: path.join(output, `card-details-${theme}.png`) });
}
await editor.getByRole("button", { name: "Save card", exact: true }).click();
await editor.waitFor({ state: "detached" });
await waitForFile(page, cardPath("card-b"), /title: Card B edited/);
const saved = await fileText(page, cardPath("card-b"));
assert.match(saved, /priority: high/);
assert.match(saved, /labels:\n\s+- bug/);
const edited = pane(page).locator('.pm-card[data-task-id="card-b"]');
assert.equal(await edited.locator(".pm-priority").innerText(), "High priority");
assert.equal(await edited.locator(".pm-label-badge").innerText(), "Bug");
assert.match(await fileText(page, cardPath("card-c")), /title: Card C/, "Other cards stay unchanged");
// Delete asks for a confirmation. Cancel keeps the card and returns focus to the card menu.
const actions = pane(page).getByRole("button", { name: "Actions for Card A", exact: true });
const confirm = page.getByRole("dialog", { name: "Delete card", exact: true });
await actions.click();
await page.getByRole("menu", { name: "Card actions", exact: true }).getByRole("menuitem", { name: "Delete card", exact: true }).click();
await confirm.getByRole("heading", { name: "Delete “Card A”?", exact: true }).waitFor();
assert.equal(await focusedName(page), "Cancel", "The safe choice has focus");
for (const theme of ["dark", "light"]) {
await setTheme(page, theme);
await page.screenshot({ path: path.join(output, `delete-card-${theme}.png`) });
}
await confirm.getByRole("button", { name: "Cancel", exact: true }).click();
await confirm.waitFor({ state: "detached" });
assert.equal(await focusedName(page), "Actions for Card A");
assert.equal(await fileText(page, deletedPath), undefined, "Cancel deletes nothing");
await actions.click();
await page.getByRole("menu", { name: "Card actions", exact: true }).getByRole("menuitem", { name: "Delete card", exact: true }).click();
await confirm.getByRole("button", { name: "Delete card", exact: true }).click();
await confirm.waitFor({ state: "detached" });
await waitForFile(page, deletedPath, /"card-a"/);
await pane(page).locator('.pm-card[data-task-id="card-a"]').waitFor({ state: "detached" });
assert.equal(await focusedName(page), "More actions", "Focus moves to the board menu after the card is gone");
assert.equal(await column(page, "To do").locator(".pm-card").count(), 1);
console.log("PASS: card details, description drafts, labels, priority, and delete");
}, { timeout: 15000 });
@@ -0,0 +1,90 @@
// Project Management description drafts with images: an image pasted in an unsaved description survives a close,
// a reopen, and a reload of the card. Save writes the image file. Cancel removes the image data and writes no image file.
import assert from "node:assert/strict";
import { runSmoke } from "../_harness/index.mjs";
import { cardPath, draftPath, fileText, loadWorkspace, openBoard, pane, waitForFile } from "../_harness/pmFixture.mjs";
const imageFile = id => `.runestone/pm/images/${id}.json`;
const draftImagesPath = id => draftPath(id).replace(/\.json$/, ".images.json");
const json = async (page, path) => JSON.parse(await fileText(page, path) ?? "null");
await runSmoke("features/pmDraftImages", async ({ page }) => {
await loadWorkspace(page);
await openBoard(page, "Roadmap");
const editor = page.locator("dialog.pm-card-editor[open]");
const description = editor.locator('textarea[aria-label="Details (Markdown)"]');
const descriptionAction = name => editor.locator(".pm-description-actions").getByRole("button", { name, exact: true });
const openCard = async title => {
await pane(page).locator(".pm-card-title", { hasText: new RegExp(`^${title}$`) }).click();
await editor.waitFor();
await editor.getByRole("button", { name: "Edit", exact: true }).click();
};
const closeCard = async () => {
await editor.getByRole("button", { name: "Close card", exact: true }).click();
await editor.waitFor({ state: "detached" });
};
// Paste a 1 by 1 PNG into the description. Returns the image ID of the new reference.
const pasteImage = async name => {
await description.evaluate((element, name) => {
const png = Uint8Array.from(atob("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg=="), c => c.charCodeAt(0));
const data = new DataTransfer();
data.items.add(new File([png], name, { type: "image/png" }));
element.dispatchEvent(new ClipboardEvent("paste", { bubbles: true, cancelable: true, clipboardData: data }));
}, name);
const reference = new RegExp(`!\\[${name.replace(".", "\\.")}\\]\\(pm-image:([0-9a-f-]{36})\\)`);
await page.waitForFunction(source => new RegExp(source).test(document.querySelector('dialog.pm-card-editor[open] textarea[aria-label="Details (Markdown)"]').value), reference.source);
return reference.exec(await description.inputValue())[1];
};
// Wait until the gallery thumbnail of `name` shows the decoded image.
const imageLoads = async name => {
await page.waitForFunction(alt => {
const image = document.querySelector(`dialog.pm-card-editor[open] .pm-card-images img[alt="${alt}"]`);
return !!image?.complete && image.naturalWidth > 0;
}, name);
assert.equal(await editor.locator(".pm-card-images .pm-error").allInnerTexts().then(texts => texts.join("")), "");
};
// A pasted image stays with the draft when the card closes. The image folder gets no file yet.
await openCard("Card A");
const first = await pasteImage("dot.png");
await imageLoads("dot.png");
await closeCard();
await waitForFile(page, draftPath("card-a"), new RegExp(`pm-image:${first}`));
assert.match((await json(page, draftImagesPath("card-a"))).images[first], /^data:image\/png;base64,iVBOR/);
assert.equal(await fileText(page, imageFile(first)), undefined, "Only a save writes the image file");
assert.match(await fileText(page, cardPath("card-a")), /\nBody of Card A\.\n$/, "Close keeps the saved description");
// The reopened card restores the draft and shows its image. Save writes the image file and ends the draft.
await openCard("Card A");
await imageLoads("dot.png");
assert.match(await description.inputValue(), new RegExp(`pm-image:${first}`));
await descriptionAction("Save").click();
await waitForFile(page, cardPath("card-a"), new RegExp(`!\\[dot\\.png\\]\\(pm-image:${first}\\)`));
assert.match(await fileText(page, imageFile(first)), /"data":"data:image\/png;base64,iVBOR/);
assert.equal((await json(page, draftPath("card-a"))).body, null);
assert.deepEqual((await json(page, draftImagesPath("card-a"))).images, {});
await closeCard();
await openCard("Card A");
await imageLoads("dot.png");
await closeCard();
// The draft saves after the paste, without another edit, so the image survives a reload of the app.
await openCard("Card B");
const second = await pasteImage("second.png");
await waitForFile(page, draftImagesPath("card-b"), new RegExp(second));
await waitForFile(page, draftPath("card-b"), new RegExp(`pm-image:${second}`));
await page.reload();
await page.locator('[data-tree-rel="note.md"]').waitFor();
await openBoard(page, "Roadmap");
await openCard("Card B");
await imageLoads("second.png");
// Cancel removes the draft and its image data. The image folder gets no file.
await descriptionAction("Cancel").click();
await page.waitForFunction(rel => /"body":null/.test(window.__TEST__.files.get(rel) ?? ""), draftPath("card-b"));
assert.deepEqual((await json(page, draftImagesPath("card-b"))).images, {});
assert.equal(await fileText(page, imageFile(second)), undefined);
assert.doesNotMatch(await fileText(page, cardPath("card-b")), /pm-image:/);
await closeCard();
console.log("PASS: a draft image survives a close, a reopen, and a reload. Save writes its file. Cancel leaves no image data.");
});
+70
View File
@@ -0,0 +1,70 @@
// Project Management drag and drop: a card to another list, a card to a new place in its list, and a list to a new
// place on the board. Each drop saves the files. All tasks has no drag and drop (UI-033).
// Ports card-placement.spec.ts, card-transfer.spec.ts (drag part), lists.spec.ts, and kanban-cards.spec.ts
// of RuneStone_Project_Management.
import assert from "node:assert/strict";
import path from "node:path";
import { outputDir, runSmoke } from "../_harness/index.mjs";
import { cardPath, column, fileText, loadWorkspace, openBoard, pane, roadmap, savedBoards, setTheme, waitForFile } from "../_harness/pmFixture.mjs";
const titles = locator => locator.locator(".pm-card-title").allInnerTexts();
const columnIds = page => pane(page).locator("section.pm-column").evaluateAll(nodes => nodes.map(node => node.dataset.listId));
await runSmoke("features/pmDrag", async ({ page }) => {
const output = await outputDir("features/pmDrag");
await loadWorkspace(page);
await openBoard(page, "Roadmap");
/** Drag `source` to a point of `target` with the mouse, and take a screenshot before the drop. */
async function drag(source, target, { x = 0.5, y = 0.5, shot }) {
const from = await source.boundingBox(), to = await target.boundingBox();
await page.mouse.move(from.x + from.width / 2, from.y + Math.min(12, from.height / 2));
await page.mouse.down();
await page.mouse.move(from.x + from.width / 2 + 20, from.y + 20, { steps: 4 });
await page.mouse.move(to.x + to.width * x, to.y + to.height * y, { steps: 8 });
if (shot) {
await pane(page).locator(".pm-drag-preview").waitFor();
await page.screenshot({ path: path.join(output, shot) });
}
await page.mouse.up();
}
// A card goes to another list. The list status applies, and only that card file changes.
await setTheme(page, "dark");
const cardC = await fileText(page, cardPath("card-c"));
await drag(pane(page).locator('.pm-card[data-task-id="card-a"]'), column(page, "In progress"), { y: 0.3, shot: "card-drag-dark.png" });
await waitForFile(page, cardPath("card-a"), /listId: doing/);
assert.match(await fileText(page, cardPath("card-a")), /status: doing/);
assert.deepEqual(await titles(column(page, "In progress")), ["Card A"]);
assert.deepEqual(await titles(column(page, "To do")), ["Card B", "Shared card"]);
assert.equal(await fileText(page, cardPath("card-c")), cardC, "Other cards stay unchanged");
assert.equal(await pane(page).locator(".pm-drag-preview, .pm-drop-target").count(), 0, "The drop removes the drag preview");
// A card goes above another card of the same list.
await drag(pane(page).locator('.pm-card[data-task-id="card-d"]'), pane(page).locator('.pm-card[data-task-id="card-b"]'), { y: 0.2 });
await page.waitForFunction(() => [...document.querySelectorAll('.plugin-editor-pane .pm-column[aria-label="To do"] .pm-card-title')].map(node => node.textContent).join() === "Shared card,Card B");
const order = async id => /\n {6}order: "([^"]+)"/.exec(await fileText(page, cardPath(id)))[1];
assert(await order("card-d") < await order("card-b"), "The saved order puts Shared card first");
// A list goes to a new place: the grip of Done goes to the left half of To do.
await setTheme(page, "light");
const grip = column(page, "Done").getByRole("button", { name: "Move list Done", exact: true });
await drag(grip, column(page, "To do"), { x: 0.2, y: 0.2, shot: "list-drag-light.png" });
await page.waitForFunction(() => [...document.querySelectorAll(".plugin-editor-pane .pm-column")].map(node => node.dataset.listId).join() === "done,todo,doing,review");
assert.deepEqual((await savedBoards(page)).find(item => item.value.id === roadmap).value.lists.map(list => list.id), ["done", "todo", "doing", "review"]);
assert.deepEqual(await columnIds(page), ["done", "todo", "doing", "review"]);
await page.screenshot({ path: path.join(output, "after-drops-light.png") });
// UI-033: All tasks has no drag and drop. Its cards and lists cannot move.
await pane(page).locator(".pm-scope").click();
await page.getByRole("menuitemradio", { name: "All tasks", exact: true }).click();
await pane(page).locator(".pm-scope-label", { hasText: /^All tasks$/ }).waitFor();
await pane(page).locator(".pm-card").first().waitFor();
assert.deepEqual([...new Set(await pane(page).locator(".pm-card").evaluateAll(nodes => nodes.map(node => node.draggable)))], [false]);
assert.equal(await pane(page).locator(".pm-list-grip").count(), 0);
const before = await fileText(page, cardPath("card-b"));
await drag(pane(page).locator('.pm-card[data-task-id="card-b"]'), column(page, "Done"), {});
await page.waitForTimeout(300);
assert.equal(await fileText(page, cardPath("card-b")), before, "A drag in All tasks changes nothing");
console.log("PASS: card and list drag and drop, and no drag in All tasks");
}, { timeout: 15000 });
+66
View File
@@ -0,0 +1,66 @@
// Project Management card images: a GIF copied in a web browser keeps its original file. A failed download keeps the still copy.
import assert from "node:assert/strict";
import { runSmoke } from "../_harness/index.mjs";
import { cardPath, fileText, loadWorkspace, openBoard, pane, waitForFile } from "../_harness/pmFixture.mjs";
const imageFile = id => `.runestone/pm/images/${id}.json`;
await runSmoke("features/pmImages", async ({ page }) => {
await loadWorkspace(page);
await openBoard(page, "Roadmap");
await pane(page).locator(".pm-card-title", { hasText: /^Card A$/ }).click();
const editor = page.locator("dialog.pm-card-editor[open]");
await editor.waitFor();
await editor.getByRole("button", { name: "Edit", exact: true }).click();
const description = editor.locator('textarea[aria-label="Details (Markdown)"]');
await description.fill("");
// A browser puts a still PNG on the clipboard, with HTML that names the original GIF.
async function pasteWebImage(src) {
await description.evaluate((element, src) => {
const png = Uint8Array.from(atob("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg=="), c => c.charCodeAt(0));
const data = new DataTransfer();
data.items.add(new File([png], "image.png", { type: "image/png" }));
data.setData("text/html", `<html><body><!--StartFragment--><img src="${src}"/><!--EndFragment--></body></html>`);
element.dispatchEvent(new ClipboardEvent("paste", { bubbles: true, cancelable: true, clipboardData: data }));
}, src);
}
const reference = name => new RegExp(`!\\[${name.replace(".", "\\.")}\\]\\(pm-image:([0-9a-f-]{36})\\)`);
await pasteWebImage("https://media.example.com/cat.gif");
await page.waitForFunction(() => /!\[image\.gif\]\(pm-image:/.test(document.querySelector('dialog.pm-card-editor[open] textarea[aria-label="Details (Markdown)"]').value));
const download = await page.evaluate(() => window.__TEST__.calls.find(call => call.command === "workspace_download_image").args);
assert.equal(download.url, "https://media.example.com/cat.gif");
// When the download fails, the card gets the still PNG.
await pasteWebImage("https://offline.example.com/cat.gif");
await page.waitForFunction(() => /!\[image\.png\]\(pm-image:/.test(document.querySelector('dialog.pm-card-editor[open] textarea[aria-label="Details (Markdown)"]').value));
await editor.getByText("The website refused the original image, so RuneStone added only its first frame.", { exact: false }).waitFor();
// The RuneStone browser keeps the bytes of the image that it copied. The website gets no second request.
await page.evaluate(async () => (await import("/src/lib/workspace/copiedImage.ts")).keepCopiedImage("https://offline.example.com/copied.gif",
Promise.resolve("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7")));
const downloads = () => page.evaluate(() => window.__TEST__.calls.filter(call => call.command === "workspace_download_image").length);
const downloadsBefore = await downloads();
await pasteWebImage("https://offline.example.com/copied.gif");
await page.waitForFunction(() => (document.querySelector('dialog.pm-card-editor[open] textarea[aria-label="Details (Markdown)"]').value.match(/!\[image\.gif\]/g) || []).length === 2);
assert.equal(await downloads(), downloadsBefore);
assert.equal(await editor.getByText("The website refused the original image", { exact: false }).count(), 0, "A kept original clears the message");
// An empty file from a browser drag gives a message, not the size limit.
await description.evaluate(element => {
const data = new DataTransfer();
data.items.add(new File([], "viprsr188.gif", { type: "image/gif" }));
element.dispatchEvent(new DragEvent("drop", { bubbles: true, cancelable: true, dataTransfer: data }));
});
await editor.getByText("The image file is empty.", { exact: false }).waitFor();
assert.equal(await editor.getByText("Use an image between 1 byte and 50 MiB.").count(), 0);
await editor.locator(".pm-description-actions").getByRole("button", { name: "Save", exact: true }).click();
await waitForFile(page, cardPath("card-a"), /pm-image:.*\n?[\s\S]*pm-image:/);
const body = await fileText(page, cardPath("card-a"));
const gif = reference("image.gif").exec(body)[1], png = reference("image.png").exec(body)[1];
assert.match(await fileText(page, imageFile(gif)), /"data":"data:image\/gif;base64,R0lGOD/);
assert.match(await fileText(page, imageFile(png)), /"data":"data:image\/png;base64,iVBOR/);
console.log("PASS: a pasted web GIF keeps its original file, a copied original needs no download, and failures explain the cause");
});
@@ -0,0 +1,38 @@
// Project Management label colors: each color choice of Manage labels shows its color, and the card title keeps its own field style, in both themes.
import assert from "node:assert/strict";
import path from "node:path";
import { outputDir, runSmoke } from "../_harness/index.mjs";
import { loadWorkspace, openBoard, pane, setTheme } from "../_harness/pmFixture.mjs";
const rgb = hex => `rgb(${hex.slice(1).match(/../g).map(value => parseInt(value, 16)).join(", ")})`;
await runSmoke("features/pmLabelColors", async ({ page }) => {
const output = await outputDir("features/pmLabelColors");
await loadWorkspace(page);
await openBoard(page, "Roadmap");
await pane(page).locator(".pm-card-title", { hasText: /^Card A$/ }).click();
const editor = page.locator("dialog.pm-card-editor[open]");
await editor.waitFor();
// The card title is a transparent field. The default field rule of Project Management does not replace its background.
const title = editor.getByRole("textbox", { name: "Title", exact: true });
assert.equal(await title.evaluate(input => getComputedStyle(input).backgroundColor), "rgba(0, 0, 0, 0)");
await editor.getByRole("group", { name: "Card details", exact: true }).getByRole("button", { name: "Labels", exact: true }).click();
await page.getByRole("dialog", { name: "Choose labels", exact: true }).getByRole("button", { name: "Manage labels", exact: true }).click();
const manager = page.getByRole("dialog", { name: "Manage labels", exact: true });
await manager.waitFor();
const bug = manager.getByRole("group", { name: "Label Bug", exact: true });
const swatches = await bug.locator("input.pm-color-swatch").evaluateAll(inputs =>
inputs.map(input => ({ name: input.getAttribute("aria-label"), color: input.style.getPropertyValue("--pm-swatch-color"), shown: getComputedStyle(input).backgroundColor })));
assert.equal(swatches.length, 16);
for (const swatch of swatches) assert.equal(swatch.shown, rgb(swatch.color), `${swatch.name} shows its color`);
await bug.getByRole("radio", { name: "Blue", exact: true }).check();
await manager.locator(".pm-label-badge", { hasText: /^Bug$/ }).waitFor();
for (const theme of ["dark", "light"]) {
await setTheme(page, theme);
await bug.screenshot({ path: path.join(output, `label-colors-${theme}.png`) });
}
console.log("PASS: label color choices and the card title field");
});
+88
View File
@@ -0,0 +1,88 @@
// Project Management in French: a language change in the settings shows an open board again in the new language and
// closes its open menu. The controls, menus, card details, and All tasks show French text from the catalog
// (src/lib/i18n/messages.ts). Board names, list names, and card titles stay as the user typed them.
// A change back to English shows English again. New in RuneStone: the plugin had no translations.
import assert from "node:assert/strict";
import path from "node:path";
import { outputDir, runSmoke } from "../_harness/index.mjs";
import { column, loadWorkspace, openBoard, pane, setTheme } from "../_harness/pmFixture.mjs";
await runSmoke("features/pmLanguage", async ({ page }) => {
const output = await outputDir("features/pmLanguage");
await loadWorkspace(page);
await openBoard(page, "Roadmap");
const catalog = await page.evaluate(async () => (await import("/src/lib/i18n/messages.ts")).catalogs.fr);
/** The French text of a catalog key, with its values. */
const fr = (key, values = {}) => {
assert(Object.hasOwn(catalog, key), `The catalog has "${key}"`);
return catalog[key].replace(/\{(\w+)\}/g, (_, name) => values[name]);
};
const button = name => pane(page).getByRole("button", { name, exact: true });
const setLanguage = async language => {
await page.evaluate(value => window.__TEST__.writeSettings("language", value), language);
await page.waitForFunction(value => document.documentElement.lang === value, language);
};
// An open menu closes when the language changes. The board shows again in French.
await button("List actions for To do").click();
await page.getByRole("menu", { name: "List actions", exact: true }).waitFor();
await setLanguage("fr");
await page.locator(".rs-menu").waitFor({ state: "detached" });
await button(fr("More actions")).waitFor();
assert.equal(fr("More actions"), "Plus d’actions");
assert.equal(fr("Calendar"), "Calendrier");
const views = pane(page).getByRole("navigation", { name: fr("Project Management views"), exact: true });
assert.deepEqual(await views.getByRole("button").evaluateAll(nodes => nodes.map(node => node.getAttribute("aria-label"))), [fr("Kanban"), fr("Gantt"), fr("Calendar")]);
for (const name of [fr("Search tasks"), fr("Manage labels"), fr("Add a list"), fr("Board scope: {name}", { name: "Roadmap" }),
fr("List actions for {name}", { name: "To do" }), fr("Collapse {name}", { name: "To do" }), fr("Actions for {name}", { name: "Card A" })]) {
assert.equal(await button(name).count() > 0, true, `The board has the control "${name}"`);
}
assert.equal(await column(page, "To do").getByRole("button", { name: fr("Add a card"), exact: true }).count(), 1);
assert.equal(await button("More actions").count(), 0, "No English control name stays");
// The text that the user typed stays unchanged.
assert.equal(await pane(page).locator(".pm-scope-label").innerText(), "Roadmap");
await page.getByRole("tab", { name: "Roadmap", exact: true }).waitFor();
assert.deepEqual(await column(page, "To do").locator(".pm-card-title").allInnerTexts(), ["Card A", "Card B", "Shared card"]);
assert.deepEqual(await pane(page).locator(".pm-column-heading h2").allInnerTexts(), ["To do", "In progress", "Done", "Review"]);
// The shared menus show French items.
await button(fr("List actions for {name}", { name: "To do" })).focus();
await page.keyboard.press("Enter");
const listMenu = page.getByRole("menu", { name: fr("List actions"), exact: true });
await listMenu.waitFor();
assert.deepEqual((await listMenu.getByRole("menuitem").allInnerTexts()).slice(0, 2), [fr("Edit list"), fr("Set list limit")]);
for (const theme of ["dark", "light"]) {
await setTheme(page, theme);
await page.screenshot({ path: path.join(output, `board-menu-fr-${theme}.png`) });
}
await page.keyboard.press("Escape");
await listMenu.waitFor({ state: "detached" });
// The card details are in French. The card title stays.
await pane(page).locator(".pm-card-title", { hasText: /^Card A$/ }).click();
const editor = page.locator("dialog.pm-card-editor[open]");
await editor.waitFor();
assert.equal(await editor.getByRole("textbox", { name: fr("Title"), exact: true }).inputValue(), "Card A");
assert.ok((await editor.locator(".pm-created-at").innerText()).startsWith(fr("Created: {date}", { date: "" })));
await editor.getByRole("button", { name: fr("Save card"), exact: true }).waitFor();
await page.screenshot({ path: path.join(output, "card-fr-light.png") });
await editor.getByRole("button", { name: fr("Close card"), exact: true }).click();
await editor.waitFor({ state: "detached" });
// All tasks: the catalog name of a group without a board translates. Board names stay.
await pane(page).locator(".pm-scope").click();
await page.getByRole("menu", { name: fr("Board scope"), exact: true }).getByRole("menuitemradio", { name: fr("All tasks"), exact: true }).click();
await pane(page).locator(".pm-scope-label", { hasText: fr("All tasks") }).waitFor();
await page.getByRole("tab", { name: "Project Management", exact: true }).waitFor();
assert.deepEqual(await column(page, "To do").locator(".pm-board-group-heading").allInnerTexts(), ["Bugs · Roadmap", "Roadmap", fr("No active board")]);
await page.screenshot({ path: path.join(output, "all-tasks-fr-light.png") });
// A change back to English shows the open view in English at once.
await setLanguage("en");
await button("More actions").waitFor();
assert.equal(await pane(page).locator(".pm-scope-label").innerText(), "All tasks");
assert.deepEqual(await column(page, "To do").locator(".pm-board-group-heading").allInnerTexts(), ["Bugs · Roadmap", "Roadmap", "No active board"]);
assert.equal(await button(fr("More actions")).count(), 0);
console.log("PASS: French controls, menus, and card details, with the typed names unchanged");
}, { timeout: 15000 });
+127
View File
@@ -0,0 +1,127 @@
// Project Management menus: the list actions, the card actions with the Move to list submenu, the board scope, and
// More actions. All use the shared host menu. Each opens with the keyboard, in the dark and the light theme, at a wide
// and a narrow width. The arrow keys move the focus, Enter runs an item, and Escape closes the menu and returns focus.
// Ports menu-audit.spec.ts, shared-menu.spec.ts, board-menu-api.spec.ts, and relations-menu.spec.ts (keyboard part)
// of RuneStone_Project_Management.
import assert from "node:assert/strict";
import path from "node:path";
import { outputDir, runSmoke, settle } from "../_harness/index.mjs";
import { cardPath, column, focusedName, loadWorkspace, openBoard, pane, roadmap, savedBoards, setTheme, waitForFile } from "../_harness/pmFixture.mjs";
await runSmoke("features/pmMenus", async ({ page }) => {
const output = await outputDir("features/pmMenus");
await loadWorkspace(page);
await openBoard(page, "Roadmap");
const listTrigger = column(page, "To do").getByRole("button", { name: "List actions for To do", exact: true });
const cardTrigger = pane(page).getByRole("button", { name: "Actions for Card A", exact: true });
const scope = pane(page).getByRole("button", { name: "Board scope: Roadmap", exact: true });
const moreTrigger = pane(page).getByRole("button", { name: "More actions", exact: true });
const menu = name => page.getByRole("menu", { name, exact: true });
const items = async name => menu(name).locator(":scope > button").evaluateAll(rows => rows.map(row => `${row.textContent.trim()}${row.disabled ? " (disabled)" : ""}`));
/** Open a menu with `key` on its focused trigger, and return the menu after its checks. */
async function open(trigger, key, name) {
await trigger.focus();
await page.keyboard.press(key);
const panel = menu(name);
await panel.waitFor();
assert.equal(await panel.evaluate(node => node.classList.contains("rs-menu")), true, `${name} uses the shared menu`);
const box = await panel.boundingBox(), viewport = page.viewportSize();
assert(box.x >= 0 && box.y >= 0 && box.x + box.width <= viewport.width + 1 && box.y + box.height <= viewport.height + 1, `${name} stays inside the window`);
return panel;
}
/** Press Escape, and make sure that the menu closes and the trigger has focus again. */
async function dismiss(name, trigger) {
await page.keyboard.press("Escape");
await menu(name).waitFor({ state: "detached" });
assert.equal(await focusedName(page), trigger, `Escape returns focus to ${trigger}`);
}
for (const theme of ["dark", "light"]) {
await setTheme(page, theme);
for (const width of [1440, 760]) {
await page.setViewportSize({ width, height: width === 1440 ? 1000 : 700 });
// A window resize closes an open menu. Let the resize event pass first.
await settle(page);
const shot = name => page.screenshot({ path: path.join(output, `${name}-${theme}-${width}.png`) });
// List actions: Enter opens the menu on the first item. The arrow keys skip a disabled item.
await column(page, "To do").scrollIntoViewIfNeeded();
await open(listTrigger, "Enter", "List actions");
assert.deepEqual(await items("List actions"), ["Edit list", "Set list limit", "Move left (disabled)", "Move right", "Archive all cards", "Delete list"]);
assert.equal(await focusedName(page), "Edit list");
await page.keyboard.press("ArrowDown");
assert.equal(await focusedName(page), "Set list limit");
await page.keyboard.press("ArrowDown");
assert.equal(await focusedName(page), "Move right", "ArrowDown skips the disabled item");
await shot("list-actions");
await dismiss("List actions", "List actions for To do");
// Card actions: ArrowDown on the card menu button opens the menu. ArrowRight opens the list submenu.
await open(cardTrigger, "ArrowDown", "Card actions");
assert.deepEqual(await items("Card actions"), ["Edit card", "Move to list", "Move to board", "Move up (disabled)", "Move down", "Remove from board", "Archive", "Delete card"]);
assert.equal(await focusedName(page), "Edit card");
await page.keyboard.press("ArrowDown");
assert.equal(await focusedName(page), "Move to list");
await page.keyboard.press("ArrowRight");
const submenu = menu("Move to list");
await submenu.waitFor();
assert.equal(await submenu.getByRole("menuitemradio", { name: "To do", exact: true }).getAttribute("aria-checked"), "true");
assert.equal(await focusedName(page), "Unlisted");
await shot("card-actions");
await page.keyboard.press("ArrowLeft");
assert.equal(await focusedName(page), "Move to list", "ArrowLeft returns to the parent item");
await dismiss("Card actions", "Actions for Card A");
// Board scope: the boards are in name order, and the focus starts on the checked board.
await open(scope, "ArrowDown", "Board scope");
assert.deepEqual(await menu("Board scope").getByRole("menuitemradio").allInnerTexts(), ["All tasks", "Bugs", "Roadmap"]);
assert.equal(await focusedName(page), "Roadmap");
await page.keyboard.press("ArrowUp");
assert.equal(await focusedName(page), "Bugs");
await shot("board-scope");
await dismiss("Board scope", "Board scope: Roadmap");
// More actions: the board commands.
await open(moreTrigger, "Enter", "More actions");
assert.deepEqual(await items("More actions"), ["New board", "Archive board", "Delete board", "Rename board", "New card", "Add existing note", "Show archived", "Refresh", "Customize background", "Project Management settings"]);
assert.equal(await focusedName(page), "New board");
await page.keyboard.press("End");
assert.equal(await focusedName(page), "Project Management settings");
await shot("more-actions");
await dismiss("More actions", "More actions");
}
}
await page.setViewportSize({ width: 1440, height: 1000 });
await settle(page);
// Enter runs the focused item. Move right changes the list order.
await open(listTrigger, "Enter", "List actions");
await page.keyboard.press("ArrowDown");
await page.keyboard.press("ArrowDown");
await page.keyboard.press("Enter");
await menu("List actions").waitFor({ state: "detached" });
await page.waitForFunction(() => [...document.querySelectorAll(".plugin-editor-pane .pm-column")].map(node => node.dataset.listId).join() === "doing,todo,done,review");
assert.deepEqual((await savedBoards(page)).find(item => item.value.id === roadmap).value.lists.map(list => list.id), ["doing", "todo", "done", "review"]);
// Enter on a submenu item moves the card to that list.
await open(cardTrigger, "ArrowDown", "Card actions");
await page.keyboard.press("ArrowDown");
await page.keyboard.press("ArrowRight");
await menu("Move to list").waitFor();
// The submenu follows the new list order: Unlisted, In progress, To do, Done, Review.
await page.keyboard.press("ArrowDown");
assert.equal(await focusedName(page), "In progress");
await page.keyboard.press("Enter");
await waitForFile(page, cardPath("card-a"), /listId: doing/);
await column(page, "In progress").locator(".pm-card-title", { hasText: "Card A" }).waitFor();
// Enter on a board opens it in the same tab.
await open(scope, "ArrowDown", "Board scope");
await page.keyboard.press("ArrowUp");
await page.keyboard.press("Enter");
await page.getByRole("tab", { name: "Bugs", exact: true, selected: true }).waitFor();
await pane(page).getByRole("button", { name: "Board scope: Bugs", exact: true }).waitFor();
assert.equal(await page.getByRole("tab", { name: "Roadmap", exact: true }).count(), 0);
console.log("PASS: list, card, board scope, and board menus with the keyboard in both themes");
}, { timeout: 15000 });
+92
View File
@@ -0,0 +1,92 @@
// Project Management views: All tasks with merged list columns and board dividers (UI-034, UI-035), then Gantt,
// Calendar (month, week, and day), and Kanban, in both themes. Each view keeps its own view state.
// Ports all-tasks.spec.ts, board-scope-alignment.spec.ts, board-view-state.spec.ts, and the Gantt and Calendar parts of
// workflow.spec.ts of RuneStone_Project_Management.
import assert from "node:assert/strict";
import path from "node:path";
import { outputDir, runSmoke } from "../_harness/index.mjs";
import { card, column, loadWorkspace, openBoard, pane, pmFiles, roadmap, setTheme } from "../_harness/pmFixture.mjs";
await runSmoke("features/pmViews", async ({ page }) => {
const output = await outputDir("features/pmViews");
// One more card on the Review list of Roadmap, so that the merged review column has two boards.
await loadWorkspace(page, Object.fromEntries([...Object.entries(pmFiles()), card("card-f", "Review card", { placements: { [roadmap]: "review" }, order: "f" })]));
await openBoard(page);
const view = name => pane(page).getByRole("navigation", { name: "Project Management views", exact: true }).getByRole("button", { name, exact: true });
const shots = async name => {
for (const theme of ["dark", "light"]) {
await setTheme(page, theme);
await page.screenshot({ path: path.join(output, `${name}-${theme}.png`) });
}
};
// UI-034: equal list names share one column. Case and outer spaces do not matter ("Review" and "review").
await pane(page).locator(".pm-card").first().waitFor();
assert.equal(await view("Kanban").getAttribute("aria-pressed"), "true");
const labels = await pane(page).locator("section.pm-column").evaluateAll(nodes => nodes.map(node => node.getAttribute("aria-label")));
assert.deepEqual(labels.map(label => label.toLowerCase()), ["to do", "in progress", "done", "review"]);
// UI-035: each column groups its cards under board names. A shared card shows once, under the names of its boards.
const todo = column(page, "To do");
const headings = locator => locator.locator(".pm-board-group-heading").allInnerTexts();
assert.deepEqual(await headings(todo), ["Bugs · Roadmap", "Roadmap", "No active board"]);
assert.equal(await todo.locator(".pm-card-title", { hasText: /^Shared card$/ }).count(), 1, "A shared card shows once");
assert.deepEqual(await todo.getByRole("region", { name: "Roadmap", exact: true }).locator(".pm-card-title").allInnerTexts(), ["Card A", "Card B"]);
assert.deepEqual(await todo.getByRole("region", { name: "No active board", exact: true }).locator(".pm-card-title").allInnerTexts(), ["Loose card"]);
const review = pane(page).locator('section.pm-column[data-list-id="list:review"]');
assert.deepEqual(await headings(review), ["Bugs", "Roadmap"]);
// A merged column has no board limit. The board keeps its limit (checked below).
assert.equal(await review.locator(".pm-list-limit").count(), 0);
assert.equal(await review.locator(".pm-count").innerText(), "2");
assert.equal(await pane(page).locator(".pm-board-group-heading").evaluateAll(nodes => nodes.every(node => getComputedStyle(node).opacity === "1")), true, "Board names are opaque");
await shots("all-tasks");
// Gantt: a row for each card, a bar for the planned dates, and a deadline marker.
await view("Gantt").click();
assert.equal(await view("Gantt").getAttribute("aria-pressed"), "true");
const timeline = pane(page).getByRole("table", { name: "Task timeline", exact: true });
await timeline.waitFor();
assert.equal(await timeline.locator(".pm-gantt-row").count(), 7, "A heading row and six cards");
const bar = timeline.locator(".pm-gantt-bar", { hasText: "Card B" });
assert.match(await bar.getAttribute("title"), /^Card B: .+ to .+$/);
assert.equal(await timeline.locator(".pm-deadline").count(), 1);
assert.match(await timeline.locator(".pm-deadline").getAttribute("aria-label"), /^Card B, deadline /);
assert.equal(await timeline.getByRole("button", { name: /^Card A/ }).locator("small").innerText(), "Unscheduled");
await pane(page).getByRole("button", { name: "Next", exact: true }).click();
await pane(page).getByRole("button", { name: "Today", exact: true }).click();
await timeline.locator(".pm-gantt-bar").waitFor();
await shots("gantt");
// Calendar: the month shows the deadline. Week and Day show the hours.
await view("Calendar").click();
const period = name => pane(page).locator(".pm-date-nav").getByRole("button", { name, exact: true });
assert.equal(await period("Month").getAttribute("aria-pressed"), "true");
await pane(page).locator(".pm-month").waitFor();
assert.equal(await pane(page).locator(".pm-day-heading").count(), 7);
assert.equal(await pane(page).locator(".pm-month-day").count(), 42);
await pane(page).getByRole("button", { name: "◆ Due: Card B", exact: true }).waitFor();
await shots("calendar-month");
await period("Week").click();
assert.equal(await pane(page).locator(".pm-hour-day").count(), 7);
assert.equal(await period("Week").getAttribute("aria-pressed"), "true");
await shots("calendar-week");
await period("Day").click();
assert.equal(await pane(page).locator(".pm-hour-day").count(), 1);
assert.equal(await pane(page).locator(".pm-hour-day .pm-hour-slot").count(), 24);
await page.waitForFunction(() => {
const state = JSON.parse(localStorage.getItem("runestone.pm.viewStates") ?? "{}").planning;
return state?.view === "calendar" && state?.period === "day";
});
// Kanban again. A board in the same tab has its own view state and shows its limit.
await view("Kanban").click();
await pane(page).locator(".pm-board").waitFor();
await openBoard(page, "Roadmap");
assert.equal(await view("Kanban").getAttribute("aria-pressed"), "true", "A board starts in Kanban");
assert.equal(await column(page, "Review").locator(".pm-count").innerText(), "1/2");
assert.equal(await column(page, "Review").locator(".pm-list-limit").count(), 1);
await view("Calendar").click();
await pane(page).locator(".pm-month").waitFor();
await shots("board-calendar");
console.log("PASS: All tasks columns and dividers, Gantt, Calendar, and Kanban");
}, { timeout: 15000 });
+65
View File
@@ -0,0 +1,65 @@
// Settings → Features: the switch of each native feature, the migration default, search, keyboard use, both themes, and narrow windows.
// A switch in the Settings window changes the main window at once.
import assert from "node:assert/strict";
import path from "node:path";
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("features/settings", async ({ browser }) => {
const output = await outputDir("features/settings");
const context = await browser.newContext({ viewport: { width: 1152, height: 815 } });
await mockTauri(context, {
commands: test => ({
...test.workspace({ root: "C:\\features-settings", files: { "note.md": "# Note\n" } }),
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
"plugin:window|is_maximized": () => false,
}),
});
const main = await openPage(context, { timeout: 10000 });
await main.goto(smokeUrl);
await main.locator('[data-tree-rel="note.md"]').waitFor();
const sourceControl = main.locator(".header-left").getByRole("button", { name: "Source control", exact: true });
await sourceControl.waitFor();
// Without an old package, the migration stores the default of each feature.
assert.deepEqual(await main.evaluate(() => window.__TEST__.settings("features")), { git: true, background: true, terminal: true, pdf: true, pm: true });
const settings = await openPage(context, { timeout: 10000 });
await settings.goto(`${smokeUrl}/?settingsWindow=true`);
await settings.getByRole("heading", { name: "General", exact: true }).waitFor();
await settings.getByRole("button", { name: "Features", exact: true }).click();
await settings.getByRole("heading", { name: "Features", exact: true }).waitFor();
const git = settings.getByRole("switch", { name: "Git", exact: true });
assert.equal(await git.isChecked(), true);
assert.match(await git.getAttribute("aria-describedby"), /feature-git-description/);
await git.click();
await sourceControl.waitFor({ state: "detached" });
assert.deepEqual(await main.evaluate(() => window.__TEST__.settings("features")), { git: false, background: true, terminal: true, pdf: true, pm: true });
assert.equal(await settings.getByRole("status").innerText(), "Changes saved.");
await git.focus();
await settings.keyboard.press("Space");
await sourceControl.waitFor();
assert.equal(await git.isChecked(), true);
// The settings search finds the page by the name and the words of a feature.
const search = settings.getByRole("textbox", { name: "Search settings", exact: true });
await search.fill("source control");
assert.deepEqual(await settings.locator('nav[aria-label="Settings categories"] button').allInnerTexts(), ["Features"]);
await search.fill("");
for (const theme of ["dark", "light"]) {
await settings.evaluate(value => { document.documentElement.dataset.theme = value; }, theme);
for (const width of [1152, 540, 360]) {
await settings.setViewportSize({ width, height: width === 1152 ? 815 : 520 });
assert(await settings.evaluate(() => document.documentElement.scrollWidth <= innerWidth), `No horizontal scroll at ${width} pixels`);
const row = settings.locator(".setting-row", { has: git });
const box = await row.boundingBox();
const toggle = await git.boundingBox();
assert(toggle.x + toggle.width <= box.x + box.width + 1, "The switch stays inside its row");
await settings.screenshot({ path: path.join(output, `features-${theme}-${width}.png`) });
}
}
await git.focus();
assert.equal(await git.evaluate(node => node.matches(":focus-visible")), true);
await settings.screenshot({ path: path.join(output, "features-focus.png") });
console.log("PASS: the Features page turns Git off and on in another window, with search, keyboard, both themes, and narrow widths");
}, { timeout: 60000 });
+474
View File
@@ -0,0 +1,474 @@
// The Terminal feature: lazy load, copy and paste, the theme and the --rs-ansi-* colors, splits, maximize, profiles, history pickers,
// tasks, run file and run selection, Settings → Terminal, the Off prompt, close and reopen, and the terminal window.
// The `pty_*` commands are mocks with channels (tests/smoke/_harness/index.mjs). They do not prove real shell behavior.
import assert from "node:assert/strict";
import path from "node:path";
import { mockTauri, openPage, outputDir, runSmoke, settle, smokeUrl } from "../_harness/index.mjs";
await runSmoke("features/terminal", async ({ browser }) => {
const output = await outputDir("features/terminal");
const shot = name => path.join(output, name);
const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } });
await context.grantPermissions(["clipboard-read", "clipboard-write"]);
await mockTauri(context, {
state: { confirm: "Cancel" },
commands: test => {
const workspace = test.workspace({
root: "C:\\smoke-workspace",
files: {
"notes/welcome.md": "# Working notes\n\nFirst paragraph.\n",
"src/hello.py": "print('hello')\n",
},
});
test.files = workspace.files;
return {
...workspace,
pty_profiles: () => [{ id: "powershell", title: "PowerShell", kind: "powershell" }, { id: "cmd", title: "Command Prompt", kind: "cmd" }, { id: "git-bash", title: "Git Bash", kind: "bash" }, { id: "node", title: "JavaScript Debug Terminal", kind: "node" }],
settings_open_window: () => null,
spelling_menu_install: () => null,
"plugin:window|is_maximized": () => false,
"plugin:window|destroy": () => null,
"plugin:dialog|message": args => { test.state.prompts = [...test.state.prompts ?? [], args.message]; return test.state.confirm; },
};
},
});
const page = await openPage(context);
const count = command => page.evaluate(command => window.__TEST__.calls.filter(c => c.command === command).length, command);
const waitCount = (command, n) => page.waitForFunction(({ command, n }) => window.__TEST__.calls.filter(c => c.command === command).length === n, { command, n });
const click = name => page.getByRole("button", { name, exact: true }).click();
const menu = name => page.getByRole("menuitem", { name, exact: true }).click();
const writes = () => page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "pty_write").map(c => c.args.data).join(""));
const xtermLoaded = target => target.evaluate(() => performance.getEntriesByType("resource").some(entry => /xterm/i.test(entry.name)));
const appearance = (target, mode) => target.evaluate(async mode => {
const { applyAppearance } = await import("/src/lib/theme/appearance.ts");
applyAppearance({ theme: "default", mode });
}, mode);
await page.goto(smokeUrl);
await page.getByText("smoke-workspace", { exact: true }).waitFor();
// The Terminal button shows from the static catalog. The feature module and xterm load at the first use.
assert.equal(await xtermLoaded(page), false, "xterm does not load at start");
await click("Terminal");
await waitCount("pty_open", 1);
const open = await page.evaluate(() => window.__TEST__.calls.find(c => c.command === "pty_open").args);
assert.equal(typeof open.page, "string", "Each open sends the page ID");
assert.equal(open.cwd, "C:\\smoke-workspace");
await page.locator(".xterm-rows > div > span").first().waitFor();
assert.equal(await xtermLoaded(page), true);
const terminalFont = await page.locator(".xterm-rows > div > span").first().evaluate(element => {
const style = getComputedStyle(element);
return { family: style.fontFamily, weight: style.fontWeight, size: style.fontSize };
});
assert.equal(terminalFont.weight, "300");
assert.equal(terminalFont.size, "13px");
assert.ok(terminalFont.family.startsWith('"Cascadia Mono"'));
// The input before the open finished includes the answer of xterm to the cursor position query.
await page.waitForFunction(() => window.__TEST__.calls.some(c => c.command === "pty_write" && /\x1b\[\d+;\d+R/.test(c.args.data)));
// Copy: a drag selects without copy, a right-click copies and clears, Ctrl+C copies a selection, and without one it interrupts.
await page.evaluate(() => navigator.clipboard.writeText("before selection"));
const beforeSelection = await writes();
const firstText = await page.locator(".xterm-rows > div > span").first().boundingBox();
await page.mouse.move(firstText.x + 1, firstText.y + firstText.height / 2);
await page.mouse.down();
await page.mouse.move(firstText.x + firstText.width, firstText.y + firstText.height / 2, { steps: 10 });
await page.mouse.up();
assert.ok(await page.locator(".xterm-selection > div").count(), "Mouse drag selects terminal output.");
assert.equal(await page.evaluate(() => navigator.clipboard.readText()), "before selection", "Selection does not copy output.");
assert.equal(await writes(), beforeSelection, "Selection does not send input to the shell.");
await page.locator(".term").first().screenshot({ path: shot("terminal-copy-selection.png") });
await page.evaluate(() => {
window.__TEST__.writeText = navigator.clipboard.writeText.bind(navigator.clipboard);
navigator.clipboard.writeText = text => new Promise(resolve => {
window.__TEST__.finishCopy = async () => { await window.__TEST__.writeText(text); resolve(); };
});
});
await page.mouse.click(firstText.x + 10, firstText.y + firstText.height / 2, { button: "right" });
assert.ok(await page.locator(".xterm-selection > div").count(), "Selection stays until the clipboard write succeeds.");
await page.evaluate(() => window.__TEST__.finishCopy());
await page.evaluate(() => { navigator.clipboard.writeText = window.__TEST__.writeText; });
await page.waitForFunction(async () => (await navigator.clipboard.readText()).includes("READY"));
await page.waitForFunction(() => !document.querySelector(".xterm-selection > div"));
assert.equal(await writes(), beforeSelection, "Right-click copy does not send input to the shell.");
await page.evaluate(() => navigator.clipboard.writeText("empty selection"));
await page.mouse.click(firstText.x + 10, firstText.y + firstText.height / 2, { button: "right" });
assert.equal(await page.evaluate(() => navigator.clipboard.readText()), "empty selection", "Right-click without selection keeps the clipboard.");
await page.mouse.dblclick(firstText.x + 10, firstText.y + firstText.height / 2);
await page.evaluate(() => navigator.clipboard.writeText(""));
const beforeCopy = await writes();
await page.keyboard.press("Control+c");
await page.waitForFunction(async () => (await navigator.clipboard.readText()).includes("READY"));
assert.equal(await writes(), beforeCopy, "Copy does not send an interrupt to the shell.");
const beforeInterrupt = await writes();
await page.locator(".xterm-screen").first().click();
await page.keyboard.press("Control+c");
await page.waitForFunction(before => window.__TEST__.calls.filter(c => c.command === "pty_write").map(c => c.args.data).join("").length > before.length, beforeInterrupt);
assert.equal((await writes()).slice(beforeInterrupt.length), "\u0003", "Ctrl+C without selection interrupts the shell.");
// A denied clipboard write keeps the selection for another try.
await page.mouse.dblclick(firstText.x + 10, firstText.y + firstText.height / 2);
await page.evaluate(() => { navigator.clipboard.writeText = () => Promise.reject(new Error("Clipboard denied for smoke test")); });
await page.locator(".xterm-screen").first().click({ button: "right" });
await page.getByText("Error: Clipboard denied for smoke test", { exact: true }).waitFor();
assert.ok(await page.locator(".xterm-selection > div").count(), "Failed copy keeps the selection.");
await page.evaluate(() => { navigator.clipboard.writeText = window.__TEST__.writeText; });
// The 16 ANSI colors come from the --rs-ansi-* tokens. A token change reaches the open terminal.
const id = open.id;
await page.evaluate(id => window.__TEST__.pty.output(id, "\x1b[31mANSI-RED\x1b[0m \x1b[94mANSI-BLUE\x1b[0m\r\n"), id);
const colorOf = text => page.evaluate(text => {
const span = [...document.querySelectorAll(".xterm-rows span")].find(node => node.textContent.includes(text));
return span && getComputedStyle(span).color;
}, text);
await page.waitForFunction(() => [...document.querySelectorAll(".xterm-rows span")].some(node => node.textContent.includes("ANSI-RED")));
const red = await page.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue("--rs-ansi-red").trim());
assert.ok(red, "The theme defines --rs-ansi-red");
await page.evaluate(() => {
document.documentElement.style.setProperty("--rs-ansi-red", "#12ab34");
document.documentElement.style.setProperty("--rs-ansi-bright-blue", "#3456cd");
});
await page.waitForFunction(() => {
const color = text => getComputedStyle([...document.querySelectorAll(".xterm-rows span")].find(node => node.textContent.includes(text))).color;
return color("ANSI-RED") === "rgb(18, 171, 52)" && color("ANSI-BLUE") === "rgb(52, 86, 205)";
});
await page.evaluate(() => { for (const name of ["--rs-ansi-red", "--rs-ansi-bright-blue"]) document.documentElement.style.removeProperty(name); });
await page.waitForFunction(() => getComputedStyle([...document.querySelectorAll(".xterm-rows span")].find(node => node.textContent.includes("ANSI-RED"))).color !== "rgb(18, 171, 52)");
assert.notEqual(await colorOf("ANSI-RED"), "rgb(18, 171, 52)");
// Selection colors keep their hue and stay at most 65% opaque, in both themes and at two widths.
for (const theme of ["light", "dark"]) {
await appearance(page, theme);
for (const width of [620, 1440]) {
await page.setViewportSize({ width, height: 1000 });
await page.locator(".xterm-helper-textarea").first().focus();
const text = await (await page.waitForFunction(() => {
const node = [...document.querySelectorAll(".xterm-rows > div > span")].find(node => node.textContent.includes("READY"));
const rect = node?.getBoundingClientRect();
return rect?.width ? { x: rect.x, y: rect.y, width: rect.width, height: rect.height } : null;
})).jsonValue();
await page.mouse.move(text.x + 1, text.y + text.height / 2);
await page.mouse.down();
await page.mouse.move(text.x + text.width, text.y + text.height / 2, { steps: 10 });
await page.mouse.up();
await page.evaluate(() => navigator.clipboard.writeText(""));
await page.keyboard.press("Control+Shift+c");
await page.waitForFunction(async () => (await navigator.clipboard.readText()).includes("READY"));
const selectionColor = await page.locator(".xterm-selection > div").first().evaluate(node => getComputedStyle(node).backgroundColor);
const selectionAlpha = Number(selectionColor.match(/rgba\([^,]+,[^,]+,[^,]+,\s*([\d.]+)\)/)?.[1] ?? 1);
assert.ok(selectionAlpha > 0 && selectionAlpha <= 0.65, `Terminal selection keeps transparency: ${selectionColor}`);
assert.ok(await page.locator(".xterm-rows .xterm-decoration-top").first().evaluate(node => getComputedStyle(node).backgroundColor === "rgba(0, 0, 0, 0)"), "Selected glyph backgrounds stay transparent.");
await page.locator(".term").first().screenshot({ path: shot(`terminal-theme-${theme}-${width}.png`) });
}
}
for (const [source, expected] of [["#ff8000", [255, 128, 0, 0.647]], ["rgba(0, 255, 128, 0.35)", [0, 255, 128, 0.35]]]) {
await page.evaluate(source => document.documentElement.style.setProperty("--rs-selection", source), source);
await page.waitForFunction(expected => {
const channels = getComputedStyle(document.querySelector(".xterm-selection > div")).backgroundColor.match(/[\d.]+/g).map(Number);
return channels.length === 4 && channels.slice(0, 3).every((channel, index) => Math.abs(channel - expected[index]) <= 2) && Math.abs(channels[3] - expected[3]) < 0.005;
}, expected);
}
await page.evaluate(() => document.documentElement.style.removeProperty("--rs-selection"));
// The panel surfaces are translucent, the xterm layers are transparent, and the ribbon controls fit at 620 pixels.
const surfaces = () => page.evaluate(() => {
const alpha = color => {
const canvas = document.createElement("canvas");
canvas.width = canvas.height = 1;
const context = canvas.getContext("2d");
context.fillStyle = color;
context.fillRect(0, 0, 1, 1);
return context.getImageData(0, 0, 1, 1).data[3] / 255;
};
return Object.fromEntries([".ribbon", ".term", ".xterm", ".xterm-viewport", ".rail", ".pane-label"].map(selector => {
const element = document.querySelector(`.dock ${selector}`);
if (!element) return [selector, null];
const style = getComputedStyle(element);
return [selector, { alpha: alpha(style.backgroundColor), opacity: style.opacity }];
}));
});
for (const mode of ["light", "dark"]) {
await appearance(page, mode);
await settle(page);
const colors = await surfaces();
// The ribbon and the panes use the translucent surface tokens, so a background image shows through them.
assert.ok(colors[".ribbon"].alpha > 0.5 && colors[".ribbon"].alpha < 1, `ribbon ${colors[".ribbon"].alpha}`);
assert.ok(colors[".term"].alpha > 0.5 && colors[".term"].alpha < 1, `term ${colors[".term"].alpha}`);
assert.equal(colors[".xterm"].alpha, 0);
assert.equal(colors[".xterm-viewport"].alpha, 0);
assert.equal(colors[".ribbon"].opacity, "1");
assert.equal(await page.locator(".bottom").evaluate(element => getComputedStyle(element).backgroundColor), "rgba(0, 0, 0, 0)");
for (const width of [620, 1440]) {
await page.setViewportSize({ width, height: 800 });
await page.locator(".xterm-helper-textarea").first().focus();
await settle(page);
await page.getByRole("button", { name: "Terminal profiles and tasks", exact: true }).focus();
await page.getByRole("tooltip", { name: "Terminal profiles and tasks", exact: true }).waitFor();
const ribbonBounds = await page.locator(".dock .ribbon").boundingBox();
for (const button of await page.locator(".dock .ribbon button").all()) {
const bounds = await button.boundingBox();
assert.ok(bounds.x >= ribbonBounds.x && bounds.x + bounds.width <= ribbonBounds.x + ribbonBounds.width + 1);
assert.ok(bounds.width >= 28 && bounds.height >= 28);
}
await page.screenshot({ path: shot(`terminal-translucent-${mode}-${width}.png`) });
}
}
// Splits, maximize, hide and show without a close, profiles, and kill.
await page.setViewportSize({ width: 1440, height: 1000 });
assert.equal(await page.getByRole("navigation", { name: "Terminal list" }).count(), 0);
const adjacent = await page.getByRole("button", { name: "New terminal", exact: true }).evaluate(button => { const buttons = [...button.closest(".actions").querySelectorAll("button")]; return buttons[buttons.indexOf(button) + 1]?.getAttribute("aria-label"); });
assert.equal(adjacent, "Terminal profiles and tasks");
await click("Split terminal (Ctrl+Shift+5)");
await waitCount("pty_open", 2);
assert.equal(await page.getByRole("navigation", { name: "Terminal list" }).count(), 1);
assert.equal(await page.locator(".pane.shown").count(), 2);
const original = await page.locator(".pane.shown").first().boundingBox();
await click("Maximize panel");
const enlarged = await page.locator(".pane.shown").first().boundingBox();
assert.ok(enlarged.height > original.height + 100);
assert.equal(await count("pty_close"), 0);
await page.screenshot({ path: shot("terminal-splits.png") });
await click("Restore panel");
await page.keyboard.press("Control+j");
assert.equal(await count("pty_close"), 0);
await page.keyboard.press("Control+j");
assert.equal(await count("pty_open"), 2);
await click("Terminal profiles and tasks");
const splitProfile = page.getByRole("menuitem", { name: "Split terminal with profile", exact: true });
await splitProfile.focus();
await page.keyboard.press("ArrowRight");
const profileSubmenu = page.getByRole("menu", { name: "Split terminal with profile", exact: true });
assert(await profileSubmenu.getByRole("menuitem", { name: "PowerShell", exact: true }).evaluate(node => document.activeElement === node));
await page.keyboard.press("ArrowLeft");
assert(await splitProfile.evaluate(node => document.activeElement === node));
await page.keyboard.press("Escape");
assert(await page.getByRole("button", { name: "Terminal profiles and tasks", exact: true }).evaluate(node => document.activeElement === node));
await click("Terminal profiles and tasks");
await page.screenshot({ path: shot("terminal-profiles.png") });
await menu("Command Prompt");
await waitCount("pty_open", 3);
assert.equal(await page.locator(".pane.shown").count(), 1);
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "pty_open").at(-1).args.profile), "cmd");
await page.keyboard.press("Control+Shift+5");
await waitCount("pty_open", 4);
assert.equal(await page.locator(".pane.shown").count(), 2);
await click("Kill terminal");
await waitCount("pty_close", 1);
assert.equal(await page.locator(".pane.shown").count(), 1);
// OSC 633 and 133 shell integration fills the history pickers.
await page.evaluate(() => {
const id = window.__TEST__.calls.filter(c => c.command === "pty_open")[2].args.id;
const data = `\x1b]633;RSCommand;${btoa("echo history-check")}\x07\x1b]633;RSCwd;${btoa("C:\\two words")}\x07\x1b]133;A\x07C:\\two words>\x1b]133;B\x07`;
window.__TEST__.pty.output(id, data);
});
await click("More terminal actions");
assert(await page.getByRole("menuitem", { name: "Run the active file", exact: true }).isDisabled());
assert(await page.getByRole("menuitem", { name: "Run selected text", exact: true }).isDisabled());
await page.screenshot({ path: shot("terminal-actions.png") });
await menu("Run a recent command… Ctrl+Alt+R");
await page.getByRole("dialog").getByRole("option", { name: "echo history-check" }).click();
await page.waitForFunction(() => window.__TEST__.calls.some(c => c.command === "pty_write" && c.args.data.includes("echo history-check")));
await page.keyboard.press("Control+g");
await page.getByRole("dialog").getByRole("option", { name: "C:\\two words" }).click();
await page.waitForFunction(() => window.__TEST__.calls.some(c => c.command === "pty_write" && c.args.data.includes('cd /d "C:\\two words"')));
// Settings → Terminal opens Settings. The page does not load xterm, and its changes reach the open panel.
await click("Terminal profiles and tasks");
await menu("Terminal settings");
await waitCount("settings_open_window", 1);
const settings = await openPage(context);
await settings.goto(`${smokeUrl}/?settingsWindow=true`);
const dialog = settings.getByRole("dialog", { name: "Settings", exact: true });
await dialog.getByRole("button", { name: "Terminal", exact: true }).click();
await dialog.getByRole("heading", { name: "Terminal", exact: true }).waitFor();
assert.equal(await xtermLoaded(settings), false, "Settings → Terminal does not load xterm");
const fontSize = dialog.getByLabel("Font size", { exact: true });
assert.equal(await fontSize.inputValue(), "13");
await fontSize.fill("40");
await fontSize.press("Enter");
await fontSize.blur();
await dialog.getByText("Choose a whole number from 9 to 28.", { exact: true }).waitFor();
await fontSize.fill("16");
await fontSize.blur();
await settings.waitForFunction(() => window.__TEST__.settings("terminal")?.fontSize === 16);
await page.waitForFunction(() => getComputedStyle(document.querySelector(".pane.shown .xterm-rows > div > span")).fontSize === "16px");
for (const mode of ["light", "dark"]) {
await appearance(settings, mode);
for (const width of [1152, 360]) {
await settings.setViewportSize({ width, height: width === 360 ? 640 : 815 });
await settle(settings);
assert(await settings.evaluate(() => document.documentElement.scrollWidth <= innerWidth), `No horizontal scroll at ${width} pixels`);
await settings.screenshot({ path: shot(`settings-terminal-${mode}-${width}.png`) });
}
await dialog.getByRole("button", { name: "Default profile", exact: true }).click();
const profileMenu = settings.getByRole("menu", { name: "Default terminal profile", exact: true });
const current = profileMenu.getByRole("menuitemradio", { name: "PowerShell", exact: true });
assert.equal(await current.getAttribute("aria-checked"), "true");
assert.equal(await profileMenu.getByRole("menuitemradio", { name: "JavaScript Debug Terminal", exact: true }).count(), 0, "The debug terminal is not a default");
const bounds = await profileMenu.boundingBox();
assert(bounds.x >= 0 && bounds.x + bounds.width <= 360 && bounds.y >= 0 && bounds.y + bounds.height <= 640);
await settings.screenshot({ path: shot(`settings-terminal-profile-${mode}-360.png`) });
await settings.keyboard.press("End");
assert(await profileMenu.getByRole("menuitemradio", { name: "Git Bash", exact: true }).evaluate(node => document.activeElement === node));
await settings.keyboard.press("Escape");
assert(await dialog.getByRole("button", { name: "Default profile", exact: true }).evaluate(node => document.activeElement === node));
}
await settings.setViewportSize({ width: 1152, height: 815 });
await dialog.getByRole("button", { name: "Default profile", exact: true }).click();
await settings.getByRole("menuitemradio", { name: "Git Bash", exact: true }).click();
await dialog.getByRole("switch", { name: "Blink cursor", exact: true }).uncheck();
await settings.waitForFunction(() => window.__TEST__.settings("terminal")?.defaultProfile === "git-bash" && window.__TEST__.settings("terminal")?.cursorBlink === false);
await page.bringToFront();
await click("New terminal");
await waitCount("pty_open", 5);
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "pty_open").at(-1).args.profile), "git-bash");
// Tasks from .runestone/tasks.json, with the shared picker rows at 360 pixels in both themes.
await page.evaluate(() => window.__TEST__.files.set(".runestone/tasks.json", JSON.stringify({ tasks: [{ label: "Smoke task", command: "echo task-ok", profile: "powershell" }] })));
await click("Terminal profiles and tasks");
await menu("Run a task…");
for (const mode of ["light", "dark"]) {
await appearance(page, mode);
await page.setViewportSize({ width: 360, height: 640 });
const row = page.getByRole("option", { name: "Smoke task echo task-ok" });
const measurements = await row.evaluate(node => {
const css = getComputedStyle(node);
const root = getComputedStyle(document.documentElement);
return { fontSize: css.fontSize, minHeight: css.minHeight, padding: css.padding, radius: css.borderRadius,
tokenFont: root.getPropertyValue("--rs-menu-font-size").trim(), tokenHeight: root.getPropertyValue("--rs-menu-row-height").trim(),
tokenRadius: root.getPropertyValue("--rs-control-radius").trim(), tokenPadding: root.getPropertyValue("--rs-menu-row-padding").trim() };
});
assert.equal(measurements.fontSize, measurements.tokenFont);
assert.equal(measurements.minHeight, measurements.tokenHeight);
assert.equal(measurements.radius, measurements.tokenRadius);
assert.equal(measurements.padding, measurements.tokenPadding);
await page.screenshot({ path: shot(`terminal-task-picker-${mode}-360.png`) });
}
await page.setViewportSize({ width: 1440, height: 1000 });
const taskQuery = page.getByRole("combobox", { name: "Run a task", exact: true });
await taskQuery.fill("no-such-task");
await page.getByText("No entries match the filter.", { exact: true }).waitFor();
assert.equal(await page.getByRole("option").count(), 0);
await taskQuery.fill("Smoke task");
const taskOption = page.getByRole("option", { name: "Smoke task echo task-ok" });
assert.equal(await taskQuery.getAttribute("aria-activedescendant"), await taskOption.getAttribute("id"));
await taskQuery.press("Enter");
await waitCount("pty_open", 6);
await page.waitForFunction(() => window.__TEST__.calls.some(c => c.command === "pty_write" && c.args.data.includes("echo task-ok")));
// Run selected text and run the active file. The editor keeps its selection while the menu takes focus.
// The shell owns its control keys, so the test opens the file from a new tab.
await click("New tab (Ctrl+T)");
await page.getByRole("button", { name: /^Find file/ }).click();
await page.getByRole("textbox", { name: "Find a file" }).fill("hello.py");
await page.getByRole("dialog").getByRole("button").filter({ hasText: "hello.py" }).first().click();
const editor = page.locator(".cm-content").first();
await editor.waitFor();
const editorFont = await editor.evaluate(element => ({ family: getComputedStyle(element).fontFamily, weight: getComputedStyle(element).fontWeight }));
assert.equal(editorFont.weight, terminalFont.weight, "The terminal uses the code font weight");
assert.ok(editorFont.family.startsWith(terminalFont.family.split(",")[0]), "The terminal uses the code font");
await editor.click();
await page.keyboard.press("Control+a");
await click("More terminal actions");
await menu("Run selected text");
await page.waitForFunction(() => window.__TEST__.calls.some(c => c.command === "pty_write" && c.args.data.includes("print('hello')")));
await click("More terminal actions");
await menu("Run the active file");
await page.waitForFunction(() => window.__TEST__.calls.some(c => c.command === "pty_write" && c.args.data.includes("python 'C:\\smoke-workspace\\src\\hello.py'")));
await click("Terminal profiles and tasks");
await menu("New terminal window Ctrl+Alt+Shift+`");
await waitCount("pty_new_window", 1);
await click("More terminal actions");
await menu("Start dictation");
await waitCount("pty_dictation", 1);
await click("More terminal actions");
await menu("Clear the terminal");
assert.equal(await count("pty_close"), 1);
// Kill down to one session and none, start again, the new and window shortcuts, then close and a fresh reopen.
await page.setViewportSize({ width: 880, height: 600 });
await page.screenshot({ path: shot("terminal-narrow.png") });
for (let remaining = 5; remaining > 1; remaining--) await click("Kill terminal");
await waitCount("pty_close", 5);
assert.equal(await page.getByRole("navigation", { name: "Terminal list" }).count(), 0);
await click("Kill terminal");
await waitCount("pty_close", 6);
await click("Start a terminal");
await waitCount("pty_open", 7);
await page.locator(".pane.shown .xterm-helper-textarea").focus();
await page.keyboard.press("Control+Shift+Backquote");
await waitCount("pty_open", 8);
await page.keyboard.press("Control+Shift+Alt+Backquote");
await waitCount("pty_new_window", 2);
const opens = await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "pty_open").map(c => c.args.id));
await click("Close terminal (end all sessions)");
await waitCount("pty_close", opens.length);
const closedIds = await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "pty_close").map(c => c.args.id));
assert.deepEqual([...closedIds].sort(), [...opens].sort());
await page.keyboard.press("Control+j");
await waitCount("pty_open", opens.length + 1);
const freshId = await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "pty_open").at(-1).args.id);
assert.equal(opens.includes(freshId), false);
// The new shell takes the focus when it starts. Wait for that before the focus moves to the close button.
await page.waitForFunction(id => window.__TEST__.calls.some(c => c.command === "pty_resize" && c.args.id === id), freshId);
await appearance(page, "light");
await settle(page);
await page.getByRole("button", { name: "Close terminal (end all sessions)", exact: true }).focus();
await page.getByRole("tooltip", { name: "Close terminal (end all sessions)", exact: true }).waitFor();
await page.screenshot({ path: shot("terminal-close-light-narrow-focus.png") });
await page.keyboard.press("Enter");
await waitCount("pty_close", opens.length + 1);
await page.keyboard.press("Control+Shift+Backquote");
await waitCount("pty_open", opens.length + 2);
assert.equal(await page.locator(".pane.shown").count(), 1);
// Off asks first while a shell runs. Cancel keeps the shells. OK ends them and removes the controls.
await settings.bringToFront();
await dialog.getByRole("button", { name: "Features", exact: true }).click();
const terminalSwitch = dialog.getByRole("switch", { name: "Terminal", exact: true });
await terminalSwitch.click();
await settings.waitForFunction(() => window.__TEST__.state.prompts?.length === 1);
await settings.waitForFunction(() => document.querySelector("#feature-terminal").checked);
assert.deepEqual(await settings.evaluate(() => window.__TEST__.state.prompts), ["Terminal sessions will end.\nTurn off Terminal?"]);
assert.equal(await terminalSwitch.isChecked(), true, "Cancel keeps Terminal on");
assert.equal(await settings.evaluate(() => window.__TEST__.settings("features").terminal), true);
const closesBefore = await count("pty_close");
await settings.evaluate(() => { window.__TEST__.state.confirm = "Ok"; });
await terminalSwitch.click();
await page.waitForFunction(before => window.__TEST__.calls.filter(c => c.command === "pty_close").length > before, closesBefore);
assert.equal(await settings.evaluate(() => window.__TEST__.settings("features").terminal), false);
await page.getByRole("button", { name: "Terminal", exact: true }).waitFor({ state: "detached" });
assert.equal(await dialog.getByRole("button", { name: "Terminal", exact: true }).count(), 0, "Settings → Terminal hides while Terminal is off");
for (const mode of ["light", "dark"]) {
await appearance(settings, mode);
await settings.setViewportSize({ width: 360, height: 640 });
await settle(settings);
await settings.screenshot({ path: shot(`features-terminal-off-${mode}-360.png`) });
}
// Without prompts, an Off with no shell needs no question.
await terminalSwitch.check();
await page.getByRole("button", { name: "Terminal", exact: true }).first().waitFor();
await settings.evaluate(() => { window.__TEST__.state.prompts = []; });
await terminalSwitch.uncheck();
await settings.waitForFunction(() => window.__TEST__.settings("features").terminal === false);
assert.deepEqual(await settings.evaluate(() => window.__TEST__.state.prompts), []);
await terminalSwitch.check();
assert.deepEqual([...page.errors, ...settings.errors], []);
await settings.close();
// The terminal window: one session, no workspace open, the exit code from the channel, and close.
await page.goto(`${smokeUrl}/?terminalWindow=C%3A%5Csmoke-workspace`);
await page.locator(".xterm").waitFor();
await waitCount("pty_open", 1);
assert.equal(await count("workspace_open"), 0);
assert.equal(await page.getByRole("button", { name: "Close terminal window", exact: true }).count(), 1);
assert.equal(await page.getByRole("button", { name: "Maximize panel", exact: true }).count(), 0);
await page.screenshot({ path: shot("terminal-window.png") });
await page.evaluate(() => window.__TEST__.pty.exit(window.__TEST__.calls.find(c => c.command === "pty_open").args.id, 3));
await page.waitForFunction(() => document.querySelector(".xterm-rows")?.textContent.includes("[Process exited with code 3]"));
await click("Close terminal window");
await waitCount("plugin:window|destroy", 1);
assert.equal(await count("pty_close"), 0, "The host removed the exited shell, so the close needs no host call");
assert.deepEqual(page.errors, []);
console.log("PASS: terminal lazy load, copy, ANSI tokens, selection, splits, profiles, history, Settings → Terminal, tasks, run file, Off prompt, close and reopen, and the terminal window.");
}, { timeout: 30000 });