Improve workspace navigation, search, and tab actions
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
import { createRequire } from "node:module";
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdir } from "node:fs/promises";
|
||||
const require = createRequire(import.meta.url);
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
|
||||
page.setDefaultTimeout(15000);
|
||||
const errors = [];
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
await mkdir(".audit", { recursive: true });
|
||||
await page.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
const root = "C:\\tab-menu-workspace";
|
||||
const files = new Map(["a.md", "b.md", "c.md", "d.md"].map(name => [name, `# ${name}\n\nOriginal text.\n`]));
|
||||
window.tabMenuTest = { prompts: [], answer: "Cancel", revealed: null, clipboard: null };
|
||||
Object.defineProperty(navigator, "clipboard", { value: { writeText: async text => { window.tabMenuTest.clipboard = text; } } });
|
||||
let sequence = 0;
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
|
||||
transformCallback: () => ++sequence, unregisterCallback: () => {},
|
||||
invoke: async (command, args = {}) => {
|
||||
if (command === "plugin:event|listen") return ++sequence;
|
||||
if (command === "plugin:event|unlisten") return;
|
||||
if (command === "workspace_last_path") return root;
|
||||
if (command === "workspace_open") return { root, name: "tab-menu-workspace", watch_mode: "native" };
|
||||
if (command === "workspace_read") { if (!files.has(args.rel)) throw new Error("missing"); return files.get(args.rel); }
|
||||
if (command === "workspace_list") return args.rel ? [] : [...files.keys()].map(name => ({ name, rel_path: name, kind: "file" }));
|
||||
if (command === "workspace_search") return [];
|
||||
if (command === "workspace_write") throw new Error("Keep unsaved edits for the close test");
|
||||
if (command === "workspace_rename") { files.set(args.to, files.get(args.from)); files.delete(args.from); return; }
|
||||
if (command === "workspace_abs_path") return `${root}\\${args.rel}`;
|
||||
if (command === "workspace_reveal") { window.tabMenuTest.revealed = args.rel; return; }
|
||||
if (command === "plugin:dialog|message") { window.tabMenuTest.prompts.push(args.message); return window.tabMenuTest.answer; }
|
||||
throw new Error(`Unhandled IPC: ${command}`);
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
|
||||
});
|
||||
const tab = name => page.getByRole("tab", { name, exact: true });
|
||||
const menu = () => page.getByRole("menu", { name: "Tab actions", exact: true });
|
||||
const item = name => page.getByRole("menuitem", { name, exact: true });
|
||||
const order = () => page.getByRole("tab").evaluateAll(nodes => nodes.map(node => node.dataset.path));
|
||||
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 tab(name).waitFor();
|
||||
}
|
||||
async function show(name) { await tab(name).click({ button: "right" }); await menu().waitFor(); }
|
||||
try {
|
||||
await page.goto(process.env.SMOKE_URL || "http://127.0.0.1:1420");
|
||||
await page.getByText("tab-menu-workspace", { exact: true }).waitFor();
|
||||
for (const name of ["a.md", "b.md", "c.md", "d.md"]) await open(name);
|
||||
await page.locator(".cm-content").filter({ hasText: "Original text." }).waitFor();
|
||||
await show("b.md");
|
||||
assert.equal(await tab("d.md").getAttribute("aria-selected"), "true");
|
||||
assert.equal(await item("Rename…").count(), 0);
|
||||
assert.equal(await item("Reading view").count(), 0);
|
||||
assert.doesNotMatch(await menu().innerText(), /Alt|Shift|Ctrl/);
|
||||
await page.screenshot({ path: ".audit/tab-menu-inactive.png" });
|
||||
await item("Pin").click();
|
||||
assert.equal(await tab("d.md").getAttribute("aria-selected"), "true");
|
||||
assert.ok(await tab("b.md").getAttribute("aria-describedby"));
|
||||
await show("d.md");
|
||||
assert.equal(await item("Close tabs after").isDisabled(), true);
|
||||
await page.screenshot({ path: ".audit/tab-menu-active.png" });
|
||||
await page.keyboard.press("Escape");
|
||||
assert.equal(await tab("d.md").evaluate(node => node === document.activeElement), true);
|
||||
await tab("d.md").press("Shift+F10");
|
||||
assert.equal(await item("Close").evaluate(node => node === document.activeElement), true);
|
||||
await page.keyboard.press("End");
|
||||
await page.keyboard.press("ArrowRight");
|
||||
assert.equal(await item("Move tab left").evaluate(node => node === document.activeElement), true);
|
||||
await page.keyboard.press("ArrowLeft");
|
||||
await page.keyboard.press("Escape");
|
||||
await show("d.md");
|
||||
await item("Reading view").click();
|
||||
await page.locator(".md-page").waitFor();
|
||||
await show("d.md");
|
||||
await item("Editing view").click();
|
||||
await page.locator(".cm-editor").waitFor();
|
||||
await show("d.md");
|
||||
await item("Source mode").click();
|
||||
await page.locator(".monaco-editor").waitFor();
|
||||
await show("d.md");
|
||||
await item("Writing mode").click();
|
||||
await page.locator(".cm-editor").waitFor();
|
||||
await show("d.md");
|
||||
await item("Copy path").click();
|
||||
await item("Workspace path").click();
|
||||
assert.equal(await page.evaluate(() => window.tabMenuTest.clipboard), "d.md");
|
||||
await show("d.md");
|
||||
await item("Show in system explorer").click();
|
||||
assert.equal(await page.evaluate(() => window.tabMenuTest.revealed), "d.md");
|
||||
await show("d.md");
|
||||
await item("Rename…").click();
|
||||
await page.getByRole("dialog").getByRole("textbox").fill("renamed.md");
|
||||
await page.getByRole("dialog").getByRole("button", { name: "Continue", exact: true }).click();
|
||||
await tab("renamed.md").waitFor();
|
||||
await show("a.md");
|
||||
await item("Close tabs after").click();
|
||||
await tab("renamed.md").waitFor({ state: "detached" });
|
||||
assert.deepEqual(await order(), ["a.md", "b.md"]);
|
||||
await open("c.md");
|
||||
await show("c.md");
|
||||
await item("Close others").click();
|
||||
await tab("a.md").waitFor({ state: "detached" });
|
||||
assert.deepEqual(await order(), ["b.md", "c.md"]);
|
||||
await page.locator(".cm-content").click();
|
||||
await page.keyboard.press("Control+End");
|
||||
await page.keyboard.type("Unsaved text");
|
||||
await tab("c.md •").waitFor();
|
||||
await show("c.md •");
|
||||
await item("Close all").click();
|
||||
await page.waitForFunction(() => window.tabMenuTest.prompts.length === 1);
|
||||
assert.deepEqual(await order(), ["b.md", "c.md"]);
|
||||
await page.evaluate(() => { window.tabMenuTest.answer = "Ok"; });
|
||||
await show("c.md •");
|
||||
await item("Close all").click();
|
||||
await tab("c.md •").waitFor({ state: "detached" });
|
||||
assert.deepEqual(await order(), ["b.md"]);
|
||||
await show("b.md");
|
||||
assert.equal(await item("Close all").isDisabled(), true);
|
||||
await item("Unpin").click();
|
||||
await show("b.md");
|
||||
await item("Close").click();
|
||||
await tab("b.md").waitFor({ state: "detached" });
|
||||
await page.getByRole("button", { name: "New tab (Ctrl T)", exact: true }).click();
|
||||
await show("New tab");
|
||||
assert.equal(await item("Rename…").count(), 0);
|
||||
assert.equal(await item("Reading view").count(), 0);
|
||||
await page.keyboard.press("Escape");
|
||||
assert.deepEqual(errors, []);
|
||||
console.log("PASS: active/inactive menus, keyboard focus, pinning, view modes, file actions, ordered closes, cancelled discard, and empty tabs");
|
||||
} catch (error) {
|
||||
await page.screenshot({ path: ".audit/tab-menu-failure.png" });
|
||||
throw error;
|
||||
} finally { await browser.close(); }
|
||||
Reference in New Issue
Block a user