RuneStone 1.0.0
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
// 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 } });
|
||||
Reference in New Issue
Block a user