Phase 5-7. - A changed tab asks Save, Don't save, or Cancel through the native dialog, instead of OK and Cancel to discard. - The conflict banner uses --rs-warn with a warning icon. Keep my edits is the primary choice and comes first. Use disk version comes last, in the error color. The banner wraps in a narrow pane. - The status bar shows the save state, the line and column, the word count, the line endings, and the view. It shows the watch mode only when it polls a network folder. - The outline and the document facts follow the active tab. A tab without a document has no outline and no document facts. - Tables: only formula cells have a hover hint, so no hint covers the next cell. The table adds no gap above its control area. The add controls show while a cell has focus. - The plugin review marks Install and enable as the primary action. The other choice is Install, keep disabled. - Read follows CommonMark soft breaks. Settings, General, Keep line breaks shows each source line break. The table preview and cell editors of Write keep their line breaks, because their editing depends on them. - Catalog rows in French, Japanese, and Simplified Chinese. - Docs: UI-053, the user guide, and plugins.md. Tests: the new layout/plainFixes, the keepLineBreaks cases in the settings unit tests, and the new install button name.
126 lines
7.5 KiB
JavaScript
126 lines
7.5 KiB
JavaScript
// 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.");
|
|
});
|