Files
RuneStone/tests/smoke/layout/viewModes.smoke.mjs
T
Knotty Wyvern 9cf82503d0 Show one view control and name the file once
Phase 5-3.

- One radio group shows Write, Source, and Read at all times, with an
  icon and a name. Narrow panes show only the icons. The arrow keys
  move the choice, and the group has one Tab stop. The current choice
  gets the selection fill and an accent bar. Hover gets only a fill.
- A Split toggle shows Read beside Write or Source. Each document pane
  keeps a split flag beside its reading flag. Read ends Split.
- Ctrl+Shift+E switches between Read and the editor. Ctrl+E still
  switches between Write and Source.
- "IDE" becomes "Source" in the Chrome type, the tab menu (a View
  submenu), the status bar, the catalog, the tests, and the docs.
- Settings, General, File name title hides the title in Write and
  Read. It is on by default.
- The breadcrumb shows only the folder of the file. The status bar
  shows the view, not the path.
- ModeSwitcher.svelte and its hover test are gone. The new test
  layout/viewModes covers the control.
- The command palette from 5-2 gets its row in docs/menu-surfaces.json.
- The user guide Format table is whole again. The 5-2 edit had put
  the Paragraph and Insert rows under the shortcut table.
- 8 new catalog rows and 10 removed rows, in French, Japanese, and
  Simplified Chinese.
- Docs: UI-049, the user guide, ui-design.md, document-tools.md,
  development.md, and the README feature list.

Tests: the new layout/viewModes, new cases in documentPanes.spec.ts
and settings.spec.ts, and the chooseView harness helper. 21 smoke
tests use the new control. Tests that read the full path from the
breadcrumb now read its tooltip.
2026-10-28 19:45:08 -07:00

148 lines
8.2 KiB
JavaScript

// 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");
}
// Narrow panes show only the icons. The names stay for assistive technology and tooltips.
await page.setViewportSize({ width: 700, height: 600 });
await page.waitForFunction(() => getComputedStyle(document.querySelector(".view-modes .label")).display === "none");
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.");
});