68 lines
3.7 KiB
JavaScript
68 lines
3.7 KiB
JavaScript
// File tree selection: Ctrl and Shift ranges across expanded folders, F2 on multiple rows, and Collapse all.
|
|
import assert from "node:assert/strict";
|
|
import path from "node:path";
|
|
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
|
|
|
await runSmoke("tree/selection", async ({ page }) => {
|
|
page.on("console", message => { if (message.type() === "error" || message.type() === "warning") console.log(message.type(), message.text()); });
|
|
await mockTauri(page, {
|
|
commands: test => test.workspace({
|
|
root: "C:\\smoke-workspace",
|
|
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",
|
|
},
|
|
writeEvents: true,
|
|
}),
|
|
});
|
|
const output = await outputDir("tree/selection");
|
|
const row = rel => page.locator(`[data-tree-rel="${rel}"]`);
|
|
const selected = () => page.locator('[role="treeitem"][aria-selected="true"]').evaluateAll(rows => rows.map(row => row.dataset.treeRel));
|
|
await page.goto(smokeUrl);
|
|
await row("notes").waitFor();
|
|
await row("notes").click();
|
|
await row("notes/second.md").waitFor();
|
|
assert.deepEqual(await selected(), ["notes"]);
|
|
await row("notes/second.md").click({ modifiers: ["Control"] });
|
|
await row("src").click({ modifiers: ["Control"] });
|
|
assert.deepEqual(await selected(), ["notes", "notes/second.md", "src"]);
|
|
assert.equal(await row("src").getAttribute("aria-expanded"), "false");
|
|
assert.equal(await page.getByRole("tab").count(), 1);
|
|
assert.equal(await page.getByRole("tab", { name: "New tab", exact: true }).count(), 1);
|
|
await row("notes").click({ modifiers: ["Control"] });
|
|
assert.deepEqual(await selected(), ["notes/second.md", "src"]);
|
|
assert.equal(await row("notes").getAttribute("aria-expanded"), "true");
|
|
await row("notes/second.md").click({ modifiers: ["Shift"] });
|
|
assert.deepEqual(await selected(), ["notes", "notes/second.md"]);
|
|
await row("src").click({ modifiers: ["Shift"] });
|
|
assert.deepEqual(await selected(), ["notes", "notes/second.md", "notes/welcome.md", "src"]);
|
|
await page.keyboard.press("F2");
|
|
assert.equal(await page.locator(".tree .rename").count(), 0);
|
|
await row("notes/welcome.md").click({ modifiers: ["Shift"] });
|
|
assert.deepEqual(await selected(), ["notes", "notes/second.md", "notes/welcome.md"]);
|
|
await row("notes/second.md").click();
|
|
assert.deepEqual(await selected(), ["notes/second.md"]);
|
|
await page.getByRole("tab", { name: /second/ }).waitFor();
|
|
await row("notes/second.md").click({ modifiers: ["Control"] });
|
|
assert.deepEqual(await selected(), []);
|
|
await row("src").click({ modifiers: ["Control"] });
|
|
await row("notes").click({ modifiers: ["Control"] });
|
|
await row("notes").click({ modifiers: ["Control"] });
|
|
await page.keyboard.press("F2");
|
|
assert.equal(await page.locator(".tree .rename").inputValue(), "src");
|
|
await page.keyboard.press("Escape");
|
|
await row("notes/second.md").click({ modifiers: ["Shift"] });
|
|
assert.deepEqual(await selected(), ["notes/second.md", "notes/welcome.md", "src"]);
|
|
const colors = await page.locator(".tree .row.selected").evaluateAll(rows => rows.map(row => getComputedStyle(row).backgroundColor));
|
|
assert.equal(new Set(colors).size, 1);
|
|
await page.screenshot({ path: path.join(output, "tree-selection.png") });
|
|
await page.getByRole("button", { name: "Collapse all", exact: true }).click();
|
|
assert.deepEqual(await selected(), ["src"]);
|
|
await row("notes").click({ modifiers: ["Shift"] });
|
|
assert.deepEqual(await selected(), ["notes", "src"]);
|
|
await row("notes").click({ modifiers: ["Control"] });
|
|
await row("notes").click({ modifiers: ["Shift", "Control"] });
|
|
assert.deepEqual(await selected(), ["notes", "src"]);
|
|
});
|