Files
RuneStone/tests/smoke/workspace/manageTemplates.smoke.mjs
T
Knotty Wyvern 0fdc991b2e Give way in narrow windows and use one icon for each action
Phase 5-6.

- Side panes give way when the window becomes narrow: the outline
  below 1100 pixels, the side pane below 800 pixels. They come back
  when the window grows. A pane that the user opens in a narrow window
  stays open, and the saved layout keeps the wide-window choice.
- One function has one icon. The SDK icon set gets duplicate, template,
  and tab. The reveal action has one label for each platform (Show in
  Explorer, Show in Finder, Show in file manager).
- The file menu follows one order: open, clipboard, organize, show and
  copy path, history, then Delete and Delete permanently in the error
  color after a separator. The tree copies paths through a Copy path
  submenu, as the tab menu does.
- The tree uses the shared chevron. Search hits come in groups by file,
  with counts and marked matches. Bookmarks show the name, the folder,
  and a remove button.
- All boolean settings use one switch design (src/lib/ui/switch.css).
  Browser settings apply at once, and the Save button is gone. The
  Settings window opens with the focus on its search.
- Targets of at least 24 pixels: the tab close button, outline rows,
  switches, and the settings search.
- Catalog rows in French, Japanese, and Simplified Chinese.
- Docs: UI-052, ui-design.md, and the user guide.

Tests: the new layout/panesAndSettings. Tests that closed or opened
panes by hand around narrow windows now rely on the new behavior, or
wait for the panes to give way before they reopen one. Tests that read
the old menu labels or the browser Save button use the new ones.
2026-10-28 21:31:36 -07:00

92 lines
5.0 KiB
JavaScript

// Note templates from the file pane menu: New note from a template, and the template manager's rename, name conflict, edit, new, delete, and long list.
import assert from "node:assert/strict";
import path from "node:path";
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
const name = "workspace/manageTemplates";
await runSmoke(name, async ({ page }) => {
const output = await outputDir(name);
await mockTauri(page, {
commands: test => {
const workspace = test.workspace({ root: "C:\\manage-templates", files: { "a.md": "# Note\n\nOriginal text.", ".runestone/templates/Daily.md": "# Daily\n\n## Tasks" } });
test.files = workspace.files;
return {
...workspace,
workspace_list: args => workspace.workspace_list(args).filter(entry => args.rel || entry.rel_path !== ".runestone"),
"plugin:dialog|message": () => "Ok",
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
spelling_menu_install: () => null,
};
},
});
const row = path => page.locator(`[data-tree-rel="${path}"]`);
const item = name => page.getByRole("menuitem", { name, exact: true });
const button = name => page.getByRole("button", { name, exact: true });
const templateName = () => page.getByRole("textbox", { name: "Template name", exact: true });
const file = path => page.evaluate(path => window.__TEST__.files.get(path), path);
async function openManager() {
await page.getByRole("navigation", { name: "Workspace files" }).click({ button: "right", position: { x: 90, y: 360 } });
await item("New note").hover();
await item("Manage templates…").click();
}
await page.goto(smokeUrl);
await row("a.md").waitFor();
await page.getByRole("navigation", { name: "Workspace files" }).click({ button: "right", position: { x: 90, y: 360 } });
await item("New note").hover();
// A template reload behind the open menu keeps the menu and its open submenu (src/lib/layout/ContextMenu.svelte).
const submenu = page.getByRole("menu", { name: "New note", exact: true });
await submenu.waitFor();
await submenu.evaluate(node => { node.dataset.smokeMark = "open"; });
await page.evaluate(() => window.dispatchEvent(new Event("runestone-templates-changed")));
await page.waitForTimeout(300);
assert.equal(await page.locator('[data-smoke-mark="open"]:popover-open').count(), 1, "A template reload keeps the open submenu");
await item("Daily").click();
await row("Daily.md").waitFor();
assert.equal(await file("Daily.md"), "# Daily\n\n## Tasks");
console.log("PASS: New note from a template");
await openManager();
await button("Rename Daily").click();
await templateName().fill("Weekly");
await button("Continue").click();
await button("Edit Weekly").waitFor();
await page.evaluate(() => window.__TEST__.files.set(".runestone/templates/Existing.md", "# Keep this template"));
await button("Rename Weekly").click();
await templateName().fill("Existing");
await button("Continue").click();
await page.getByRole("alert").filter({ hasText: "Destination exists" }).waitFor();
assert.equal(await file(".runestone/templates/Existing.md"), "# Keep this template");
for (const mode of ["light", "dark"]) {
await page.evaluate(async mode => { const { saveAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ theme: "default", mode }); }, mode);
await page.screenshot({ path: path.join(output, `templates-${mode}.png`) });
}
await button("Edit Weekly").click();
await page.getByRole("tab", { name: "Weekly.md", exact: true }).waitFor();
console.log("PASS: rename, rename conflict, and edit a template");
await openManager();
await button("New template").click();
await templateName().fill("Meeting");
await button("Continue").click();
await page.getByRole("tab", { name: "Meeting.md", exact: true }).waitFor();
assert.equal(await file(".runestone/templates/Meeting.md"), "");
await openManager();
await button("Delete Weekly").click();
await button("Edit Weekly").waitFor({ state: "detached" });
assert.equal(await file("Daily.md"), "# Daily\n\n## Tasks", "Deleting template preserves notes");
await button("Close templates").click();
console.log("PASS: create and delete a template");
await page.evaluate(() => { for (let i = 0; i < 40; i++) window.__TEST__.files.set(`.runestone/templates/Long template name ${i}.md`, "# Template"); });
await page.setViewportSize({ width: 600, height: 600 });
// The side pane gives way below 800 pixels. The test opens it again.
await page.locator("aside.left").waitFor({ state: "detached" });
await page.keyboard.press("Control+Backslash");
await page.locator("aside.left").waitFor();
await openManager();
assert.ok(await page.locator("dialog .list").evaluate(node => node.scrollHeight > node.clientHeight), "Long template list scrolls");
await page.screenshot({ path: path.join(output, "templates-narrow-long.png") });
await button("Close templates").click();
console.log("PASS: a long template list scrolls in a narrow window");
}, { viewport: { width: 1200, height: 850 } });