RuneStone 1.0.0

This commit is contained in:
Knotty Wyvern
2026-11-16 04:21:21 -07:00
commit b52eeb14a1
827 changed files with 241421 additions and 0 deletions
+149
View File
@@ -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: "Read beside", 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, "Read beside");
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, "Read beside");
await page.locator(".body.split .source-editor").waitFor();
assert.equal(await checked(), "Source");
await chooseView(page, "Read beside");
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, "Read beside");
await page.locator(".chrome-bar").screenshot({ path: `${output}/bar-split-${theme}.png` });
await chooseView(page, "Read beside");
}
// 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.");
});