RuneStone 1.0.0
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
// The command palette (Ctrl+Shift+P), the side pane on Ctrl+\, the generated shortcut list in Help, and the Write formatting shortcuts.
|
||||
import assert from "node:assert/strict";
|
||||
import path from "node:path";
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
const name = "layout/commands";
|
||||
await runSmoke(name, async ({ page }) => {
|
||||
const output = await outputDir(name);
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
const workspace = test.workspace({ root: "C:\\commands", files: { "a.md": "# Note\n\nalpha beta gamma delta epsilon\n" } });
|
||||
test.files = workspace.files;
|
||||
return { ...workspace, plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }), spelling_menu_install: () => null };
|
||||
},
|
||||
});
|
||||
await page.goto(smokeUrl);
|
||||
await page.locator('[data-tree-rel="a.md"]').click();
|
||||
await page.locator(".live-writer .cm-content").waitFor();
|
||||
|
||||
// The palette lists the app commands with their shortcuts and runs the chosen one.
|
||||
await page.keyboard.press("Control+Shift+P");
|
||||
const palette = page.getByRole("dialog", { name: "Commands", exact: true });
|
||||
await palette.waitFor();
|
||||
assert.equal(await palette.getByRole("button", { name: "Save the active file Ctrl+S", exact: true }).count(), 1);
|
||||
assert.match(await palette.locator("footer").textContent(), /\d+ commands/);
|
||||
await page.screenshot({ path: path.join(output, "palette.png") });
|
||||
await page.getByRole("textbox", { name: "Find a command", exact: true }).fill("side pane");
|
||||
assert.deepEqual((await palette.locator(".rs-picker-row").allTextContents()).map(text => text.replace(/\s+/g, " ").trim()), ["Show or hide the side pane Ctrl+\\"]);
|
||||
assert.equal(await page.locator("aside.left").count(), 1);
|
||||
await page.keyboard.press("Enter");
|
||||
await palette.waitFor({ state: "detached" });
|
||||
await page.locator("aside.left").waitFor({ state: "detached" });
|
||||
// Ctrl+\ shows the side pane again. Ctrl+B no longer toggles it.
|
||||
await page.keyboard.press("Control+Backslash");
|
||||
await page.locator("aside.left").waitFor();
|
||||
|
||||
// Write formatting shortcuts make the same edits as the Format menu.
|
||||
const select = word => page.evaluate(async word => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
const view = EditorView.findFromDOM(document.querySelector(".live-writer .cm-content"));
|
||||
const from = view.state.doc.toString().indexOf(word);
|
||||
view.dispatch({ selection: { anchor: from, head: from + word.length } });
|
||||
view.focus();
|
||||
}, word);
|
||||
for (const [word, keys] of [["beta", "Control+b"], ["gamma", "Control+i"], ["delta", "Control+Shift+X"], ["epsilon", "Control+Shift+H"], ["alpha", "Control+k"]]) {
|
||||
await select(word);
|
||||
await page.keyboard.press(keys);
|
||||
}
|
||||
assert.equal(await page.locator("aside.left").count(), 1, "Ctrl+B in Write does not hide the side pane");
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(() => window.__TEST__.files.get("a.md").includes("==epsilon=="));
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.files.get("a.md")), "# Note\n\n[alpha]() **beta** *gamma* ~~delta~~ ==epsilon==\n");
|
||||
|
||||
// The Format menu shows the shortcuts.
|
||||
await page.locator(".live-writer .cm-line").filter({ hasText: "beta" }).click({ button: "right" });
|
||||
await page.getByRole("menuitem", { name: "Format", exact: true }).hover();
|
||||
for (const label of ["Bold Ctrl+B", "Italic Ctrl+I", "Strikethrough Ctrl+Shift+X", "Highlight Ctrl+Shift+H"]) await page.getByRole("menuitem", { name: label, exact: true }).waitFor();
|
||||
assert.equal(await page.getByRole("menuitem", { name: "Add external link Ctrl+K", exact: true }).count(), 1);
|
||||
await page.keyboard.press("Escape");
|
||||
await page.keyboard.press("Escape");
|
||||
|
||||
// Help lists every shortcut, open, in groups.
|
||||
await page.keyboard.press("F1");
|
||||
const help = page.getByRole("dialog", { name: "Help and about", exact: true });
|
||||
await help.waitFor();
|
||||
const list = help.locator("details").filter({ hasText: "Keyboard shortcuts" });
|
||||
assert.equal(await list.getAttribute("open"), "");
|
||||
for (const heading of ["General", "Write", "Files"]) await list.getByRole("heading", { name: heading, exact: true }).waitFor();
|
||||
const rows = await list.locator("dl div").allTextContents();
|
||||
for (const row of ["Show all commandsCtrl+Shift+P", "Show or hide the side paneCtrl+\\", "BoldCtrl+B", "Delete permanentlyShift+Delete", "Help and aboutF1"]) assert(rows.includes(row), `Help lists ${row}`);
|
||||
await page.screenshot({ path: path.join(output, "help-shortcuts.png") });
|
||||
console.log("PASS: the command palette, Ctrl+\\ for the side pane, Write formatting shortcuts, menu shortcut labels, and the Help shortcut list");
|
||||
});
|
||||
@@ -0,0 +1,148 @@
|
||||
// Keyboard and focus: radio check marks, menu focus rings, hover against active, readable disabled controls, the file tree keys, and splitters.
|
||||
import assert from "node:assert/strict";
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("layout/keyboardFocus", async ({ page }) => {
|
||||
const output = await outputDir("layout/keyboardFocus");
|
||||
await mockTauri(page, {
|
||||
commands: test => ({
|
||||
...test.workspace({
|
||||
root: "C:\\keyboard",
|
||||
files: {
|
||||
"alpha.md": "# Alpha\n",
|
||||
"beta.md": "# Beta\n",
|
||||
"notes/first.md": "# First\n",
|
||||
"notes/second.md": "# Second\n",
|
||||
"notes/deep/third.md": "# Third\n",
|
||||
"zeta.txt": "Zeta\n",
|
||||
},
|
||||
}),
|
||||
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
|
||||
"plugin:window|is_maximized": () => false,
|
||||
}),
|
||||
});
|
||||
await page.setViewportSize({ width: 1280, height: 760 });
|
||||
await page.goto(smokeUrl);
|
||||
const tree = page.getByRole("tree", { name: "Workspace files" });
|
||||
const row = rel => page.locator(`[data-tree-rel="${rel}"]`);
|
||||
const focused = () => page.evaluate(() => document.activeElement?.getAttribute("data-tree-rel") ?? document.activeElement?.getAttribute("aria-label"));
|
||||
await row("alpha.md").waitFor();
|
||||
|
||||
// The tree has one Tab stop. Arrow keys move, Right opens or enters a folder, Left closes it or goes up.
|
||||
assert.equal(await tree.locator('[role="treeitem"][tabindex="0"]').count(), 1);
|
||||
await row("alpha.md").click();
|
||||
await page.getByRole("tab", { name: "alpha.md", exact: true, selected: true }).waitFor();
|
||||
await row("alpha.md").focus();
|
||||
await page.keyboard.press("ArrowDown");
|
||||
assert.equal(await focused(), "beta.md");
|
||||
assert.equal(await row("beta.md").getAttribute("aria-selected"), "true");
|
||||
// Folders come first: notes, alpha.md, beta.md, zeta.txt.
|
||||
await page.keyboard.press("ArrowDown");
|
||||
assert.equal(await focused(), "zeta.txt");
|
||||
await page.keyboard.press("Home");
|
||||
assert.equal(await focused(), "notes");
|
||||
await page.keyboard.press("ArrowRight");
|
||||
await row("notes/first.md").waitFor();
|
||||
assert.equal(await row("notes").getAttribute("aria-expanded"), "true");
|
||||
await page.keyboard.press("ArrowRight");
|
||||
assert.equal(await focused(), "notes/deep");
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
assert.equal(await focused(), "notes");
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
assert.equal(await row("notes").getAttribute("aria-expanded"), "false");
|
||||
await page.keyboard.press("End");
|
||||
assert.equal(await focused(), "zeta.txt");
|
||||
await page.keyboard.press("Home");
|
||||
assert.equal(await focused(), "notes");
|
||||
await page.keyboard.press("z");
|
||||
assert.equal(await focused(), "zeta.txt");
|
||||
await page.keyboard.press("Shift+ArrowUp");
|
||||
assert.equal(await tree.locator('[aria-selected="true"]').count(), 2);
|
||||
assert.equal(await tree.locator('[role="treeitem"][tabindex="0"]').count(), 1);
|
||||
// Tab leaves the tree at once.
|
||||
await page.keyboard.press("Tab");
|
||||
assert.notEqual(await page.evaluate(() => !!document.activeElement?.closest('[role="tree"]')), true);
|
||||
await page.keyboard.press("Shift+Tab");
|
||||
assert.equal(await page.evaluate(() => !!document.activeElement?.closest('[role="tree"]')), true);
|
||||
|
||||
// A splitter takes focus. The arrow keys move it by 16 pixels, and Home and End go to its limits.
|
||||
const splitter = page.getByRole("separator", { name: "Resize the side pane", exact: true });
|
||||
const width = () => page.locator("aside.left").evaluate(node => Math.round(node.getBoundingClientRect().width));
|
||||
const before = await width();
|
||||
await splitter.focus();
|
||||
await page.keyboard.press("ArrowRight");
|
||||
assert.equal(await width(), before + 16);
|
||||
assert.equal(await splitter.getAttribute("aria-valuenow"), String(before + 16));
|
||||
await page.keyboard.press("Home");
|
||||
assert.equal(await width(), 160);
|
||||
await page.keyboard.press("End");
|
||||
assert.equal(await width(), 480);
|
||||
assert.equal(await splitter.evaluate(node => getComputedStyle(node).outlineWidth), "2px");
|
||||
const outline = page.getByRole("separator", { name: "Resize the outline", exact: true });
|
||||
await outline.focus();
|
||||
const right = () => page.locator("aside.right").evaluate(node => Math.round(node.getBoundingClientRect().width));
|
||||
const rightBefore = await right();
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
assert.equal(await right(), rightBefore + 16);
|
||||
await splitter.focus();
|
||||
await page.keyboard.press("Home");
|
||||
|
||||
for (const theme of ["dark", "light"]) {
|
||||
await page.evaluate(async mode => { const { saveAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ theme: "default", mode }); window.dispatchEvent(new Event("focus")); }, theme);
|
||||
await page.waitForFunction(mode => document.documentElement.dataset.theme === mode, theme);
|
||||
|
||||
// An active toggle differs from a hovered button. A disabled button keeps full opacity and dim text.
|
||||
const files = page.getByRole("button", { name: "Files", exact: true });
|
||||
const search = page.getByRole("button", { name: "Search", exact: true });
|
||||
await search.hover();
|
||||
const look = locator => locator.evaluate(node => { const style = getComputedStyle(node); return { fill: style.backgroundColor, color: style.color, bar: style.boxShadow }; });
|
||||
const [hovered, active] = [await look(search), await look(files)];
|
||||
assert.equal(hovered.bar, "none");
|
||||
assert.match(active.bar, /inset/);
|
||||
assert.notEqual(hovered.color, active.color);
|
||||
const save = page.getByRole("button", { name: "Save", exact: true });
|
||||
assert.equal(await save.isDisabled(), true);
|
||||
assert.equal(await save.evaluate(node => getComputedStyle(node).opacity), "1");
|
||||
const dim = await page.evaluate(() => { const probe = document.createElement("span"); probe.style.color = "var(--rs-text-dim)"; document.body.append(probe); const color = getComputedStyle(probe).color; probe.remove(); return color; });
|
||||
assert.equal(await save.evaluate(node => getComputedStyle(node).color), dim);
|
||||
await page.locator("header.header").screenshot({ path: `${output}/header-states-${theme}.png` });
|
||||
|
||||
// The current radio row shows a check mark and no fill. Keyboard focus adds a ring that hover does not have.
|
||||
await page.getByRole("tab", { name: "alpha.md", exact: true }).click({ button: "right" });
|
||||
await page.getByRole("menuitem", { name: "View", exact: true }).click();
|
||||
const write = page.getByRole("menuitemradio", { name: "Write", exact: true });
|
||||
const source = page.getByRole("menuitemradio", { name: "Source", exact: true });
|
||||
assert.equal(await write.getAttribute("aria-checked"), "true");
|
||||
assert.equal(await write.locator("svg").count(), 1);
|
||||
assert.equal(await source.locator("svg").count(), 0);
|
||||
await source.hover();
|
||||
assert.equal(await source.evaluate(node => getComputedStyle(node).outlineStyle), "none");
|
||||
await write.focus();
|
||||
await page.keyboard.press("ArrowDown");
|
||||
const keyed = page.locator('[role="menu"] button:focus-visible');
|
||||
assert.equal(await keyed.getAttribute("aria-checked"), "false");
|
||||
assert.equal(await keyed.evaluate(node => getComputedStyle(node).outlineWidth), "2px");
|
||||
// With focus and the pointer on other rows, the checked row has no fill.
|
||||
await page.mouse.move(0, 700);
|
||||
assert.equal(await write.evaluate(node => getComputedStyle(node).backgroundColor), "rgba(0, 0, 0, 0)");
|
||||
await page.screenshot({ path: `${output}/menu-check-${theme}.png` });
|
||||
await page.keyboard.press("Escape");
|
||||
await page.keyboard.press("Escape");
|
||||
await page.keyboard.press("Escape");
|
||||
|
||||
// Disabled menu rows keep full opacity and dim text.
|
||||
await page.getByRole("tab", { name: "alpha.md", exact: true }).click({ button: "right" });
|
||||
const disabled = page.getByRole("menuitem", { name: "Close tabs after", exact: true });
|
||||
assert.equal(await disabled.isDisabled(), true);
|
||||
assert.equal(await disabled.evaluate(node => getComputedStyle(node).opacity), "1");
|
||||
assert.equal(await disabled.evaluate(node => getComputedStyle(node).color), dim);
|
||||
await page.keyboard.press("Escape");
|
||||
}
|
||||
|
||||
// Help names the key that leaves the text before Tab moves on.
|
||||
await page.keyboard.press("F1");
|
||||
await page.getByRole("dialog", { name: "Help and about" }).getByText("Leave the text, then press Tab", { exact: true }).waitFor();
|
||||
await page.getByRole("button", { name: "Close help", exact: true }).click();
|
||||
assert.deepEqual(page.errors, []);
|
||||
console.log("PASS: one tree Tab stop, tree keys, type-ahead, range selection, keyboard splitters, radio check marks, menu focus ring, hover against active, readable disabled controls, Help, both themes.");
|
||||
});
|
||||
@@ -0,0 +1,80 @@
|
||||
// Sidebar layout persistence: the hidden outline, resized sidebars, and the navigation view survive layout changes, reloads, and reopened windows.
|
||||
import assert from "node:assert/strict";
|
||||
import { mockTauri, openPage, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("layout/outline", async ({ browser }) => {
|
||||
// Pages share one context, so a reopened window keeps the saved layout.
|
||||
const context = await browser.newContext({ viewport: { width: 1280, height: 800 } });
|
||||
// Unknown commands return null, as the original mock did.
|
||||
await mockTauri(context, {
|
||||
strict: false,
|
||||
commands: test => ({
|
||||
...test.workspace({ root: "D:\\LayoutTest", files: { "note.md": "# Layout test\n\nA note.\n" } }),
|
||||
plugins_snapshot: () => ({ root: "D:\\LayoutTest\\plugins", plugins: [] }),
|
||||
}),
|
||||
});
|
||||
const errors = [];
|
||||
let page;
|
||||
async function ready() { await page.getByRole("button", { name: /^(Hide|Show) outline$/ }).waitFor(); }
|
||||
async function reopen() {
|
||||
if (page) { errors.push(...page.errors); await page.close(); }
|
||||
page = await openPage(context, { timeout: 5000 });
|
||||
await page.goto(smokeUrl);
|
||||
await ready();
|
||||
}
|
||||
async function resize(index, x) {
|
||||
const box = await page.locator(".gutter-v").nth(index).boundingBox();
|
||||
await page.mouse.move(box.x + box.width / 2, box.y + 60);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(x, box.y + 60);
|
||||
await page.mouse.up();
|
||||
}
|
||||
async function widths() {
|
||||
return page.locator(".shell").evaluate(element => [element.style.getPropertyValue("--left"), element.style.getPropertyValue("--right")]);
|
||||
}
|
||||
await reopen();
|
||||
await page.getByText("LayoutTest", { exact: true }).waitFor();
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill("note.md");
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: "note.md" }).click();
|
||||
await page.locator(".cm-content").waitFor();
|
||||
await page.getByRole("button", { name: "Hide outline", exact: true }).click();
|
||||
await page.keyboard.press("Control+e");
|
||||
await page.locator(".source-editor .cm-content").waitFor();
|
||||
assert.equal(await page.locator(".right").count(), 0);
|
||||
await page.keyboard.press("Control+e");
|
||||
await page.locator(".cm-content").waitFor();
|
||||
assert.equal(await page.locator(".right").count(), 0);
|
||||
console.log("PASS: hidden outline stays hidden across Writer and Source changes");
|
||||
await page.reload();
|
||||
await page.getByRole("button", { name: "Show outline", exact: true }).waitFor();
|
||||
assert.equal(await page.locator(".right").count(), 0);
|
||||
await reopen();
|
||||
await page.getByRole("button", { name: "Show outline", exact: true }).waitFor();
|
||||
console.log("PASS: hidden outline survives reload and window reopen");
|
||||
|
||||
await page.getByRole("button", { name: "Show outline", exact: true }).click();
|
||||
// The left ribbon is 44 pixels wide, so the gutter at 374 gives a 330-pixel side pane.
|
||||
await resize(0, 374);
|
||||
await resize(1, 970);
|
||||
const resized = await widths();
|
||||
assert.deepEqual(resized, ["330px", "310px"]);
|
||||
await page.getByRole("button", { name: "Bookmarks", exact: true }).click();
|
||||
await reopen();
|
||||
assert.deepEqual(await widths(), resized);
|
||||
assert.equal(await page.getByRole("button", { name: "Bookmarks", exact: true }).getAttribute("aria-pressed"), "true");
|
||||
await page.getByRole("button", { name: "Hide outline", exact: true }).waitFor();
|
||||
console.log("PASS: resized sidebars and chosen navigation view survive reopen");
|
||||
|
||||
await page.getByRole("button", { name: "Bookmarks", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Hide outline", exact: true }).click();
|
||||
await reopen();
|
||||
assert.equal(await page.locator(".left, .right").count(), 0);
|
||||
await page.keyboard.press("Control+Backslash");
|
||||
assert.equal(await page.getByRole("button", { name: "Bookmarks", exact: true }).getAttribute("aria-pressed"), "true");
|
||||
await page.getByRole("button", { name: "Show outline", exact: true }).click();
|
||||
assert.deepEqual(await widths(), resized);
|
||||
console.log("PASS: collapsed sidebars retain their sizes and navigation view");
|
||||
errors.push(...page.errors);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
@@ -0,0 +1,112 @@
|
||||
// Layout, icons, and Settings: side panes that give way, one file menu order with a danger Delete, tree chevrons,
|
||||
// grouped search hits, readable bookmarks, 24-pixel targets, one switch design, and the first focus in Settings.
|
||||
import assert from "node:assert/strict";
|
||||
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("layout/panesAndSettings", async ({ browser }) => {
|
||||
const output = await outputDir("layout/panesAndSettings");
|
||||
const context = await browser.newContext({ viewport: { width: 1280, height: 760 } });
|
||||
await mockTauri(context, {
|
||||
commands: test => ({
|
||||
...test.workspace({
|
||||
root: "C:\\panes",
|
||||
files: {
|
||||
"alpha.md": "# Alpha\n\nThe river runs past the river mill.\n",
|
||||
"notes/beta.md": "# Beta\n\nA river note.\n\nAnother river line.\n",
|
||||
"notes/gamma.md": "# Gamma\n\nNo match here.\n",
|
||||
".runestone/marks.json": JSON.stringify({ pins: [], bookmarks: ["notes/beta.md", "alpha.md"], order: {} }),
|
||||
},
|
||||
}),
|
||||
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
|
||||
"plugin:window|is_maximized": () => false,
|
||||
}),
|
||||
});
|
||||
const page = await openPage(context);
|
||||
await page.goto(smokeUrl);
|
||||
const row = rel => page.locator(`[data-tree-rel="${rel}"]`);
|
||||
await row("alpha.md").waitFor();
|
||||
await row("alpha.md").click();
|
||||
await page.getByRole("tab", { name: "alpha.md", exact: true, selected: true }).waitFor();
|
||||
|
||||
// Side panes give way in narrow windows and come back when the window grows. The saved layout keeps the wide choice.
|
||||
const panes = () => page.evaluate(() => ({ left: !!document.querySelector("aside.left"), right: !!document.querySelector("aside.right") }));
|
||||
assert.deepEqual(await panes(), { left: true, right: true });
|
||||
await page.setViewportSize({ width: 1000, height: 760 });
|
||||
await page.waitForFunction(() => !document.querySelector("aside.right"));
|
||||
assert.deepEqual(await panes(), { left: true, right: false });
|
||||
await page.setViewportSize({ width: 760, height: 760 });
|
||||
await page.waitForFunction(() => !document.querySelector("aside.left"));
|
||||
const layout = () => page.evaluate(() => JSON.parse(localStorage.getItem("runestone.workbenchLayout") ?? "{}"));
|
||||
assert.equal((await layout()).leftOpen, true);
|
||||
assert.equal((await layout()).rightOpen, true);
|
||||
// A pane that the user opens in a narrow window stays open.
|
||||
await page.getByRole("button", { name: "Show outline", exact: true }).click();
|
||||
await page.locator("aside.right").waitFor();
|
||||
await page.screenshot({ path: `${output}/narrow-760.png` });
|
||||
await page.setViewportSize({ width: 1280, height: 760 });
|
||||
await page.waitForFunction(() => !!document.querySelector("aside.left") && !!document.querySelector("aside.right"));
|
||||
|
||||
// The file menu: open, clipboard, organize, show and copy path, history, then Delete in the error color.
|
||||
await row("alpha.md").click({ button: "right" });
|
||||
const menu = page.getByRole("menu", { name: "File actions", exact: true });
|
||||
await menu.waitFor();
|
||||
const labels = await menu.locator(":scope > button, :scope > hr").evaluateAll(nodes => nodes.map(node => node.tagName === "HR" ? "|" : node.querySelector(".action-label").textContent));
|
||||
assert.deepEqual(labels, ["Open in new tab", "Open in default app", "Open in terminal", "|", "Cut", "Copy", "Paste", "Make a copy", "|",
|
||||
"Rename", "Remove bookmark", "Pin", "Save as template", "|", "Show in Explorer", "Copy path", "|", "Undo file move", "Redo file move", "|", "Delete", "Delete permanently"]);
|
||||
const error = await page.evaluate(() => { const probe = document.createElement("span"); probe.style.color = "var(--rs-error)"; document.body.append(probe); const color = getComputedStyle(probe).color; probe.remove(); return color; });
|
||||
assert.equal(await menu.getByRole("menuitem", { name: "Delete", exact: true }).evaluate(node => getComputedStyle(node).color), error);
|
||||
// Each function has one icon: duplicate, template, and tab differ from copy.
|
||||
const icon = name => menu.getByRole("menuitem", { name, exact: true }).locator("svg").first().evaluate(node => node.innerHTML);
|
||||
const copy = await icon("Copy");
|
||||
for (const name of ["Make a copy", "Save as template", "Open in new tab"]) assert.notEqual(await icon(name), copy, name);
|
||||
await page.screenshot({ path: `${output}/file-menu.png` });
|
||||
await page.keyboard.press("Escape");
|
||||
|
||||
// Folders use the shared chevron. It turns when the folder opens.
|
||||
const chevron = row("notes").locator(".twist svg");
|
||||
assert.equal(await chevron.count(), 1);
|
||||
assert.equal(await chevron.evaluate(node => getComputedStyle(node).transform), "none");
|
||||
await row("notes").click();
|
||||
await page.waitForFunction(() => getComputedStyle(document.querySelector('[data-tree-rel="notes"] .twist svg')).transform !== "none");
|
||||
|
||||
// Search hits come in groups by file, with a count and marked matches.
|
||||
await page.getByRole("button", { name: "Search", exact: true }).click();
|
||||
await page.getByPlaceholder("Search files and notes").fill("river");
|
||||
await page.keyboard.press("Enter");
|
||||
await page.getByRole("status").filter({ hasText: "3 results in 2 files" }).waitFor();
|
||||
const groups = await page.locator(".results > .file").evaluateAll(nodes => nodes.map(node => [node.querySelector(".name").textContent, node.querySelector(".count").textContent]));
|
||||
assert.deepEqual(groups, [["alpha.md", "1"], ["beta.md", "2"]]);
|
||||
assert.equal(await page.locator(".results > .file").first().locator("mark").count(), 2);
|
||||
assert.equal(await page.locator(".results mark").first().textContent(), "river");
|
||||
await page.screenshot({ path: `${output}/search.png` });
|
||||
await page.locator(".results button").filter({ hasText: "Another river line." }).click();
|
||||
await page.getByRole("tab", { name: "beta.md", exact: true, selected: true }).waitFor();
|
||||
|
||||
// Bookmarks show the file name, its folder, and a remove button.
|
||||
await page.getByRole("button", { name: "Bookmarks", exact: true }).click();
|
||||
const bookmark = page.locator(".pane li").filter({ hasText: "beta.md" });
|
||||
assert.equal(await bookmark.locator(".folder").textContent(), "notes");
|
||||
await page.screenshot({ path: `${output}/bookmarks.png` });
|
||||
await bookmark.getByRole("button", { name: "Remove bookmark: beta.md", exact: true }).click();
|
||||
await bookmark.waitFor({ state: "detached" });
|
||||
|
||||
// Targets are at least 24 pixels.
|
||||
const close = await page.getByRole("button", { name: "Close beta.md", exact: true }).boundingBox();
|
||||
assert.ok(close.width >= 24 && close.height >= 24, JSON.stringify(close));
|
||||
const outlineRows = await page.locator("aside.right li button").evaluateAll(nodes => nodes.map(node => node.getBoundingClientRect().height));
|
||||
assert.ok(outlineRows.length && outlineRows.every(height => height >= 24), JSON.stringify(outlineRows));
|
||||
|
||||
// Settings: the first focus is on the search, and every switch has one design.
|
||||
const settings = await openPage(context);
|
||||
await settings.goto(smokeUrl + "/?settingsWindow=true");
|
||||
await settings.getByRole("textbox", { name: "Search settings", exact: true }).waitFor();
|
||||
await settings.waitForFunction(() => document.activeElement?.getAttribute("aria-label") === "Search settings");
|
||||
await settings.getByRole("button", { name: "General", exact: true }).click();
|
||||
const switches = await settings.getByRole("switch").evaluateAll(nodes => nodes.map(node => { const rect = node.getBoundingClientRect(); return `${node.className.split(" ")[0]} ${Math.round(rect.width)}x${Math.round(rect.height)}`; }));
|
||||
assert.ok(switches.length >= 4 && switches.every(item => item === "rs-switch 40x24"), JSON.stringify(switches));
|
||||
await settings.getByRole("button", { name: "Appearance", exact: true }).click();
|
||||
assert.equal(await settings.getByRole("switch", { name: "Transparent surfaces", exact: true }).evaluate(node => node.className.split(" ")[0]), "rs-switch");
|
||||
await settings.screenshot({ path: `${output}/settings-appearance.png` });
|
||||
assert.deepEqual([...page.errors, ...settings.errors], []);
|
||||
console.log("PASS: panes give way, file menu order and icons, danger Delete, tree chevrons, grouped search, bookmarks, 24-pixel targets, one switch design, Settings first focus.");
|
||||
});
|
||||
@@ -0,0 +1,125 @@
|
||||
// Plain fixes: Save, Don't save, and Cancel when a changed tab closes, the conflict banner, the status bar facts,
|
||||
// panes that follow the active tab, table hints and controls, and the line break setting.
|
||||
import assert from "node:assert/strict";
|
||||
import { chooseView, mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("layout/plainFixes", async ({ page }) => {
|
||||
const output = await outputDir("layout/plainFixes");
|
||||
await mockTauri(page, {
|
||||
state: { answer: "Cancel" },
|
||||
commands: test => {
|
||||
const workspace = test.workspace({
|
||||
root: "C:\\plain",
|
||||
files: {
|
||||
"a.md": "# Alpha\n\nFirst line\nsecond line of the same paragraph.\n",
|
||||
"b.md": "# Beta\r\n\r\nWindows text.\r\n",
|
||||
"c.md": "# Gamma\n\nThird note.\n",
|
||||
"table.md": "| Name | Value |\n| --- | --- |\n| One | 1 |\n| Two | =B2*2 |\n",
|
||||
},
|
||||
});
|
||||
Object.assign(test, { files: workspace.files });
|
||||
return {
|
||||
...workspace,
|
||||
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
|
||||
"plugin:window|is_maximized": () => false,
|
||||
"plugin:dialog|message": args => { (test.state.prompts ??= []).push(args); return test.state.answer; },
|
||||
};
|
||||
},
|
||||
});
|
||||
await page.setViewportSize({ width: 1280, height: 800 });
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText("plain", { exact: true }).waitFor();
|
||||
await page.evaluate(() => window.__TEST__.writeSettings("general", { autosaveEnabled: false, autosaveSeconds: 5 }));
|
||||
const open = async name => {
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
|
||||
await page.getByRole("tab", { name, exact: true, selected: true }).waitFor();
|
||||
};
|
||||
const status = () => page.locator(".status").innerText();
|
||||
const type = async text => { await page.locator(".cm-content").click(); await page.keyboard.press("Control+End"); await page.keyboard.type(text); };
|
||||
const answer = value => page.evaluate(value => { window.__TEST__.state.answer = value; }, value);
|
||||
const file = name => page.evaluate(name => window.__TEST__.files.get(name), name);
|
||||
|
||||
// The status bar shows the save state, the cursor, the words, the line endings, and the view. Native watching has no label.
|
||||
await open("a.md");
|
||||
await page.locator(".cm-content").click();
|
||||
await page.keyboard.press("Control+Home");
|
||||
await page.waitForFunction(() => /Ln 1, Col 1/.test(document.querySelector(".status").textContent));
|
||||
assert.match(await status(), /Saved/);
|
||||
assert.match(await status(), /10 words/);
|
||||
assert.match(await status(), /LF/);
|
||||
assert.doesNotMatch(await status(), /watch/i);
|
||||
await open("b.md");
|
||||
await page.waitForFunction(() => /CRLF/.test(document.querySelector(".status").textContent));
|
||||
await page.locator(".status").screenshot({ path: `${output}/status.png` });
|
||||
|
||||
// Closing a changed tab asks Save, Don't save, or Cancel.
|
||||
await type(" Edited");
|
||||
await page.waitForFunction(() => /Unsaved/.test(document.querySelector(".status").textContent));
|
||||
const prompts = () => page.evaluate(() => window.__TEST__.state.prompts ?? []);
|
||||
await page.keyboard.press("Control+w");
|
||||
await page.waitForFunction(() => (window.__TEST__.state.prompts ?? []).length === 1);
|
||||
assert.deepEqual((await prompts())[0].buttons, { YesNoCancelCustom: ["Save", "Don't save", "Cancel"] });
|
||||
assert.equal(await page.getByRole("tab", { name: /^b\.md/ }).count(), 1, "Cancel keeps the tab");
|
||||
await answer("Save");
|
||||
await page.keyboard.press("Control+w");
|
||||
await page.getByRole("tab", { name: /^b\.md/ }).waitFor({ state: "detached" });
|
||||
assert.match(await file("b.md"), /Edited/);
|
||||
await open("c.md");
|
||||
await type(" Dropped");
|
||||
await answer("Don't save");
|
||||
await page.keyboard.press("Control+w");
|
||||
await page.getByRole("tab", { name: /^c\.md/ }).waitFor({ state: "detached" });
|
||||
assert.doesNotMatch(await file("c.md"), /Dropped/);
|
||||
|
||||
// The conflict banner: the warning icon, the safe choice first, and the choice that discards edits last.
|
||||
await open("a.md");
|
||||
await type(" Mine");
|
||||
await page.evaluate(() => {
|
||||
window.__TEST__.files.set("a.md", "# Alpha\n\nChanged on disk.\n");
|
||||
window.__TEST__.emit("workspace-event", { root: "C:\\plain", kind: "modify", paths: ["a.md"] });
|
||||
});
|
||||
const banner = page.locator(".conflict");
|
||||
await banner.waitFor();
|
||||
assert.equal(await banner.locator("svg").count(), 1);
|
||||
assert.deepEqual(await banner.getByRole("button").allInnerTexts(), ["Keep my edits", "Save a copy", "Use disk version"]);
|
||||
const color = token => page.evaluate(token => { const probe = document.createElement("span"); probe.style.color = `var(${token})`; document.body.append(probe); const value = getComputedStyle(probe).color; probe.remove(); return value; }, token);
|
||||
assert.equal(await banner.getByRole("button", { name: "Use disk version" }).evaluate(node => getComputedStyle(node).color), await color("--rs-error"));
|
||||
assert.equal(await banner.evaluate(node => getComputedStyle(node).borderBottomColor), await color("--rs-warn"));
|
||||
await page.setViewportSize({ width: 880, height: 800 });
|
||||
assert.ok(await banner.evaluate(node => node.scrollWidth <= node.clientWidth + 1), "The banner wraps in a narrow pane");
|
||||
await page.screenshot({ path: `${output}/conflict-narrow.png` });
|
||||
await page.setViewportSize({ width: 1280, height: 800 });
|
||||
await banner.getByRole("button", { name: "Keep my edits" }).click();
|
||||
await banner.waitFor({ state: "detached" });
|
||||
|
||||
// Read follows CommonMark soft breaks by default. The setting keeps each source line break.
|
||||
await page.keyboard.press("Control+s");
|
||||
await chooseView(page, "Read");
|
||||
const paragraph = page.locator(".md-page .reading p").first();
|
||||
assert.equal(await paragraph.evaluate(node => getComputedStyle(node).whiteSpace), "normal");
|
||||
await page.evaluate(() => window.__TEST__.writeSettings("general", { ...window.__TEST__.settings("general"), keepLineBreaks: true }));
|
||||
await page.waitForFunction(() => getComputedStyle(document.querySelector(".md-page .reading p")).whiteSpace === "pre-line");
|
||||
await page.evaluate(() => window.__TEST__.writeSettings("general", { ...window.__TEST__.settings("general"), keepLineBreaks: false }));
|
||||
await chooseView(page, "Write");
|
||||
|
||||
// A plain table cell has no hover hint, because the footer shows its address. The controls show while a cell has focus.
|
||||
await open("table.md");
|
||||
const table = page.locator(".live-writer .writer-table");
|
||||
await table.waitFor();
|
||||
await table.locator("td").first().hover();
|
||||
await page.waitForTimeout(500);
|
||||
assert.equal(await page.locator(".rs-tooltip:popover-open").count(), 0);
|
||||
await table.locator("td").first().click();
|
||||
await page.waitForFunction(() => getComputedStyle(document.querySelector(".writer-table .table-add")).opacity === "1");
|
||||
await page.keyboard.press("Escape");
|
||||
|
||||
// The outline and the status bar follow the active tab: a tab without a document has no outline and no document facts.
|
||||
await page.evaluate(() => window.__TEST__.emit("runestone-theme-editor-open", null));
|
||||
await page.getByRole("tab", { name: "Theme editor", exact: true, selected: true }).waitFor();
|
||||
await page.waitForFunction(() => !/Ln \d/.test(document.querySelector(".status").textContent));
|
||||
assert.equal(await page.locator("aside.right li").count(), 0);
|
||||
assert.deepEqual(page.errors, []);
|
||||
console.log("PASS: status bar facts, Save, Don't save, and Cancel on close, conflict banner order and colors, line break setting, table hints and controls, panes that follow the active tab.");
|
||||
});
|
||||
@@ -0,0 +1,146 @@
|
||||
// Document splits: independent modes, edits, saves, selections, and conflicts per pane; nested relative links; narrow stacking; and the close guard.
|
||||
import assert from "node:assert/strict";
|
||||
import { chooseView, mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("layout/splits", async ({ page }) => {
|
||||
const output = await outputDir("layout/splits");
|
||||
page.on("console", message => { if (message.text().includes("binding_property_non_reactive")) page.errors.push(message.text()); });
|
||||
// The checks need edits to stay unsaved; autosave runs every 5 s by default (src/lib/workspace/settings.ts:12, src/lib/layout/Workbench.svelte:1165).
|
||||
await page.addInitScript(() => localStorage.setItem("runestone.settings", JSON.stringify({ autosaveEnabled: false })));
|
||||
await mockTauri(page, {
|
||||
state: { answer: "Cancel" },
|
||||
commands: test => {
|
||||
const workspace = test.workspace({
|
||||
root: "C:\\tab-menu-workspace",
|
||||
files: {
|
||||
"a.md": "# Alpha\n\nOrigin paragraph.\n\n[[notes/b.md|Right note]]\n",
|
||||
"b.md": "# b.md\n\nOriginal text.\n\n```js\nconst answer = 42;\n```\n\n| Name | Value |\n| --- | --- |\n| Alpha | One |\n",
|
||||
"c.md": "# c.md\n\nOriginal text.\n\n```js\nconst answer = 42;\n```\n\n| Name | Value |\n| --- | --- |\n| Alpha | One |\n",
|
||||
"d.md": "# d.md\n\nOriginal text.\n\n```js\nconst answer = 42;\n```\n\n| Name | Value |\n| --- | --- |\n| Alpha | One |\n",
|
||||
"notes/b.md": "# Bravo\n\nSecond paragraph.\n\n[Relative](c.md)\n\n[[/a.md|Original note]]\n",
|
||||
"notes/c.md": "# Charlie\n\nThird paragraph.\n",
|
||||
"sample.txt": "const answer = 42;\n",
|
||||
},
|
||||
});
|
||||
Object.assign(test, { files: workspace.files, writes: [], prompts: [] });
|
||||
return {
|
||||
...workspace,
|
||||
workspace_write: args => {
|
||||
if (args.expected !== undefined && workspace.files.get(args.rel) !== args.expected) throw new Error("conflict");
|
||||
workspace.files.set(args.rel, args.contents);
|
||||
test.writes.push(args.rel);
|
||||
},
|
||||
spelling_menu_install: () => {},
|
||||
"plugin:dialog|message": args => { test.prompts.push(args.message); return test.state.answer; },
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
const pane = path => page.locator(`[data-document-path="${path}"]`);
|
||||
const item = name => page.getByRole('menuitem',{name,exact:true});
|
||||
async function openRight(path,label) {
|
||||
const current = pane(path);
|
||||
await current.locator('.cm-content').getByText(path === 'a.md' ? 'Origin paragraph.' : 'Second paragraph.',{exact:true}).click();
|
||||
await current.locator('.cm-content').getByText(label,{exact:true}).click({button:'right'});
|
||||
await item('Open to the right').click();
|
||||
}
|
||||
async function append(path, text) {
|
||||
const target=pane(path).locator('.cm-content');
|
||||
await target.click(); await page.keyboard.press('Control+End'); await page.keyboard.type(text);
|
||||
}
|
||||
async function text(path) { return pane(path).locator('.cm-content').evaluate(async node=> { const {EditorView}=await import('/node_modules/@codemirror/view/dist/index.js'); return EditorView.findFromDOM(node).state.doc.toString(); }); }
|
||||
async function focus(path) { await pane(path).locator('.cm-content').click(); }
|
||||
async function changeOnDisk(path, text) {
|
||||
await page.evaluate(([path, text]) => {
|
||||
window.__TEST__.files.set(path, text);
|
||||
window.__TEST__.emit("workspace-event", { root: "C:\\tab-menu-workspace", kind: "modify", paths: [path] });
|
||||
}, [path, text]);
|
||||
}
|
||||
await page.goto(smokeUrl);
|
||||
await page.locator('[data-tree-rel="a.md"]').click(); await pane('a.md').locator('.cm-content').waitFor();
|
||||
await append('a.md','\nLeft unsaved.');
|
||||
await openRight('a.md','Right note'); await pane('notes/b.md').locator('.cm-content').waitFor();
|
||||
assert.equal(await page.locator('.document-pane').count(),2);
|
||||
assert.match(await text('a.md'),/Left unsaved/);
|
||||
await append('notes/b.md','\nRight saved.'); await page.keyboard.press('Control+s');
|
||||
await page.waitForFunction(()=>window.__TEST__.writes.includes('notes/b.md'));
|
||||
assert.equal(await page.evaluate(()=>window.__TEST__.writes.includes('a.md')),false,'Save uses the focused right pane');
|
||||
await focus('a.md'); await page.keyboard.press('Control+s'); await page.waitForFunction(()=>window.__TEST__.writes.includes('a.md'));
|
||||
await chooseView(pane('notes/b.md'), 'Source'); await pane('notes/b.md').locator('.source-editor .cm-content').waitFor();
|
||||
assert.equal(await pane('a.md').locator('.cm-content').count(),1,'Changing the right mode keeps the left editor');
|
||||
await openRight('a.md','Right note');
|
||||
assert.equal(await page.locator('.document-pane').count(),2);
|
||||
await page.waitForFunction(()=>!!document.activeElement?.matches('[data-document-path="notes/b.md"] .source-editor .cm-content')); await page.keyboard.press('Control+End'); await page.keyboard.type('\nSource edit.'); await page.keyboard.press('Control+s');
|
||||
await page.waitForFunction(()=>window.__TEST__.files.get('notes/b.md').includes('Source edit.'));
|
||||
await chooseView(pane('notes/b.md'), 'Write'); await pane('notes/b.md').locator('.cm-content').waitFor();
|
||||
assert.match(await text('notes/b.md'),/Source edit/);
|
||||
await chooseView(pane('notes/b.md'), 'Read'); await pane('notes/b.md').locator('.reading').waitFor();
|
||||
assert.equal(await pane('a.md').locator('.reading').count(),0,'Reading mode belongs to its pane');
|
||||
await focus('a.md'); assert.equal(await pane('notes/b.md').locator('.reading').count(),1);
|
||||
await chooseView(pane('notes/b.md'), 'Write'); await pane('notes/b.md').locator('.cm-content').waitFor();
|
||||
for(const path of ['a.md','notes/b.md']) await pane(path).locator('.cm-content').evaluate(async node=> {
|
||||
const {EditorView}=await import('/node_modules/@codemirror/view/dist/index.js'); const v=EditorView.findFromDOM(node); const source=v.state.doc.toString(); const from=source.indexOf(source.includes('Alpha') ? 'Origin' : 'Second'); v.dispatch({selection:{anchor:from,head:from+6}});
|
||||
});
|
||||
// Read the selection of each pane editor. Each editor keeps its own selection.
|
||||
const selections=(await Promise.all(['a.md','notes/b.md'].map(path=>pane(path).locator('.cm-content').evaluate(async node=> { const {EditorView}=await import('/node_modules/@codemirror/view/dist/index.js'); const {state}=EditorView.findFromDOM(node); return state.sliceDoc(state.selection.main.from,state.selection.main.to); })))).filter(Boolean).sort();
|
||||
assert.deepEqual(selections,['Origin','Second'],'Each pane retains its own selection');
|
||||
await openRight('a.md','Right note'); assert.equal(await page.locator('.document-pane').count(),2);
|
||||
await page.waitForFunction(()=>document.activeElement?.closest('[data-document-path]')?.dataset.documentPath==='notes/b.md');
|
||||
await openRight('notes/b.md','Original note'); assert.equal(await page.locator('.document-pane').count(),2);
|
||||
await page.waitForFunction(()=>document.activeElement?.closest('[data-document-path]')?.dataset.documentPath==='a.md');
|
||||
await append('notes/b.md','\nRight still unsaved.');
|
||||
for(const theme of ['light','dark']) {
|
||||
await page.evaluate(async mode=> { const {saveAppearance}=await import('/src/lib/theme/appearance.ts'); saveAppearance({theme:'default',mode}); },theme);
|
||||
await page.screenshot({path:`${output}/two-editors-${theme}.png`});
|
||||
}
|
||||
await pane('notes/b.md').getByRole('button',{name:'Close split',exact:true}).click();
|
||||
assert.equal(await page.locator('.document-pane').count(),1); assert.equal(await pane('a.md').count(),1);
|
||||
assert.match(await text('a.md'),/Left unsaved/);
|
||||
assert.equal(await page.getByRole('tab').count(),2,'Closing a split preserves both tabs');
|
||||
await page.getByRole('tab',{name:/b.md/}).click(); await pane('notes/b.md').locator('.cm-content').waitFor();
|
||||
assert.match(await text('notes/b.md'),/Right still unsaved/,'The closed split retains its unsaved buffer');
|
||||
await page.getByRole('tab',{name:/a.md/}).click(); await openRight('a.md','Right note'); await pane('notes/b.md').locator('.cm-content').waitFor();
|
||||
await openRight('notes/b.md','Relative'); await pane('notes/c.md').locator('.cm-content').waitFor();
|
||||
assert.equal(await page.locator('.document-pane').count(),3);
|
||||
assert.match(await text('notes/c.md'),/Charlie/,'Relative links use the pane document folder');
|
||||
await pane('notes/c.md').getByRole('button',{name:'Close split',exact:true}).click();
|
||||
assert.equal(await page.locator('.document-pane').count(),2);
|
||||
await changeOnDisk('notes/b.md','# Bravo disk\n\nExternal update.\n');
|
||||
await pane('notes/b.md').getByRole('alert').waitFor();
|
||||
assert.equal(await pane('a.md').getByRole('alert').count(),0);
|
||||
assert.match(await text('notes/b.md'),/Right still unsaved/,'A disk conflict preserves the right pane edits');
|
||||
await focus('a.md');
|
||||
await pane('notes/b.md').getByRole('button',{name:'Use disk version',exact:true}).click();
|
||||
await page.waitForFunction(()=>document.querySelector('[data-document-path="notes/b.md"] .cm-content')?.textContent.includes('External update.'));
|
||||
assert.match(await text('a.md'),/Left unsaved/,'Resolving the other pane cannot replace the primary buffer');
|
||||
await page.getByRole('button',{name:'Files',exact:true}).click(); await page.getByRole('button',{name:'Hide outline',exact:true}).click();
|
||||
await page.setViewportSize({width:560,height:740});
|
||||
for(const theme of ['light','dark']) {
|
||||
await page.evaluate(async mode=> { const {saveAppearance}=await import('/src/lib/theme/appearance.ts'); saveAppearance({theme:'default',mode}); },theme);
|
||||
const first=await pane('a.md').boundingBox(), second=await pane('notes/b.md').boundingBox();
|
||||
assert.ok(first.width>500 && second.width>500 && second.y>=first.y+first.height-1,'Narrow panes stack with readable widths');
|
||||
await page.screenshot({path:`${output}/stacked-${theme}.png`});
|
||||
}
|
||||
await append('notes/b.md','\nNarrow edit.'); await page.keyboard.press('Control+s');
|
||||
await page.waitForFunction(()=>window.__TEST__.files.get('notes/b.md').includes('Narrow edit.'));
|
||||
await pane('notes/b.md').getByRole('button',{name:'Close split',exact:true}).click();
|
||||
await append('a.md','\nAfter closing split.'); await page.keyboard.press('Control+s');
|
||||
await page.waitForFunction(()=>window.__TEST__.files.get('a.md').includes('After closing split.'));
|
||||
await page.setViewportSize({width:1440,height:1000});
|
||||
await openRight('a.md','Right note'); await pane('notes/b.md').locator('.cm-content').waitFor();
|
||||
await append('notes/b.md','\nClose guard.');
|
||||
await page.keyboard.press('Control+w');
|
||||
await page.waitForFunction(()=>window.__TEST__.prompts.length>0);
|
||||
assert.equal(await pane('notes/b.md').count(),1,'Cancel keeps the dirty split open');
|
||||
await page.keyboard.press('Control+s'); await page.waitForFunction(()=>window.__TEST__.files.get('notes/b.md').includes('Close guard.'));
|
||||
await page.keyboard.press('Control+w'); await pane('notes/b.md').waitFor({state:'detached'});
|
||||
await focus('a.md'); await append('a.md','\nOther tab closed.'); await page.keyboard.press('Control+s');
|
||||
await page.waitForFunction(()=>window.__TEST__.files.get('a.md').includes('Other tab closed.'));
|
||||
// A closed tab releases its editor state. The reopened note has no undo history.
|
||||
await openRight('a.md','Right note'); await pane('notes/b.md').locator('.cm-content').waitFor();
|
||||
const reopened=await text('notes/b.md');
|
||||
assert.match(reopened,/Close guard\./);
|
||||
await focus('notes/b.md'); await page.keyboard.press('Control+z');
|
||||
assert.equal(await text('notes/b.md'),reopened,'Closing the tab releases only its editor state');
|
||||
console.log(JSON.stringify({passed:['independent Writer/Source/Reading modes','dirty close cancellation and editor state release','independent edits and saves','per-pane selections','focus existing duplicate target','closing split retains unsaved tabs','nested relative link origin','per-pane conflict resolution','narrow layout and save','light/dark screenshots'],nativeDesktop:'not tested'},null,2));
|
||||
}, { timeout: 15000 });
|
||||
@@ -0,0 +1,138 @@
|
||||
// The title bar and the side pane: the bottom bar with the workspace switcher, Help, and Settings, the ribbon fallback, readable tabs with a list of all tabs, the drag area, caption buttons, Snap Layouts, and the macOS layout.
|
||||
import assert from "node:assert/strict";
|
||||
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
const names = ["meeting-notes", "research-plan", "inbox", "field-notes", "weekly-review", "reading-list", "project-ideas", "travel", "budget", "journal", "recipes"];
|
||||
|
||||
await runSmoke("layout/titleBar", async ({ browser }) => {
|
||||
const output = await outputDir("layout/titleBar");
|
||||
const context = await browser.newContext({ viewport: { width: 1280, height: 720 } });
|
||||
await mockTauri(context, {
|
||||
state: { names },
|
||||
commands: test => ({
|
||||
...test.workspace({ root: "C:\\Users\\me\\Documents\\Field work", files: Object.fromEntries(test.state.names.map(name => [`notes/${name}.md`, `# ${name}\n\nText.\n`])) }),
|
||||
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
|
||||
"plugin:window|is_maximized": () => false,
|
||||
window_snap_layouts: () => null,
|
||||
}),
|
||||
});
|
||||
const page = await openPage(context);
|
||||
async function open(name) {
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill(`${name}.md`);
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: `${name}.md` }).first().click();
|
||||
await page.getByRole("tab", { name: `${name}.md`, exact: true, selected: true }).waitFor();
|
||||
}
|
||||
const box = locator => locator.evaluate(node => { const rect = node.getBoundingClientRect(); return { x: rect.x, right: rect.right, width: rect.width, height: rect.height, bottom: rect.bottom }; });
|
||||
|
||||
await page.goto(smokeUrl);
|
||||
// The bar at the bottom of the side pane holds the workspace switcher, Help, and Settings, as in Obsidian.
|
||||
// The switcher opens the workspace list above it.
|
||||
const workspace = page.getByRole("button", { name: "Field work", exact: true });
|
||||
await workspace.waitFor();
|
||||
// Auto-save stays off, so the edited tab keeps its unsaved mark.
|
||||
await page.evaluate(() => window.__TEST__.writeSettings("general", { autosaveEnabled: false, autosaveSeconds: 5 }));
|
||||
const footer = page.locator("aside.left .left-footer");
|
||||
assert.equal(await footer.locator(".workspace-button").count(), 1);
|
||||
assert.equal(await footer.getByRole("button", { name: "Help and about (F1)", exact: true }).count(), 1);
|
||||
assert.equal(await footer.getByRole("button", { name: "Settings (Ctrl+,)", exact: true }).count(), 1);
|
||||
assert.equal(await page.locator("header.header .workspace-button").count(), 0);
|
||||
// The header right keeps only Save, the outline toggle, and the window controls. The other tools are in the left ribbon.
|
||||
assert.deepEqual(await page.locator(".header-right").getByRole("button").evaluateAll(nodes => nodes.map(node => node.getAttribute("aria-label"))),
|
||||
["Save", "Hide outline", "Minimize window", "Maximize window", "Close window"]);
|
||||
const ribbon = page.locator(".plugin-ribbon");
|
||||
assert.equal(await ribbon.getByRole("button", { name: "Settings (Ctrl+,)", exact: true }).count(), 0, "The ribbon has no second copy while the pane is open");
|
||||
await workspace.click();
|
||||
const picker = page.getByRole("dialog", { name: "Workspaces" });
|
||||
await picker.waitFor();
|
||||
assert.ok(await picker.evaluate((node, top) => node.getBoundingClientRect().bottom <= top, (await workspace.boundingBox()).y));
|
||||
await page.screenshot({ path: `${output}/bottom-bar.png` });
|
||||
await page.keyboard.press("Escape");
|
||||
|
||||
// While the side pane is closed, the workspace switcher, Help, and Settings move to the bottom of the ribbon.
|
||||
await page.keyboard.press("Control+\\");
|
||||
await page.locator("aside.left").waitFor({ state: "detached" });
|
||||
const ribbonSwitcher = ribbon.getByRole("button", { name: "Open folder (Ctrl+O)", exact: true });
|
||||
await ribbonSwitcher.click();
|
||||
await picker.waitFor();
|
||||
const switcherBox = await ribbonSwitcher.boundingBox(), pickerBox = await picker.boundingBox();
|
||||
assert.ok(pickerBox.y + pickerBox.height <= switcherBox.y + 1 && pickerBox.x < 100, JSON.stringify({ switcherBox, pickerBox }));
|
||||
await page.screenshot({ path: `${output}/ribbon-fallback.png` });
|
||||
await page.keyboard.press("Escape");
|
||||
await ribbon.getByRole("button", { name: "Help and about (F1)", exact: true }).click();
|
||||
await page.getByRole("dialog", { name: "Help and about" }).waitFor();
|
||||
await page.getByRole("button", { name: "Close help", exact: true }).click();
|
||||
assert.equal(await ribbon.getByRole("button", { name: "Settings (Ctrl+,)", exact: true }).isVisible(), true);
|
||||
assert.equal((await box(ribbon)).width, 44);
|
||||
await page.keyboard.press("Control+\\");
|
||||
await page.locator("aside.left").waitFor();
|
||||
|
||||
// Tabs keep a readable width and scroll. Fades show hidden tabs, and the list names every tab.
|
||||
for (const name of names) await open(name);
|
||||
const widths = await page.locator("header .tab").evaluateAll(tabs => tabs.map(tab => tab.getBoundingClientRect().width));
|
||||
assert.ok(widths.every(width => width >= 120), JSON.stringify(widths));
|
||||
const strip = page.locator("header .tabs");
|
||||
assert.equal(await strip.evaluate(node => node.classList.contains("fade-start")), true);
|
||||
assert.equal(await strip.evaluate(node => node.classList.contains("fade-end")), false, "The active last tab is in view with its close button");
|
||||
await page.locator(".cm-content").click();
|
||||
await page.keyboard.type("Edit ");
|
||||
// An unsaved tab adds " •" to its name.
|
||||
await page.getByRole("tab", { name: /^recipes.md/ }).click({ button: "right" });
|
||||
await page.getByRole("menuitem", { name: "Pin", exact: true }).click();
|
||||
await page.getByRole("button", { name: "All tabs", exact: true }).click();
|
||||
const list = page.getByRole("menu", { name: "All tabs", exact: true });
|
||||
await list.waitFor();
|
||||
assert.equal(await list.getByRole("menuitemradio").count(), names.length);
|
||||
const recipes = list.getByRole("menuitemradio", { name: /^recipes\.md/ });
|
||||
assert.equal(await recipes.getAttribute("aria-checked"), "true");
|
||||
assert.match(await recipes.innerText(), /Unsaved/);
|
||||
assert.equal(await recipes.locator("svg").count(), 1, "The pinned tab shows the pin icon");
|
||||
await page.screenshot({ path: `${output}/all-tabs.png` });
|
||||
await list.getByRole("menuitemradio", { name: "inbox.md", exact: true }).click();
|
||||
await page.getByRole("tab", { name: "inbox.md", exact: true, selected: true }).waitFor();
|
||||
await list.waitFor({ state: "detached" });
|
||||
assert.equal(await strip.evaluate(node => node.classList.contains("fade-end")), true);
|
||||
|
||||
// A fixed drag area follows the tabs. Caption buttons are square and fill the title bar height.
|
||||
const drag = page.locator(".window-drag-space");
|
||||
assert.equal(Math.round((await box(drag)).width), 120);
|
||||
assert.equal(await drag.getAttribute("data-tauri-drag-region"), "");
|
||||
const captions = await page.locator(".window-controls .icon-btn").evaluateAll(buttons => buttons.map(button => ({ width: button.getBoundingClientRect().width, height: button.getBoundingClientRect().height, radius: getComputedStyle(button).borderRadius })));
|
||||
const height = (await box(page.locator("header.header"))).height;
|
||||
assert.deepEqual(captions, Array(3).fill({ width: 46, height, radius: "0px" }));
|
||||
// Resting on maximize asks the host for Snap Layouts. A short pass does not.
|
||||
const calls = () => page.evaluate(() => window.__TEST__.calls.filter(call => call.command === "window_snap_layouts").length);
|
||||
await page.getByRole("button", { name: "Maximize window", exact: true }).hover();
|
||||
await page.mouse.move(600, 400);
|
||||
await page.waitForTimeout(700);
|
||||
assert.equal(await calls(), 0);
|
||||
await page.getByRole("button", { name: "Maximize window", exact: true }).hover();
|
||||
await page.waitForFunction(() => window.__TEST__.calls.some(call => call.command === "window_snap_layouts"));
|
||||
await page.mouse.move(600, 400);
|
||||
|
||||
for (const theme of ["dark", "light"]) {
|
||||
await page.evaluate(async mode => { const { saveAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ theme: "default", mode }); window.dispatchEvent(new Event("focus")); }, theme);
|
||||
await page.waitForFunction(mode => document.documentElement.dataset.theme === mode, theme);
|
||||
await page.locator("header.header").screenshot({ path: `${output}/header-${theme}.png` });
|
||||
}
|
||||
await page.setViewportSize({ width: 880, height: 560 });
|
||||
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth));
|
||||
assert.ok((await box(page.locator(".window-controls"))).right <= 880);
|
||||
await page.screenshot({ path: `${output}/narrow.png` });
|
||||
|
||||
// macOS keeps its native traffic lights: no caption buttons, and room at the start of the title bar.
|
||||
const mac = await openPage(context);
|
||||
await mac.addInitScript(() => {
|
||||
Object.defineProperty(navigator, "platform", { get: () => "MacIntel" });
|
||||
Object.defineProperty(navigator, "userAgentData", { get: () => ({ platform: "macOS" }) });
|
||||
});
|
||||
await mac.goto(smokeUrl);
|
||||
await mac.getByRole("button", { name: "Field work", exact: true }).waitFor();
|
||||
assert.equal(await mac.evaluate(() => document.documentElement.dataset.titleBar), "mac");
|
||||
assert.equal(await mac.locator(".window-controls").count(), 0);
|
||||
assert.equal(await mac.locator(".header-left").evaluate(node => getComputedStyle(node).paddingLeft), "82px");
|
||||
assert.match(await mac.getByRole("button", { name: "Settings (⌘,)", exact: true }).getAttribute("aria-label"), /⌘/);
|
||||
await mac.locator("header.header").screenshot({ path: `${output}/header-mac.png` });
|
||||
assert.deepEqual([...page.errors, ...mac.errors], []);
|
||||
console.log("PASS: bottom bar of the side pane, ribbon fallback, readable tabs with fades and a list, fixed drag area, square caption buttons, Snap Layouts request, macOS layout, both themes, narrow window.");
|
||||
});
|
||||
@@ -0,0 +1,149 @@
|
||||
// The view control: Write, Source, and Read always visible, the Split toggle, keys, the status bar, the breadcrumb, the file title setting, narrow panes, and both themes.
|
||||
import assert from "node:assert/strict";
|
||||
import { chooseView, mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("layout/viewModes", async ({ browser }) => {
|
||||
const output = await outputDir("layout/viewModes");
|
||||
const context = await browser.newContext({ viewport: { width: 1200, height: 760 } });
|
||||
await mockTauri(context, {
|
||||
commands: test => ({
|
||||
...test.workspace({
|
||||
root: "C:\\view-modes",
|
||||
files: {
|
||||
"notes/field-notes.md": "# Project field notes\n\nFirst paragraph with **bold** text.\n",
|
||||
"top.md": "# Top\n\nRoot note.\n",
|
||||
"src/hello.py": "print('hello')\n",
|
||||
},
|
||||
}),
|
||||
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
|
||||
}),
|
||||
});
|
||||
const page = await openPage(context), settings = await openPage(context);
|
||||
const group = page.getByRole("radiogroup", { name: "View", exact: true });
|
||||
const radio = name => group.getByRole("radio", { name, exact: true });
|
||||
const split = page.locator(".chrome-bar").getByRole("button", { name: "Split", exact: true });
|
||||
const checked = () => group.getByRole("radio", { checked: true }).getAttribute("aria-label");
|
||||
const status = () => page.locator(".status").innerText();
|
||||
async function open(name) {
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
|
||||
await page.getByRole("tab", { name, exact: true, selected: true }).waitFor();
|
||||
}
|
||||
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText("view-modes", { exact: true }).waitFor();
|
||||
await open("field-notes.md");
|
||||
await page.getByRole("textbox", { name: "Writing editor", exact: true }).waitFor();
|
||||
|
||||
// All choices stay visible, and the pointer does not move them.
|
||||
assert.deepEqual(await group.getByRole("radio").evaluateAll(nodes => nodes.map(node => node.getAttribute("aria-label"))), ["Write", "Source", "Read"]);
|
||||
assert.equal(await checked(), "Write");
|
||||
assert.equal(await split.getAttribute("aria-pressed"), "false");
|
||||
const boxes = () => group.getByRole("radio").evaluateAll(nodes => nodes.map(node => JSON.stringify(node.getBoundingClientRect())));
|
||||
const before = await boxes();
|
||||
await radio("Source").hover();
|
||||
assert.deepEqual(await boxes(), before);
|
||||
// Hover gets a fill. Only the current choice gets the accent bar.
|
||||
const look = name => radio(name).evaluate(node => ({ fill: getComputedStyle(node).backgroundColor, bar: getComputedStyle(node).boxShadow }));
|
||||
const [hovered, current] = [await look("Source"), await look("Write")];
|
||||
assert.notEqual(hovered.fill, "rgba(0, 0, 0, 0)");
|
||||
assert.equal(hovered.bar, "none");
|
||||
assert.match(current.bar, /inset/);
|
||||
assert.notEqual(hovered.fill, current.fill);
|
||||
|
||||
// The tab names the file, so the breadcrumb shows only its folder and the status bar shows only the view.
|
||||
assert.equal(await page.locator(".breadcrumb").innerText(), "notes");
|
||||
assert.equal(await page.locator(".breadcrumb").getAttribute("title"), "notes/field-notes.md");
|
||||
assert.doesNotMatch(await status(), /field-notes/);
|
||||
assert.match(await status(), /Write$/);
|
||||
|
||||
// The group has one Tab stop. Arrow keys, Home, and End move the choice.
|
||||
assert.deepEqual(await group.getByRole("radio").evaluateAll(nodes => nodes.map(node => node.tabIndex)), [0, -1, -1]);
|
||||
await radio("Write").focus();
|
||||
await page.keyboard.press("ArrowRight");
|
||||
await page.locator(".source-editor .cm-gutters").waitFor();
|
||||
assert.equal(await checked(), "Source");
|
||||
assert.equal(await page.evaluate(() => document.activeElement?.getAttribute("aria-label")), "Source");
|
||||
assert.match(await status(), /Source$/);
|
||||
await page.keyboard.press("End");
|
||||
await page.locator(".md-page .reading").waitFor();
|
||||
assert.equal(await checked(), "Read");
|
||||
assert.match(await status(), /Read$/);
|
||||
await page.keyboard.press("Home");
|
||||
await page.locator(".live-writer").waitFor();
|
||||
assert.equal(await checked(), "Write");
|
||||
|
||||
// Ctrl+Shift+E switches between Read and the editor. Ctrl+E switches between Write and Source.
|
||||
await page.locator(".cm-content").click();
|
||||
await page.keyboard.press("Control+Shift+E");
|
||||
await page.locator(".md-page .reading").waitFor();
|
||||
await page.keyboard.press("Control+Shift+E");
|
||||
await page.locator(".live-writer").waitFor();
|
||||
await page.keyboard.press("Control+e");
|
||||
await page.locator(".source-editor").waitFor();
|
||||
await page.keyboard.press("Control+e");
|
||||
await page.locator(".live-writer").waitFor();
|
||||
|
||||
// Split shows Read beside the current editor. Write and Source keep it. Read ends it.
|
||||
await chooseView(page, "Split");
|
||||
assert.equal(await split.getAttribute("aria-pressed"), "true");
|
||||
await page.locator(".body.split .live-writer").waitFor();
|
||||
await page.locator(".body.split .md-page").waitFor();
|
||||
await chooseView(page, "Source");
|
||||
await page.locator(".body.split .source-editor").waitFor();
|
||||
assert.equal(await split.getAttribute("aria-pressed"), "true");
|
||||
await chooseView(page, "Read");
|
||||
assert.equal(await split.getAttribute("aria-pressed"), "false");
|
||||
assert.equal(await page.locator(".body.split").count(), 0);
|
||||
assert.equal(await page.locator(".editor-wrap").isVisible(), false);
|
||||
await chooseView(page, "Split");
|
||||
await page.locator(".body.split .source-editor").waitFor();
|
||||
assert.equal(await checked(), "Source");
|
||||
await chooseView(page, "Split");
|
||||
await chooseView(page, "Write");
|
||||
|
||||
// The file title shows by default. The General setting hides it in Write and Read.
|
||||
assert.equal(await page.locator(".live-writer .document-title").count(), 1);
|
||||
await settings.goto(smokeUrl + "/?settingsWindow=true");
|
||||
await settings.getByRole("button", { name: "General", exact: true }).click();
|
||||
const titleSwitch = settings.getByRole("switch", { name: "File name title", exact: true });
|
||||
assert.equal(await titleSwitch.isChecked(), true);
|
||||
await titleSwitch.uncheck();
|
||||
await page.waitForFunction(() => !document.querySelector(".live-writer .document-title"));
|
||||
await chooseView(page, "Read");
|
||||
await page.locator(".md-page .reading").waitFor();
|
||||
assert.equal(await page.locator(".md-page .document-title").count(), 0);
|
||||
await titleSwitch.check();
|
||||
await page.locator(".md-page .document-title").waitFor();
|
||||
await chooseView(page, "Write");
|
||||
await page.locator(".live-writer .document-title").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 }); window.dispatchEvent(new Event("focus")); }, theme);
|
||||
await page.waitForFunction(mode => document.documentElement.dataset.theme === mode, theme);
|
||||
await page.locator(".chrome-bar").screenshot({ path: `${output}/bar-${theme}.png` });
|
||||
await chooseView(page, "Split");
|
||||
await page.locator(".chrome-bar").screenshot({ path: `${output}/bar-split-${theme}.png` });
|
||||
await chooseView(page, "Split");
|
||||
}
|
||||
|
||||
// The controls show icons only, at every width (UI-056). The names stay for assistive technology and tooltips.
|
||||
assert.equal(await page.locator(".chrome-bar").evaluate(bar => [...bar.querySelectorAll(".view-modes button, button.split")].map(button => button.textContent.trim()).join("")), "");
|
||||
// The side panes give way first in a narrow window.
|
||||
await page.setViewportSize({ width: 520, height: 600 });
|
||||
await page.locator("aside.left").waitFor({ state: "detached" });
|
||||
assert.equal(await radio("Read").getAttribute("aria-label"), "Read");
|
||||
assert.ok(await page.locator(".chrome-bar").evaluate(node => node.scrollWidth <= node.clientWidth + 1));
|
||||
await page.locator(".chrome-bar").screenshot({ path: `${output}/bar-narrow.png` });
|
||||
await page.setViewportSize({ width: 1200, height: 760 });
|
||||
|
||||
// Other text files have Write and Source only. A file at the workspace root has no folder in the breadcrumb.
|
||||
await open("hello.py");
|
||||
assert.deepEqual(await group.getByRole("radio").evaluateAll(nodes => nodes.map(node => node.getAttribute("aria-label"))), ["Write", "Source"]);
|
||||
assert.equal(await split.count(), 0);
|
||||
await open("top.md");
|
||||
assert.equal(await page.locator(".breadcrumb").innerText(), "");
|
||||
assert.deepEqual([...page.errors, ...settings.errors], []);
|
||||
console.log("PASS: visible view choices, hover and current states, radio keys, Ctrl+E and Ctrl+Shift+E, Split, status bar, breadcrumb, file title setting, narrow panes, both themes.");
|
||||
});
|
||||
@@ -0,0 +1,65 @@
|
||||
// Custom window controls: maximize, restore, minimize, the terminal close guard, the keyboard tooltip, and the header at 1400 and 880 px.
|
||||
import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { mockTauri, outputDir, repoRoot, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("layout/windowControls", async ({ page }) => {
|
||||
const output = await outputDir("layout/windowControls");
|
||||
await mockTauri(page, {
|
||||
state: { maximized: false, confirm: "Cancel" },
|
||||
commands: test => ({
|
||||
workspace_last_path: () => null,
|
||||
"plugin:window|is_maximized": () => test.state.maximized,
|
||||
"plugin:window|toggle_maximize": () => { test.state.maximized = !test.state.maximized; test.emit("tauri://resize", { width: 1400, height: 900 }); },
|
||||
"plugin:window|minimize": () => {},
|
||||
"plugin:window|destroy": () => {},
|
||||
"plugin:window|close": () => { test.emit("tauri://close-requested"); },
|
||||
"plugin:dialog|message": () => test.state.confirm,
|
||||
}),
|
||||
});
|
||||
// The Terminal button belongs to the Terminal feature, which is on by default (src/lib/features/catalog.ts).
|
||||
const called = command => page.evaluate(command => window.__TEST__.calls.some(call => call.command === command), command);
|
||||
|
||||
const config = JSON.parse(await readFile(path.join(repoRoot, "src-tauri/tauri.conf.json"), "utf8"));
|
||||
assert.equal(config.app.windows[0].decorations, false);
|
||||
const capability = JSON.parse(await readFile(path.join(repoRoot, "src-tauri/capabilities/default.json"), "utf8"));
|
||||
for (const permission of ["close", "minimize", "toggle-maximize", "start-dragging"]) {
|
||||
assert.ok(capability.permissions.includes(`core:window:allow-${permission}`));
|
||||
}
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByRole("button", { name: "Maximize window", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Restore window", exact: true }).waitFor();
|
||||
await page.getByRole("button", { name: "Restore window", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Maximize window", exact: true }).waitFor();
|
||||
// Native maximize/restore (e.g. double-clicking the drag region) updates the button too.
|
||||
await page.evaluate(() => { window.__TEST__.state.maximized = true; window.__TEST__.emit("tauri://resize", { width: 1920, height: 1080 }); });
|
||||
await page.getByRole("button", { name: "Restore window", exact: true }).waitFor();
|
||||
await page.getByRole("button", { name: "Minimize window", exact: true }).click();
|
||||
assert.ok(await called("plugin:window|minimize"));
|
||||
await page.getByRole("button", { name: "Close window", exact: true }).focus();
|
||||
await page.getByRole("tooltip", { name: "Close window", exact: true }).waitFor();
|
||||
// Opening the terminal engages the existing close guard; cancellation must not destroy the window.
|
||||
await page.getByRole("button", { name: "Terminal", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Close window", exact: true }).click();
|
||||
await page.waitForFunction(() => window.__TEST__.calls.some(call => call.command === "plugin:dialog|message"));
|
||||
assert.equal(await called("plugin:window|destroy"), false);
|
||||
await page.evaluate(() => window.__TEST__.state.confirm = "Ok");
|
||||
await page.getByRole("button", { name: "Close window", exact: true }).click();
|
||||
await page.waitForFunction(() => window.__TEST__.calls.some(call => call.command === "plugin:window|destroy"));
|
||||
await page.getByRole("button", { name: "Terminal", exact: true }).click();
|
||||
for (const width of [1400, 880]) {
|
||||
await page.setViewportSize({ width, height: 900 });
|
||||
const layout = await page.evaluate(() => {
|
||||
const header = document.querySelector(".header").getBoundingClientRect();
|
||||
const controls = [...document.querySelectorAll(".header button")].map(el => el.getBoundingClientRect());
|
||||
return { height: header.height, top: header.top, fits: controls.every(rect => rect.x >= 0 && rect.right <= innerWidth && rect.y >= header.y && rect.bottom <= header.bottom), drag: document.querySelector(".window-drag-space").getBoundingClientRect().width };
|
||||
});
|
||||
assert.equal(layout.height, 36);
|
||||
assert.equal(layout.top, 0);
|
||||
assert.ok(layout.fits);
|
||||
assert.ok(layout.drag >= 40);
|
||||
await page.screenshot({ path: path.join(output, `window-controls-${width}.png`) });
|
||||
}
|
||||
console.log("Window controls smoke passed: actions, restore state, close guard, keyboard tooltip, and 1400/880px layouts.");
|
||||
}, { viewport: { width: 1400, height: 900 }, timeout: 30000 });
|
||||
@@ -0,0 +1,770 @@
|
||||
// Core workbench: source edits and history, agent refresh and conflicts, persistent terminals, Reading and Mermaid previews, the live Writer, tables and their menus, and narrow layouts.
|
||||
import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { chooseView, mockTauri, outputDir, repoRoot, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("layout/workbench", async ({ page }) => {
|
||||
const output = await outputDir("layout/workbench");
|
||||
const showcase = await readFile(path.join(repoRoot, "fixtures/reader-showcase.md"), "utf8");
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
const workspace = test.workspace({
|
||||
root: "C:\\smoke-workspace",
|
||||
writeEvents: true,
|
||||
files: {
|
||||
"notes/welcome.md": "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n",
|
||||
"notes/second.md": "# Second note\n",
|
||||
"src/hello.py": "print('hello')\n",
|
||||
},
|
||||
});
|
||||
Object.assign(test, { files: workspace.files, root: workspace.root });
|
||||
// The Terminal feature opens its shells through the default `pty_*` handlers of the harness.
|
||||
return {
|
||||
...workspace,
|
||||
workspace_write: args => {
|
||||
if (args.expected !== undefined && workspace.files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk");
|
||||
return workspace.workspace_write(args);
|
||||
},
|
||||
workspace_search: () => [],
|
||||
"plugin:dialog|message": () => "Cancel",
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
async function quickOpen(name) {
|
||||
await page.keyboard.press("Control+p");
|
||||
await page.getByRole("textbox", { name: "Find a file" }).fill(name);
|
||||
await page.getByRole("dialog").getByRole("button").filter({ hasText: name }).first().click();
|
||||
await chooseView(page, "Source");
|
||||
await page.locator(".source-editor .cm-content").waitFor();
|
||||
}
|
||||
async function contents() {
|
||||
return page.evaluate(async () => {
|
||||
const { EditorView } = await import("/node_modules/@codemirror/view/dist/index.js");
|
||||
return EditorView.findFromDOM(document.querySelector(".source-editor .cm-content"))?.state.doc.toString();
|
||||
});
|
||||
}
|
||||
async function waitForText(text) {
|
||||
await page.evaluate(async () => { window.__EditorView = (await import("/node_modules/@codemirror/view/dist/index.js")).EditorView; });
|
||||
await page.waitForFunction(expected => window.__EditorView.findFromDOM(document.querySelector(".source-editor .cm-content"))?.state.doc.toString() === expected, text);
|
||||
}
|
||||
async function focusEditor() {
|
||||
await page.locator(".source-editor .cm-content").click({position:{x:120,y:12}});
|
||||
}
|
||||
|
||||
await page.goto(smokeUrl);
|
||||
await page.getByText("smoke-workspace", { exact: true }).waitFor();
|
||||
await quickOpen("welcome.md");
|
||||
const original = await contents();
|
||||
assert.ok(original.startsWith("---\ntitle:"));
|
||||
await focusEditor();
|
||||
await page.keyboard.press("Control+End");
|
||||
await page.keyboard.type("Added in source.");
|
||||
await waitForText(original + "Added in source.");
|
||||
await quickOpen("hello.py");
|
||||
await page.getByRole("tab", { name: /welcome\.md/ }).click();
|
||||
await focusEditor();
|
||||
await page.keyboard.press("Control+z");
|
||||
await page.waitForFunction(expected => window.__EditorView.findFromDOM(document.querySelector(".source-editor .cm-content"))?.state.doc.toString() !== expected, original + "Added in source.");
|
||||
await page.keyboard.press("Control+y");
|
||||
await waitForText(original + "Added in source.");
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(expected => window.__TEST__.files.get("notes/welcome.md") === expected, original + "Added in source.");
|
||||
|
||||
await chooseView(page, "Split");
|
||||
await page.locator(".md-page h1").first().waitFor();
|
||||
assert.ok(await page.locator(".source-editor").isVisible());
|
||||
await page.evaluate(() => {
|
||||
window.__TEST__.files.set("notes/welcome.md", "# Agent update\n");
|
||||
window.__TEST__.emit("workspace-event", { root: window.__TEST__.root, kind: "modify", paths: ["notes/welcome.md"] });
|
||||
});
|
||||
await waitForText("# Agent update\n");
|
||||
await focusEditor();
|
||||
await page.keyboard.press("Control+End");
|
||||
await page.keyboard.type("Local edit");
|
||||
await page.evaluate(() => {
|
||||
window.__TEST__.files.set("notes/welcome.md", "# Another agent edit\n");
|
||||
window.__TEST__.emit("workspace-event", { root: window.__TEST__.root, kind: "modify", paths: ["notes/welcome.md"] });
|
||||
});
|
||||
await page.getByRole("button", { name: "Keep my edits" }).waitFor();
|
||||
assert.equal(await contents(), "# Agent update\nLocal edit");
|
||||
await page.getByRole("button", { name: "Keep my edits" }).click();
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(() => window.__TEST__.files.get("notes/welcome.md") === "# Agent update\nLocal edit");
|
||||
|
||||
await page.getByRole("button", { name: "Terminal", exact: true }).click();
|
||||
await page.waitForFunction(() => window.__TEST__.calls.some(c => c.command === "pty_open"));
|
||||
await page.waitForFunction(() => window.__TEST__.calls.some(c => c.command === "pty_write" && /\x1b\[\d+;\d+R/.test(c.args.data)));
|
||||
await page.screenshot({ path: path.join(output, "core-rebuild-terminal.png") });
|
||||
await page.getByRole("button", { name: "Terminal", exact: true }).click();
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "pty_close").length), 0);
|
||||
await page.getByRole("button", { name: "Terminal", exact: true }).click();
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "pty_open").length), 1);
|
||||
await page.getByRole("button", { name: "New terminal", exact: true }).click();
|
||||
await page.waitForFunction(() => window.__TEST__.calls.filter(c => c.command === "pty_open").length === 2);
|
||||
await page.getByRole("button", { name: "Kill terminal", exact: true }).first().click();
|
||||
await page.waitForFunction(() => window.__TEST__.calls.filter(c => c.command === "pty_close").length === 1);
|
||||
await page.getByRole("button", { name: "Terminal", exact: true }).click();
|
||||
await page.keyboard.press("Control+n");
|
||||
await page.getByLabel("New file path relative to the workspace").fill("notes/new-note.md");
|
||||
await page.getByRole("button", { name: "Continue", exact: true }).click();
|
||||
await page.getByRole("tab", { name: "new-note.md", exact: true }).waitFor();
|
||||
// A new note starts in its filename field, which keeps its own keys (src/lib/editor/DocumentEditor.svelte:386-392, src/lib/editor/noteTitle.ts:80).
|
||||
await page.getByRole("textbox", { name: "Note filename", exact: true }).waitFor();
|
||||
await page.screenshot({ path: path.join(output, "core-rebuild.png") });
|
||||
await page.keyboard.press("Escape");
|
||||
|
||||
await page.evaluate(text => {
|
||||
window.__TEST__.files.set("reader-showcase.md", text);
|
||||
window.__TEST__.emit("workspace-event", { root: window.__TEST__.root, kind: "create", paths: ["reader-showcase.md"] });
|
||||
}, showcase);
|
||||
await quickOpen("reader-showcase.md");
|
||||
// Each view choice shows only an icon (UI-056). The accessible name and the tooltip give its name and shortcut (src/lib/layout/ViewModes.svelte).
|
||||
const read = page.getByRole("radiogroup", { name: "View", exact: true }).getByRole("radio", { name: "Read", exact: true });
|
||||
const readTip = page.getByRole("tooltip").filter({ hasText: "Read (Ctrl+Shift+E)" });
|
||||
assert.equal(await read.innerText(), "");
|
||||
assert.equal(await read.locator("svg").count(), 1);
|
||||
await read.hover();
|
||||
await readTip.waitFor({ state: "visible" });
|
||||
const tip = await readTip.boundingBox();
|
||||
assert.ok(tip.x >= 0 && tip.x + tip.width <= 1440);
|
||||
await read.click();
|
||||
assert.equal(await read.getAttribute("aria-checked"), "true");
|
||||
await page.locator(".reading h1:not(.document-title)").waitFor();
|
||||
assert.equal(await page.locator(".source-editor").isVisible(), false);
|
||||
assert.equal(await page.locator(".reading h1:not(.document-title)").innerText(), "Project field notes");
|
||||
assert.equal(await page.locator(".reading ol > li").count(), 3);
|
||||
assert.equal(await page.locator(".reading ol ul > li").count(), 2);
|
||||
assert.equal(await page.locator(".reading input:checked").count(), 2);
|
||||
assert.equal(await page.locator(".md-properties").getAttribute("open"), null);
|
||||
assert.ok((await page.locator(".reading > p").first().innerText()).includes("implementation notes"));
|
||||
const surface = await page.locator(".reading").boundingBox();
|
||||
assert.ok(surface.width <= 741);
|
||||
await page.mouse.move(700, 980);
|
||||
await page.screenshot({ path: path.join(output, "reader-mode.png") });
|
||||
await page.locator(".md-table-scroll").scrollIntoViewIfNeeded();
|
||||
await page.getByRole("button", { name: "Copy code", exact: true }).click();
|
||||
await page.getByRole("button", { name: "Copied", exact: true }).waitFor();
|
||||
await page.screenshot({ path: path.join(output, "reader-details.png") });
|
||||
|
||||
// At the minimum window width of 880 pixels the outline gives way, and Split stacks in the remaining pane.
|
||||
await page.setViewportSize({ width: 880, height: 900 });
|
||||
await page.locator(".md-page").evaluate(element => { element.scrollTop = 0; });
|
||||
await page.screenshot({ path: path.join(output, "reader-narrow.png") });
|
||||
assert.ok(await page.locator(".md-page").evaluate(element => element.scrollWidth <= element.clientWidth + 1));
|
||||
await chooseView(page, "Split");
|
||||
await page.waitForFunction(() => {
|
||||
const host = document.querySelector(".source-editor");
|
||||
const rendered = host?.querySelector(".cm-editor");
|
||||
return rendered && Math.abs(host.clientWidth - rendered.clientWidth) < 2;
|
||||
});
|
||||
assert.equal(await page.locator(".body.split").evaluate(element => getComputedStyle(element).flexDirection), "column");
|
||||
await page.screenshot({ path: path.join(output, "reader-split.png") });
|
||||
assert.ok(await page.locator(".md-page").evaluate(element => element.scrollWidth <= element.clientWidth + 1));
|
||||
|
||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||||
await page.waitForFunction(() => getComputedStyle(document.querySelector(".body.split")).flexDirection === "row");
|
||||
await page.screenshot({ path: path.join(output, "reader-split-wide.png") });
|
||||
|
||||
// A second press ends the Split view.
|
||||
await chooseView(page, "Split");
|
||||
await page.locator(".md-page").waitFor({ state: "detached" });
|
||||
// The editor stores one line break character. The saved file keeps its own line breaks.
|
||||
assert.equal(await contents(), showcase.replace(/\r\n/g, "\n"));
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.files.get("reader-showcase.md")), showcase);
|
||||
await read.focus();
|
||||
await readTip.waitFor({ state: "visible" });
|
||||
await page.keyboard.press("Escape");
|
||||
await readTip.waitFor({ state: "hidden" });
|
||||
|
||||
// Continuous live Markdown: only active lines reveal source; checkboxes
|
||||
// remain inline and update the original file without HTML serialization.
|
||||
const writingSource = '---\ntitle: Preserved\n---\n\n# Writer preview\n\nA **formatted** paragraph.\n\n[Project link](https://example.com/old)\n\n- [ ] Ship draft\n- [x] Finished task\n\n```mermaid\nflowchart LR\n A[Draft] --> B[Publish]\n```\n\n```mermaid\nnot a valid diagram\n```\n\n- Parent\n - Child\n';
|
||||
await page.evaluate(text => {
|
||||
window.__TEST__.files.set("writing.md", text);
|
||||
window.__TEST__.emit("workspace-event", { root: window.__TEST__.root, kind: "create", paths: ["writing.md"] });
|
||||
}, writingSource);
|
||||
await quickOpen("writing.md");
|
||||
await chooseView(page, "Write");
|
||||
const writer = page.getByRole("textbox", { name: "Writing editor", exact: true });
|
||||
await writer.waitFor();
|
||||
assert.equal(await page.locator('.live-writer [contenteditable="true"]').count(), 1);
|
||||
assert.equal(await page.getByRole("toolbar", { name: "Text formatting" }).count(), 0);
|
||||
await page.locator(".live-writer .md-diagram svg").waitFor({ timeout: 30000 });
|
||||
await page.getByRole("status").filter({ hasText: "Diagram could not render" }).waitFor();
|
||||
const paragraph = page.locator(".live-writer .cm-line").filter({ hasText: "A formatted paragraph." });
|
||||
await paragraph.click();
|
||||
await page.locator(".live-writer .cm-line").filter({ hasText: "A **formatted** paragraph." }).waitFor();
|
||||
await page.keyboard.press("Home");
|
||||
await page.keyboard.type("New ");
|
||||
await page.keyboard.press("Control+s");
|
||||
const editedSource = writingSource.replace("A **formatted**", "New A **formatted**");
|
||||
await page.waitForFunction(text => window.__TEST__.files.get("writing.md") === text, editedSource);
|
||||
await page.keyboard.press("Control+z");
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(text => window.__TEST__.files.get("writing.md") === text, writingSource);
|
||||
await page.keyboard.press("Control+y");
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(text => window.__TEST__.files.get("writing.md") === text, editedSource);
|
||||
await chooseView(page, "Source");
|
||||
await waitForText(editedSource);
|
||||
await focusEditor();
|
||||
await page.keyboard.press("Control+z");
|
||||
await waitForText(writingSource);
|
||||
await chooseView(page, "Write");
|
||||
await writer.waitFor();
|
||||
// Write keeps the caret of the Source undo, so the paragraph can show its source.
|
||||
await page.locator(".live-writer .cm-line").filter({ hasText: /A (\*\*)?formatted(\*\*)? paragraph\./ }).click();
|
||||
await page.keyboard.press("End");
|
||||
await page.keyboard.press("Enter");
|
||||
await page.keyboard.press("Enter");
|
||||
await page.keyboard.type("First new paragraph.");
|
||||
await page.keyboard.press("Enter");
|
||||
await page.keyboard.press("Enter");
|
||||
await page.keyboard.type("**Second new paragraph.**");
|
||||
await page.keyboard.press("Enter");
|
||||
await page.keyboard.press("Enter");
|
||||
await page.keyboard.type("Third new paragraph.");
|
||||
assert.equal(await page.locator(".live-writer .writer-strong").filter({ hasText: "Second new paragraph." }).count(), 1);
|
||||
await page.keyboard.press("Home");
|
||||
await page.keyboard.press("Shift+ArrowUp");
|
||||
await page.keyboard.press("Shift+ArrowUp");
|
||||
assert.ok((await page.evaluate(() => window.getSelection().toString())).includes("Second new paragraph."));
|
||||
await page.keyboard.press("Backspace");
|
||||
await page.keyboard.press("Control+z");
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(() => window.__TEST__.files.get("writing.md").includes("First new paragraph.\n\n**Second new paragraph.**\n\nThird new paragraph."));
|
||||
assert.ok(await writer.evaluate(el => el.contains(document.activeElement)));
|
||||
|
||||
// Link syntax becomes editable on a normal click, without opening the link.
|
||||
await page.locator('.live-writer .writer-link').filter({ hasText: "Project link" }).click();
|
||||
await page.locator('.live-writer .cm-line').filter({ hasText: "[Project link](https://example.com/old)" }).waitFor();
|
||||
await page.keyboard.press("End");
|
||||
await page.keyboard.press("Home");
|
||||
await page.keyboard.press("Shift+End");
|
||||
await page.keyboard.type("[Project link](https://example.com/new)");
|
||||
await page.keyboard.press("ArrowDown");
|
||||
await page.locator('.live-writer [data-href="https://example.com/new"]').waitFor();
|
||||
const task = page.locator('.live-writer .cm-line').filter({ hasText: "Ship draft" });
|
||||
const checkbox = task.getByRole("checkbox");
|
||||
assert.ok(await task.evaluate(line => {
|
||||
const box = line.querySelector('input').getBoundingClientRect();
|
||||
const text = [...line.childNodes].find(node => node.nodeType === Node.TEXT_NODE && node.textContent.includes('Ship draft'));
|
||||
const range = document.createRange(); range.selectNode(text);
|
||||
const label = range.getBoundingClientRect();
|
||||
return Math.abs((box.top + box.bottom) / 2 - (label.top + label.bottom) / 2) < 8 && box.right <= label.left;
|
||||
}));
|
||||
await checkbox.click();
|
||||
await task.locator('.writer-completed').waitFor();
|
||||
assert.equal(await task.locator('.writer-completed').evaluate(el => getComputedStyle(el).textDecorationLine), 'line-through');
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(() => window.__TEST__.files.get("writing.md").includes('- [x] Ship draft'));
|
||||
// Task markers stay rendered until the cursor reaches them (src/lib/editor/liveMarkdown.ts:262-268).
|
||||
await task.locator('.writer-completed').click();
|
||||
await page.keyboard.press("Home");
|
||||
await page.locator('.live-writer .cm-line').filter({ hasText: '- [x] Ship draft' }).waitFor();
|
||||
await page.keyboard.press("Shift+End");
|
||||
await page.keyboard.type('- [ ] Revised task');
|
||||
await page.keyboard.press("ArrowUp");
|
||||
await page.locator('.live-writer .cm-line').filter({ hasText: 'Revised task' }).getByRole('checkbox', { checked: false }).waitFor();
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(() => window.__TEST__.files.get("writing.md").includes('- [ ] Revised task'));
|
||||
await page.locator(".live-writer .md-diagram svg").waitFor();
|
||||
await page.screenshot({ path: path.join(output, "writing-continuous.png") });
|
||||
await page.setViewportSize({ width: 1000, height: 900 });
|
||||
assert.ok(await page.locator(".cm-scroller").evaluate(el => el.scrollWidth <= el.clientWidth + 1));
|
||||
await page.evaluate(() => {
|
||||
window.__TEST__.files.set("crlf.md", "# Windows note\r\n\r\nA paragraph.\r\n\r\nTail stays intact.\r\n");
|
||||
window.__TEST__.emit("workspace-event", { root: window.__TEST__.root, kind: "create", paths: ["crlf.md"] });
|
||||
});
|
||||
await quickOpen("crlf.md");
|
||||
await chooseView(page, "Write");
|
||||
await page.locator(".live-writer .cm-line").filter({ hasText: "A paragraph." }).click();
|
||||
await page.keyboard.press("Home");
|
||||
await page.keyboard.type("Changed ");
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(() => window.__TEST__.files.get("crlf.md") === "# Windows note\r\n\r\nChanged A paragraph.\r\n\r\nTail stays intact.\r\n");
|
||||
await page.keyboard.press("Control+n");
|
||||
await page.getByLabel("New file path relative to the workspace").fill("blank.md");
|
||||
await page.getByRole("button", { name: "Continue", exact: true }).click();
|
||||
// Enter keeps the new note's filename and moves to its body (src/lib/editor/noteTitle.ts:57, 83).
|
||||
await page.getByRole("textbox", { name: "Note filename", exact: true }).press("Enter");
|
||||
await writer.waitFor();
|
||||
await page.keyboard.type("One");
|
||||
await page.keyboard.press("Enter");
|
||||
await page.keyboard.type("Two");
|
||||
await page.keyboard.press("Enter");
|
||||
await page.keyboard.type("Three");
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(() => window.__TEST__.files.get("blank.md").replace(/\r\n/g, "\n") === "One\nTwo\nThree");
|
||||
await page.getByRole("tab", { name: "crlf.md", exact: true }).click();
|
||||
await page.getByRole("tab", { name: "blank.md", exact: true }).click();
|
||||
await writer.waitFor();
|
||||
await page.keyboard.press("Control+z");
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(() => window.__TEST__.files.get("blank.md").replace(/\r\n/g, "\n") !== "One\nTwo\nThree");
|
||||
await page.keyboard.press("Control+y");
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(() => window.__TEST__.files.get("blank.md").replace(/\r\n/g, "\n") === "One\nTwo\nThree");
|
||||
await page.keyboard.press("Control+f");
|
||||
// The find field is labelled "Find in document" (src/lib/editor/FindPanel.svelte:60).
|
||||
await page.getByRole("textbox", { name: "Find in document", exact: true }).fill("Two");
|
||||
await page.keyboard.press("Escape");
|
||||
await page.keyboard.press("Control+a");
|
||||
await page.keyboard.type("- [ ] First task");
|
||||
await page.keyboard.press("Enter");
|
||||
await page.keyboard.type("Second task");
|
||||
await page.keyboard.press("Control+s");
|
||||
await page.waitForFunction(() => window.__TEST__.files.get("blank.md").replace(/\r\n/g, "\n") === "- [ ] First task\n- [ ] Second task");
|
||||
await page.evaluate(() => {
|
||||
window.__TEST__.files.set("blank.md", "Fresh disk version\r\n");
|
||||
window.__TEST__.emit("workspace-event", { root: window.__TEST__.root, kind: "modify", paths: ["blank.md"] });
|
||||
});
|
||||
await page.locator('.live-writer .cm-line').filter({ hasText: 'Fresh disk version' }).waitFor();
|
||||
await page.keyboard.press("Control+z");
|
||||
assert.ok((await writer.innerText()).includes("Fresh disk version"));
|
||||
|
||||
const tableSource = '# Table layout\n\n| Ticker | Name | Exchange | Products/Service | Notes |\n| :--- | --- | --- | --- | --- |\n| IBKR.US | Interactive Brokers Group Inc | NASDAQ | Broker | Rebuild the trading interface.<br>Keep listings consistent.<br>Introduce automated investing.<br>Make the API usable and document common errors. |\n| CBOE.US | Cboe Global Markets Inc | BATS | Exchange | Operations;<br>- Trading |\n\nAfter the table.\n';
|
||||
await page.evaluate(text => {
|
||||
window.__TEST__.files.set("tables.md", text);
|
||||
window.__TEST__.emit("workspace-event", { root: window.__TEST__.root, kind: "create", paths: ["tables.md"] });
|
||||
}, tableSource);
|
||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||||
await quickOpen("tables.md");
|
||||
await chooseView(page, "Write");
|
||||
const table = page.locator('.live-writer table');
|
||||
await table.waitFor();
|
||||
assert.equal(await page.locator('.live-writer .document-title').innerText(), 'tables');
|
||||
const tableHeading = page.locator('.live-writer .writer-heading');
|
||||
await tableHeading.click();
|
||||
assert.equal(await tableHeading.innerText(), '# Table layout');
|
||||
await table.locator('tbody tr').first().locator('td').first().click();
|
||||
await page.waitForFunction(() => document.querySelector('.live-writer .writer-heading')?.textContent === 'Table layout');
|
||||
// The add controls show while a cell of the table has focus (src/lib/editor/DocumentEditor.svelte).
|
||||
await page.waitForFunction(() => [...document.querySelectorAll('.table-add')].every(button => getComputedStyle(button).opacity === '1'));
|
||||
await page.keyboard.press('Control+s');
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.files.get('tables.md')), tableSource);
|
||||
assert.equal(await table.locator('th').count(), 5);
|
||||
assert.equal(await table.locator('tbody tr').count(), 2);
|
||||
assert.equal(await table.locator('br').count(), 4);
|
||||
assert.ok(!(await table.innerText()).includes('<br>'));
|
||||
// Columns keep the 3rem minimum width (`.reading th, .reading td` in src/lib/layout/reading.css; reduced from 8rem in 909894b).
|
||||
assert.ok(await table.locator('th').evaluateAll(cells => {
|
||||
const minimum = 3 * parseFloat(getComputedStyle(document.documentElement).fontSize);
|
||||
return cells.every(cell => cell.getBoundingClientRect().width >= minimum - 0.5);
|
||||
}));
|
||||
assert.ok(await table.locator('td').evaluateAll(cells => cells.every(cell => getComputedStyle(cell).verticalAlign === 'top')));
|
||||
assert.ok(await page.locator('.cm-scroller').evaluate(el => el.scrollWidth <= el.clientWidth + 1));
|
||||
const addColumn = page.getByRole('button', { name: 'Add column to the right', exact: true });
|
||||
const addRow = page.getByRole('button', { name: 'Add row below', exact: true });
|
||||
// The add controls show on hover, and also while a cell of the table has focus. This part checks hover alone.
|
||||
await page.evaluate(() => document.activeElement?.blur());
|
||||
await addColumn.hover();
|
||||
await page.waitForFunction(() => getComputedStyle(document.querySelector('.table-add-column')).opacity === '1');
|
||||
assert.equal(await addRow.evaluate(el => getComputedStyle(el).opacity), '0');
|
||||
await table.locator('td').first().hover();
|
||||
await page.waitForFunction(() => [...document.querySelectorAll('.table-add')].every(button => getComputedStyle(button).opacity === '0'));
|
||||
await addColumn.hover();
|
||||
await page.waitForFunction(() => getComputedStyle(document.querySelector('.table-add-column')).opacity === '1');
|
||||
await page.screenshot({ path: path.join(output, 'writing-table-column.png') });
|
||||
await addColumn.click();
|
||||
await page.waitForFunction(() => document.querySelectorAll('.live-writer th').length === 6);
|
||||
await addRow.hover();
|
||||
await page.waitForFunction(() => getComputedStyle(document.querySelector('.table-add-row')).opacity === '1');
|
||||
await page.screenshot({ path: path.join(output, 'writing-table-row.png') });
|
||||
await addRow.click();
|
||||
await page.waitForFunction(() => document.querySelectorAll('.live-writer tbody tr').length === 3);
|
||||
await page.keyboard.press('Control+s');
|
||||
await page.waitForFunction(() => window.__TEST__.files.get('tables.md').includes('| | | | | | |'));
|
||||
assert.ok((await page.evaluate(() => window.__TEST__.files.get('tables.md'))).endsWith('\n\nAfter the table.\n'));
|
||||
await page.keyboard.press('Control+z');
|
||||
await page.waitForFunction(() => document.querySelectorAll('.live-writer tbody tr').length === 2);
|
||||
await page.keyboard.press('Control+z');
|
||||
await page.keyboard.press('Control+s');
|
||||
await page.waitForFunction(expected => window.__TEST__.files.get('tables.md') === expected, tableSource);
|
||||
await page.keyboard.press('Control+y');
|
||||
await page.keyboard.press('Control+y');
|
||||
await table.locator('th').last().click();
|
||||
const cellEditor = page.locator('.writer-cell-editor');
|
||||
await cellEditor.waitFor();
|
||||
assert.equal(await table.locator('th').count(), 6);
|
||||
assert.equal(await page.locator('.live-writer .cm-line').filter({ hasText: '| Ticker |' }).count(), 0);
|
||||
await page.keyboard.type('New column');
|
||||
await page.keyboard.press('Control+s');
|
||||
await page.waitForFunction(() => window.__TEST__.files.get('tables.md').includes('New column'));
|
||||
await page.keyboard.press('Tab');
|
||||
assert.ok(await table.locator('tbody tr').first().locator('td').first().locator('.writer-cell-editor').count());
|
||||
await page.keyboard.press('Shift+Tab');
|
||||
assert.ok(await table.locator('th').last().locator('.writer-cell-editor').count());
|
||||
await table.locator('tbody tr').first().locator('td').nth(4).click();
|
||||
assert.equal(await cellEditor.locator('br:not(.ProseMirror-trailingBreak)').count(), 3);
|
||||
await page.keyboard.press('Control+End');
|
||||
// Shift+Enter adds a line break in a cell; Enter moves to the next row (src/lib/editor/tableControls.ts:278-286).
|
||||
await page.keyboard.press('Shift+Enter');
|
||||
await page.keyboard.type('Plain | pipe and *stars*');
|
||||
await page.keyboard.press('Control+s');
|
||||
await page.waitForFunction(() => window.__TEST__.files.get('tables.md').includes('<br>Plain \\| pipe and \\*stars\\*'));
|
||||
assert.equal(await table.locator('th').count(), 6);
|
||||
await page.screenshot({ path: path.join(output, 'writing-table-cell-edit.png') });
|
||||
await page.keyboard.press('Control+z');
|
||||
await page.keyboard.press('Control+s');
|
||||
await page.waitForFunction(() => !window.__TEST__.files.get('tables.md').includes('Plain'));
|
||||
await cellEditor.waitFor();
|
||||
await page.keyboard.press('Control+y');
|
||||
await page.keyboard.press('Control+s');
|
||||
await page.waitForFunction(() => window.__TEST__.files.get('tables.md').includes('Plain'));
|
||||
await page.keyboard.press('Escape');
|
||||
await page.locator('.live-writer .cm-line').filter({ hasText: 'After the table.' }).click();
|
||||
const beforeVisit = await page.evaluate(() => window.__TEST__.files.get('tables.md'));
|
||||
await table.locator('tbody tr').first().locator('td').nth(4).click();
|
||||
await page.keyboard.press('Escape');
|
||||
await page.keyboard.press('Control+s');
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.files.get('tables.md')), beforeVisit);
|
||||
await table.locator('tbody tr').last().locator('td').last().click();
|
||||
await page.keyboard.press('Tab');
|
||||
await page.waitForFunction(() => document.querySelectorAll('.live-writer tbody tr').length === 4);
|
||||
await table.locator('tbody tr').last().locator('td').first().locator('.writer-cell-editor').waitFor();
|
||||
await page.keyboard.press('Escape');
|
||||
await page.setViewportSize({ width: 1000, height: 900 });
|
||||
assert.ok(await page.locator('.cm-scroller').evaluate(el => el.scrollWidth <= el.clientWidth + 1));
|
||||
await chooseView(page, 'Read');
|
||||
assert.equal(await page.locator('.md-page .document-title').innerText(), 'tables');
|
||||
assert.equal(await page.locator('.md-page table br').count(), 5);
|
||||
assert.ok(await page.locator('.md-page').evaluate(el => el.scrollWidth <= el.clientWidth + 1));
|
||||
|
||||
const selectionTable = '| A | B | C |\n| --- | --- | --- |\n| one | two | three |\n| four | five | six |\n\nAfter.\n';
|
||||
await page.evaluate(text => {
|
||||
window.__TEST__.files.set('selection-table.md', text);
|
||||
window.__TEST__.emit('workspace-event', { root: window.__TEST__.root, kind: 'create', paths: ['selection-table.md'] });
|
||||
window.__TEST__.clipboard = '';
|
||||
// Cell copies write plain text and HTML through clipboard.write (src/lib/editor/tableSelectionControls.ts:80-85).
|
||||
Object.defineProperty(navigator, 'clipboard', { configurable: true, value: {
|
||||
write: async items => { window.__TEST__.clipboard = await (await items[0].getType('text/plain')).text(); },
|
||||
writeText: async text => { window.__TEST__.clipboard = text; },
|
||||
readText: async () => window.__TEST__.clipboard,
|
||||
} });
|
||||
}, selectionTable);
|
||||
await quickOpen('selection-table.md');
|
||||
await chooseView(page, 'Write');
|
||||
const selectedTable = page.locator('.live-writer table');
|
||||
const selectedCell = (r, c) => selectedTable.locator('tr').nth(r).locator('th, td').nth(c);
|
||||
const fromCell = await selectedCell(1, 0).boundingBox(), toCell = await selectedCell(2, 1).boundingBox();
|
||||
await page.mouse.move(fromCell.x + 15, fromCell.y + 15);
|
||||
await page.mouse.down();
|
||||
await page.mouse.move(toCell.x + 15, toCell.y + 15, { steps: 12 });
|
||||
await page.mouse.up();
|
||||
assert.equal(await selectedTable.locator('.is-cell-selected').count(), 4);
|
||||
await selectedCell(1, 0).click({ button: 'right' });
|
||||
await page.getByRole('menuitem', { name: 'Format', exact: true }).hover();
|
||||
await page.getByRole('menuitem', { name: 'Bold', exact: true }).waitFor();
|
||||
await page.screenshot({ path: path.join(output, 'table-cell-selection-menu.png') });
|
||||
await page.getByRole('menuitem', { name: 'Bold', exact: true }).click();
|
||||
await page.waitForFunction(() => document.querySelectorAll('.live-writer table strong').length === 4);
|
||||
await page.waitForFunction(() => document.querySelectorAll('.is-cell-selected').length === 4);
|
||||
await page.keyboard.press('Control+i');
|
||||
await page.waitForFunction(() => document.querySelectorAll('.live-writer table em').length === 4);
|
||||
await page.keyboard.press('Control+z');
|
||||
await page.waitForFunction(() => document.querySelectorAll('.live-writer table em').length === 0);
|
||||
assert.equal(await selectedTable.locator('strong').count(), 4);
|
||||
await selectedCell(1, 0).click();
|
||||
await selectedCell(2, 1).click({ modifiers: ['Shift'] });
|
||||
assert.equal(await selectedTable.locator('.is-cell-selected').count(), 4);
|
||||
async function cellAction(name, formatted = false) {
|
||||
await selectedTable.locator('.is-cell-selected').first().click({ button: 'right' });
|
||||
if (formatted) await page.getByRole('menuitem', { name: 'Format', exact: true }).hover();
|
||||
await page.getByRole('menuitem', { name, exact: true }).click();
|
||||
}
|
||||
await cellAction('Clear formatting', true);
|
||||
await page.waitForFunction(() => document.querySelectorAll('.live-writer table strong').length === 0);
|
||||
await cellAction('Copy Ctrl+C');
|
||||
// clipboard.write resolves its items asynchronously.
|
||||
await page.waitForFunction(expected => window.__TEST__.clipboard === expected, 'one\ttwo\nfour\tfive');
|
||||
await cellAction('Cut Ctrl+X');
|
||||
await page.waitForFunction(() => [...document.querySelectorAll('.is-cell-selected')].every(cell => !cell.textContent.trim()));
|
||||
await cellAction('Paste Ctrl+V');
|
||||
await page.waitForFunction(() => document.querySelector('.live-writer tbody td').textContent === 'one');
|
||||
await cellAction('Align centre');
|
||||
await page.waitForFunction(() => [...document.querySelectorAll('.is-cell-selected')].every(cell => cell.style.textAlign === 'center'));
|
||||
for (const [name, selector] of [['Highlight', 'mark'], ['Math', '[data-cell-format="math"]'], ['Comment', '[data-cell-format="comment"]'], ['Code', 'code'], ['Strikethrough', 's']]) {
|
||||
await cellAction(name, true);
|
||||
await page.waitForFunction(selector => document.querySelectorAll(`.live-writer table ${selector}`).length === 4, selector);
|
||||
await cellAction('Clear formatting', true);
|
||||
}
|
||||
// Native clipboard events must operate on the rectangle, including one-step undo.
|
||||
await page.locator('.writer-table').evaluate(el => {
|
||||
const data = new DataTransfer(); data.setData('text/plain', 'red\tblue\ngreen\tyellow');
|
||||
el.dispatchEvent(new ClipboardEvent('paste', { clipboardData: data, bubbles: true, cancelable: true }));
|
||||
});
|
||||
await page.waitForFunction(() => document.querySelector('.live-writer tbody td').textContent === 'red');
|
||||
await page.keyboard.press('Control+z');
|
||||
await page.waitForFunction(() => document.querySelector('.live-writer tbody td').textContent === 'one');
|
||||
await selectedCell(1, 0).click();
|
||||
await selectedCell(2, 1).click({ modifiers: ['Shift'] });
|
||||
await cellAction('Delete cells');
|
||||
await page.waitForFunction(() => document.querySelector('.live-writer tbody td').textContent === 'three');
|
||||
assert.equal(await selectedTable.locator('th').count(), 3);
|
||||
await page.keyboard.press('Control+z');
|
||||
await page.waitForFunction(() => document.querySelector('.live-writer tbody td').textContent === 'one');
|
||||
await selectedCell(1, 0).click();
|
||||
await selectedCell(1, 0).click({ modifiers: ['Shift'] });
|
||||
await page.keyboard.press('Control+a');
|
||||
assert.equal(await selectedTable.locator('.is-cell-selected').count(), 9);
|
||||
await cellAction('Delete cells');
|
||||
await page.waitForFunction(() => document.querySelectorAll('.live-writer table').length === 0);
|
||||
await page.keyboard.press('Control+z');
|
||||
await selectedTable.waitFor();
|
||||
for (const [name, selector] of [['Highlight', 'mark'], ['Math', '[data-cell-format="math"]'], ['Comment', '[data-cell-format="comment"]']]) {
|
||||
await selectedCell(1, 0).click();
|
||||
await selectedCell(1, 0).click({ modifiers: ['Shift'] });
|
||||
await selectedCell(1, 0).click({ button: 'right' });
|
||||
await page.getByRole('menuitem', { name: 'Format', exact: true }).hover();
|
||||
await page.getByRole('menuitem', { name, exact: true }).click();
|
||||
await selectedCell(1, 0).click();
|
||||
await page.keyboard.press('Control+End');
|
||||
await page.keyboard.type(' edited');
|
||||
await page.keyboard.press('Escape');
|
||||
assert.ok(await selectedCell(1, 0).locator(selector).count(), `${name} survives cell editing`);
|
||||
await selectedCell(1, 0).click();
|
||||
await selectedCell(1, 0).click({ modifiers: ['Shift'] });
|
||||
await selectedCell(1, 0).click({ button: 'right' });
|
||||
await cellAction('Clear formatting', true);
|
||||
}
|
||||
|
||||
const actionsSource = '| Name | Value |\n| :--- | ---: |\n| Interactive Brokers Group | 20 |\n| Apple | 3 |\n| Pear | 10 |\n\nAfter.\n';
|
||||
await page.evaluate(text => {
|
||||
window.__TEST__.files.set('table-actions.md', text);
|
||||
window.__TEST__.emit('workspace-event', { root: window.__TEST__.root, kind: 'create', paths: ['table-actions.md'] });
|
||||
}, actionsSource);
|
||||
await quickOpen('table-actions.md');
|
||||
await chooseView(page, 'Write');
|
||||
const actionTable = page.locator('.live-writer table');
|
||||
const actionCell = (r, c) => actionTable.locator('tr').nth(r).locator('th, td').nth(c);
|
||||
async function actionItem(label, group, r = 1, c = 0) {
|
||||
await actionCell(r, c).click({ button: 'right' });
|
||||
if (group) await page.getByRole('menuitem', { name: group, exact: true }).hover();
|
||||
await page.getByRole('menuitem', { name: label, exact: true }).click();
|
||||
}
|
||||
async function saveActionSource() {
|
||||
await page.keyboard.press('Control+s');
|
||||
return page.evaluate(() => window.__TEST__.files.get('table-actions.md'));
|
||||
}
|
||||
async function undoAction() {
|
||||
await page.keyboard.press('Control+z');
|
||||
await page.keyboard.press('Control+s');
|
||||
await page.waitForFunction(expected => window.__TEST__.files.get('table-actions.md') === expected, actionsSource);
|
||||
}
|
||||
for (const [label, group, r, c, rows, columns] of [
|
||||
['Add row above', 'Row', 1, 0, 5, 2], ['Add row below', 'Row', 2, 0, 5, 2], ['Duplicate row', 'Row', 1, 0, 5, 2], ['Delete row', 'Row', 1, 0, 3, 2],
|
||||
['Add column to the left', 'Column', 1, 0, 4, 3], ['Add column to the right', 'Column', 1, 1, 4, 3], ['Duplicate column', 'Column', 1, 1, 4, 3], ['Delete column', 'Column', 1, 1, 4, 1],
|
||||
]) {
|
||||
await actionItem(label, group, r, c);
|
||||
assert.equal(await actionTable.locator('tr').count(), rows, label);
|
||||
assert.equal(await actionTable.locator('th').count(), columns, label);
|
||||
await undoAction();
|
||||
}
|
||||
await actionItem('Move row down', 'Row');
|
||||
assert.equal(await actionCell(2, 0).innerText(), 'Interactive Brokers Group');
|
||||
await undoAction();
|
||||
await actionItem('Move row up', 'Row', 2);
|
||||
assert.equal(await actionCell(1, 0).innerText(), 'Apple');
|
||||
await undoAction();
|
||||
await actionItem('Move column right', 'Column');
|
||||
assert.equal(await actionCell(0, 0).innerText(), 'Value');
|
||||
assert.equal(await actionCell(1, 0).evaluate(el => el.style.textAlign), 'right');
|
||||
await undoAction();
|
||||
await actionItem('Move column left', 'Column', 1, 1);
|
||||
assert.equal(await actionCell(0, 0).innerText(), 'Value');
|
||||
await undoAction();
|
||||
await actionItem('Sort by column (A to Z)', undefined, 1, 1);
|
||||
assert.deepEqual(await actionTable.locator('tbody tr td:last-child').allTextContents(), ['3', '10', '20']);
|
||||
await undoAction();
|
||||
await actionItem('Sort by column (Z to A)', undefined, 1, 1);
|
||||
assert.deepEqual(await actionTable.locator('tbody tr td:last-child').allTextContents(), ['20', '10', '3']);
|
||||
await undoAction();
|
||||
await actionCell(0, 0).click({ button: 'right' });
|
||||
await page.getByRole('menuitem', { name: 'Row', exact: true }).hover();
|
||||
assert.ok(await page.getByRole('menuitem', { name: 'Add row above', exact: true }).isDisabled());
|
||||
assert.ok(await page.getByRole('menuitem', { name: 'Move row down', exact: true }).isDisabled());
|
||||
await page.keyboard.press('Escape');
|
||||
async function selectBrokers() {
|
||||
await actionCell(1, 0).click();
|
||||
await page.keyboard.press('Control+Home');
|
||||
for (let i = 0; i < 12; i++) await page.keyboard.press('ArrowRight');
|
||||
for (let i = 0; i < 7; i++) await page.keyboard.press('Shift+ArrowRight');
|
||||
assert.equal(await page.evaluate(() => getSelection().toString()), 'Brokers');
|
||||
}
|
||||
await selectBrokers();
|
||||
await actionCell(1, 0).click({ button: 'right' });
|
||||
assert.equal(await page.getByRole('menuitem', { name: 'Copy Ctrl+C', exact: true }).isDisabled(), false);
|
||||
assert.ok(await page.locator('.table-cell-menu button').evaluateAll(buttons => buttons.every(button => button.querySelector('svg[aria-hidden="true"]'))));
|
||||
await page.getByRole('menuitem', { name: 'Row', exact: true }).hover();
|
||||
await page.screenshot({ path: path.join(output, 'table-text-row-menu.png') });
|
||||
await page.getByRole('menuitem', { name: 'Column', exact: true }).hover();
|
||||
await page.screenshot({ path: path.join(output, 'table-text-column-menu.png') });
|
||||
await page.getByRole('menuitem', { name: 'Column', exact: true }).focus();
|
||||
await page.keyboard.press('ArrowRight');
|
||||
assert.equal(await page.evaluate(() => document.activeElement.textContent), 'Add column to the left');
|
||||
await page.keyboard.press('ArrowLeft');
|
||||
assert.equal(await page.evaluate(() => document.activeElement.textContent), 'Column');
|
||||
await page.keyboard.press('Escape');
|
||||
await actionItem('Bold', 'Format');
|
||||
assert.equal(await actionCell(1, 0).locator('strong').innerText(), 'Brokers');
|
||||
assert.ok((await saveActionSource()).includes('Interactive **Brokers** Group'));
|
||||
await actionItem('Add external link');
|
||||
await page.getByRole('dialog').locator('input').fill('https://example.com/brokers?q=1');
|
||||
await page.getByRole('button', { name: 'Continue', exact: true }).click();
|
||||
await page.waitForFunction(() => document.querySelector('.live-writer td a')?.getAttribute('href') === 'https://example.com/brokers?q=1');
|
||||
assert.equal(await actionCell(1, 0).locator('a').innerText(), 'Brokers');
|
||||
await page.keyboard.press('Control+z');
|
||||
await selectBrokers();
|
||||
await actionItem('Add link');
|
||||
await page.getByRole('dialog').locator('input').fill('notes/second');
|
||||
await page.getByRole('button', { name: 'Continue', exact: true }).click();
|
||||
await page.waitForFunction(() => document.querySelector('.live-writer td a')?.getAttribute('data-kind') === 'wiki');
|
||||
await page.keyboard.press('Control+z');
|
||||
await selectBrokers();
|
||||
await actionItem('Search for “Brokers”');
|
||||
await page.getByPlaceholder('Search files and notes').waitFor();
|
||||
assert.equal(await page.getByPlaceholder('Search files and notes').inputValue(), 'Brokers');
|
||||
await page.waitForFunction(() => window.__TEST__.calls.some(call => call.command === 'workspace_search' && call.args.query === 'Brokers'));
|
||||
await selectBrokers();
|
||||
await actionItem('Extract current selection…');
|
||||
await page.getByRole('dialog').locator('input').fill('extracted-brokers.md');
|
||||
await page.getByRole('button', { name: 'Continue', exact: true }).click();
|
||||
await page.waitForFunction(() => window.__TEST__.files.get('extracted-brokers.md') === '**Brokers**\n');
|
||||
await page.waitForFunction(() => document.querySelector('.live-writer td a')?.getAttribute('href') === '/extracted-brokers.md');
|
||||
await page.keyboard.press('Control+z');
|
||||
await selectBrokers();
|
||||
await page.evaluate(() => { window.__TEST__.clipboard = '<b>literal</b>\nnext'; });
|
||||
await actionItem('Paste as plain text');
|
||||
assert.ok((await saveActionSource()).includes('Interactive <') || (await saveActionSource()).includes('Interactive \\<b\\>literal\\</b\\><br>next'));
|
||||
assert.equal(await actionCell(1, 0).locator('b').count(), 0);
|
||||
await page.keyboard.press('Control+z');
|
||||
await selectBrokers();
|
||||
await page.evaluate(() => {
|
||||
navigator.clipboard.read = async () => [{ types: ['text/html', 'text/plain'], getType: async type => new Blob([type === 'text/html' ? '<em>Rich paste</em>' : 'Rich paste'], { type }) }];
|
||||
});
|
||||
await actionItem('Paste Ctrl+V');
|
||||
await page.waitForFunction(() => document.querySelector('.live-writer td em')?.textContent === 'Rich paste');
|
||||
await page.keyboard.press('Control+z');
|
||||
await page.evaluate(() => { delete navigator.clipboard.read; });
|
||||
await selectBrokers();
|
||||
await actionItem('Copy Ctrl+C');
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.clipboard), 'Brokers');
|
||||
await actionItem('Cut Ctrl+X');
|
||||
await page.waitForFunction(() => !document.querySelector('.live-writer td').textContent.includes('Brokers'));
|
||||
await page.keyboard.press('Control+z');
|
||||
await selectBrokers();
|
||||
await actionItem('Select all Ctrl+A');
|
||||
assert.equal(await page.evaluate(() => getSelection().toString()), 'Interactive Brokers Group');
|
||||
await page.setViewportSize({ width: 800, height: 600 });
|
||||
await actionCell(1, 0).click({ button: 'right' });
|
||||
await page.getByRole('menuitem', { name: 'Column', exact: true }).hover();
|
||||
assert.ok(await page.locator('.table-cell-menu, .table-cell-submenu:popover-open').evaluateAll(panels => panels.every(panel => {
|
||||
const rect = panel.getBoundingClientRect(); return rect.left >= 0 && rect.top >= 0 && rect.right <= innerWidth && rect.bottom <= innerHeight;
|
||||
})));
|
||||
await page.keyboard.press('Escape');
|
||||
await page.setViewportSize({ width: 1000, height: 900 });
|
||||
|
||||
const richTable = '| Name | Notes |\r\n| :--- | ---: |\r\n| Untouched | ~~Old~~ **bold** [link](https://example.com) <br />Next |\r\n| Short |\r\n';
|
||||
await page.evaluate(text => {
|
||||
window.__TEST__.files.set('rich-table.md', text);
|
||||
window.__TEST__.emit('workspace-event', { root: window.__TEST__.root, kind: 'create', paths: ['rich-table.md'] });
|
||||
}, richTable);
|
||||
await quickOpen('rich-table.md');
|
||||
await chooseView(page, 'Write');
|
||||
const richCell = page.locator('.live-writer tbody tr').first().locator('td').last();
|
||||
assert.equal(await page.locator('.live-writer .document-title').innerText(), 'rich-table');
|
||||
await richCell.click();
|
||||
await page.keyboard.press('Control+s');
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.files.get('rich-table.md')), richTable);
|
||||
await page.keyboard.press('Control+End');
|
||||
await page.keyboard.type(' edited');
|
||||
await page.keyboard.press('Control+s');
|
||||
await page.waitForFunction(() => window.__TEST__.files.get('rich-table.md').includes('edited'));
|
||||
const richSaved = await page.evaluate(() => window.__TEST__.files.get('rich-table.md'));
|
||||
assert.ok(richSaved.includes('| Untouched |'));
|
||||
assert.ok(richSaved.includes('~~Old~~'));
|
||||
assert.ok(richSaved.includes('**bold**'));
|
||||
assert.ok(richSaved.includes('https://example.com'));
|
||||
assert.ok(richSaved.includes(''));
|
||||
assert.ok(richSaved.includes('<br>Next edited'));
|
||||
assert.ok(!/(?<!\r)\n/.test(richSaved));
|
||||
await page.keyboard.press('Escape');
|
||||
await richCell.click();
|
||||
await page.keyboard.press('Control+End');
|
||||
await page.keyboard.type(' again');
|
||||
await page.keyboard.press('Control+s');
|
||||
await page.waitForFunction(() => window.__TEST__.files.get('rich-table.md').includes('Next edited again'));
|
||||
const shortCell = page.locator('.live-writer tbody tr').last().locator('td').last();
|
||||
await shortCell.click();
|
||||
await cellEditor.evaluate(el => {
|
||||
const data = new DataTransfer(); data.setData('text/plain', 'Pasted | text\nSecond line');
|
||||
el.dispatchEvent(new ClipboardEvent('paste', { clipboardData: data, bubbles: true, cancelable: true }));
|
||||
});
|
||||
await page.keyboard.press('Control+s');
|
||||
await page.waitForFunction(() => window.__TEST__.files.get('rich-table.md').includes('Pasted \\| text<br>Second line'));
|
||||
await page.keyboard.press('Control+a');
|
||||
await page.keyboard.press('Control+b');
|
||||
await page.keyboard.press('Control+s');
|
||||
await page.waitForFunction(() => window.__TEST__.files.get('rich-table.md').includes('**Pasted \\| text**'));
|
||||
assert.equal(await page.locator('.live-writer th').count(), 2);
|
||||
|
||||
// Physical mouse coordinates below tall block widgets must resolve to the
|
||||
// visible line, including immediately adjacent heading/body lines.
|
||||
const longTable = '| Ticker | Name | Notes |\n| --- | --- | --- |\n' +
|
||||
Array.from({ length: 14 }, (_, index) => `| STOCK${index} | Company ${index} | First note<br>Second note<br>Third note |`).join('\n');
|
||||
const hitTestSource = `# Listed\n\n${longTable}\n\n# Tier 1\nTier one body directly below heading.\n\n${longTable}\n\n## Tier 2\nTier two body directly below heading.\n`;
|
||||
await page.evaluate(text => {
|
||||
window.__TEST__.files.set('table-hit-testing.md', text);
|
||||
window.__TEST__.emit('workspace-event', { root: window.__TEST__.root, kind: 'create', paths: ['table-hit-testing.md'] });
|
||||
}, hitTestSource);
|
||||
await quickOpen('table-hit-testing.md');
|
||||
await chooseView(page, 'Write');
|
||||
async function clickRenderedLine(locator, expected) {
|
||||
await locator.scrollIntoViewIfNeeded();
|
||||
const rect = await locator.boundingBox();
|
||||
assert.ok(rect);
|
||||
await page.mouse.click(rect.x + 45, rect.y + rect.height * .7);
|
||||
const actual = await page.evaluate(() => window.getSelection()?.anchorNode?.parentElement?.closest('.cm-line')?.textContent);
|
||||
assert.equal(actual, expected, `Mouse click on ${expected} landed on ${actual}`);
|
||||
}
|
||||
async function checkLinesAfterTables() {
|
||||
await page.locator('.cm-scroller').evaluate(async el => {
|
||||
el.scrollTop = 0;
|
||||
await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
|
||||
});
|
||||
for (const [heading, body] of [
|
||||
['# Tier 1', 'Tier one body directly below heading.'],
|
||||
['## Tier 2', 'Tier two body directly below heading.'],
|
||||
]) {
|
||||
const tables = page.locator('.live-writer .writer-table');
|
||||
await (heading === '# Tier 1' ? tables.first() : tables.last()).locator('.table-add-row').scrollIntoViewIfNeeded();
|
||||
await clickRenderedLine(page.locator('.live-writer .writer-heading').filter({ hasText: heading.replace(/^#+ /, '') }), heading);
|
||||
await page.keyboard.press('End');
|
||||
await page.keyboard.type(' edited');
|
||||
await page.keyboard.press('Control+s');
|
||||
await page.waitForFunction(text => window.__TEST__.files.get('table-hit-testing.md').includes(text + ' edited\n'), heading);
|
||||
await page.keyboard.press('Control+z');
|
||||
await clickRenderedLine(page.locator('.live-writer .cm-line').filter({ hasText: body }), body);
|
||||
}
|
||||
}
|
||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||||
await checkLinesAfterTables();
|
||||
await page.locator('.cm-scroller').evaluate(async el => {
|
||||
el.scrollTop = 0;
|
||||
await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
|
||||
});
|
||||
await page.locator('.live-writer table').first().locator('tbody tr').last().locator('td').last().click();
|
||||
await page.keyboard.press('Control+End');
|
||||
for (let line = 0; line < 4; line++) {
|
||||
await page.keyboard.press('Enter');
|
||||
await page.keyboard.type('A newly added line changes the table height.');
|
||||
}
|
||||
await checkLinesAfterTables();
|
||||
await page.setViewportSize({ width: 1000, height: 900 });
|
||||
await checkLinesAfterTables();
|
||||
await page.screenshot({ path: path.join(output, 'table-cursor-position.png') });
|
||||
console.log("PASS: continuous live Markdown, raw active lines, editable links and checklists, completed-task strikethrough, cross-line selection, preservation and history, search, table layout/line breaks/edge insertion/cell editing/undo, save, agent refresh, conflicts, persistent terminals, reader and Mermaid previews, narrow layouts (mocked desktop IPC).");
|
||||
});
|
||||
Reference in New Issue
Block a user