106 lines
6.0 KiB
JavaScript
106 lines
6.0 KiB
JavaScript
// Tab order: pointer drags, cancellation, keyboard moves, tab menus, empty tabs, and an overflowing tab bar.
|
|
import assert from "node:assert/strict";
|
|
import { mockTauri, runSmoke, settle as settleFrames, smokeUrl } from "../_harness/index.mjs";
|
|
|
|
await runSmoke("tabs/order", async ({ page }) => {
|
|
await mockTauri(page, {
|
|
commands: test => {
|
|
const files = new Map(Array.from({ length: 16 }, (_, i) => [`note-${String(i).padStart(2, "0")}.md`, `# Note ${i}\n\nKeep this text.\n`]));
|
|
files.set("note-00.md", Array.from({ length: 200 }, (_, i) => `Paragraph ${i}.\n\n`).join(""));
|
|
return {
|
|
...test.workspace({ root: "C:\\tab-order-workspace", files }),
|
|
workspace_search: () => [],
|
|
"plugin:dialog|message": () => "Cancel",
|
|
};
|
|
},
|
|
});
|
|
const settle = () => settleFrames(page);
|
|
const tab = name => page.getByRole("tab", { name, exact: true });
|
|
const order = () => page.getByRole("tablist", { name: "Working tabs" }).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 drag(from, to, side, cancel) {
|
|
const source = await tab(from).boundingBox();
|
|
const target = await tab(to).boundingBox();
|
|
await page.mouse.move(source.x + source.width / 2, source.y + source.height / 2);
|
|
await page.mouse.down();
|
|
await page.mouse.move(side === "before" ? target.x + 2 : target.x + target.width - 2, target.y + target.height / 2, { steps: 10 });
|
|
if (cancel === "escape") await page.keyboard.press("Escape");
|
|
if (cancel === "outside") await page.mouse.move(target.x, target.y + 100);
|
|
await page.mouse.up();
|
|
await settle();
|
|
}
|
|
await page.goto(smokeUrl);
|
|
await page.getByText("tab-order-workspace", { exact: true }).waitFor();
|
|
for (const name of ["note-00.md", "note-01.md", "note-02.md"]) await open(name);
|
|
await drag("note-00.md", "note-02.md", "after");
|
|
assert.deepEqual(await order(), ["note-01.md", "note-02.md", "note-00.md"]);
|
|
assert.equal(await tab("note-02.md").getAttribute("aria-selected"), "true");
|
|
await drag("note-00.md", "note-01.md", "before");
|
|
assert.deepEqual(await order(), ["note-00.md", "note-01.md", "note-02.md"]);
|
|
for (const cancel of ["escape", "outside"]) {
|
|
await drag("note-00.md", "note-02.md", "after", cancel);
|
|
assert.deepEqual(await order(), ["note-00.md", "note-01.md", "note-02.md"]);
|
|
}
|
|
await tab("note-00.md").click();
|
|
assert.equal(await tab("note-00.md").getAttribute("aria-selected"), "true");
|
|
await page.locator(".cm-scroller").evaluate(node => { node.scrollTop = 1200; });
|
|
await settle();
|
|
const scrollTop = await page.locator(".cm-scroller").evaluate(node => node.scrollTop);
|
|
assert.ok(scrollTop > 1000);
|
|
await tab("note-00.md").press("Alt+Shift+ArrowRight");
|
|
await settle();
|
|
assert.deepEqual(await order(), ["note-01.md", "note-00.md", "note-02.md"]);
|
|
assert.ok(Math.abs(await page.locator(".cm-scroller").evaluate(node => node.scrollTop) - scrollTop) < 5);
|
|
assert.equal(await tab("note-00.md").evaluate(node => document.activeElement === node), true);
|
|
await tab("note-00.md").press("ArrowRight");
|
|
assert.equal(await tab("note-02.md").getAttribute("aria-selected"), "true");
|
|
await tab("note-02.md").press("Shift+F10");
|
|
await page.getByRole("menuitem", { name: "Move tab", exact: true }).click();
|
|
assert.equal(await page.getByRole("menuitem", { name: /Move tab right/ }).isDisabled(), true);
|
|
await page.getByRole("menuitem", { name: /Move tab left/ }).click();
|
|
assert.deepEqual(await order(), ["note-01.md", "note-02.md", "note-00.md"]);
|
|
await tab("note-01.md").click({ button: "right" });
|
|
await page.getByRole("menuitem", { name: "Move tab", exact: true }).click();
|
|
assert.equal(await page.getByRole("menuitem", { name: /Move tab left/ }).isDisabled(), true);
|
|
await page.keyboard.press("Escape");
|
|
assert.equal(await page.getByRole("menu", { name: "Tab actions" }).count(), 0);
|
|
console.log("PASS: pointer moves, cancellation, keyboard moves, and tab menus");
|
|
|
|
await page.getByRole("button", { name: "New tab (Ctrl+T)", exact: true }).click();
|
|
await tab("New tab").press("Alt+Shift+Home");
|
|
assert.match((await order())[0], /^empty:/);
|
|
await page.getByRole("button", { name: "Close New tab", exact: true }).click();
|
|
await tab("note-01.md").click({ button: "middle" });
|
|
assert.deepEqual(await order(), ["note-02.md", "note-00.md"]);
|
|
console.log("PASS: empty tabs and middle-click close after reorder");
|
|
|
|
for (let i = 3; i < 16; i++) await open(`note-${String(i).padStart(2, "0")}.md`);
|
|
const bar = page.getByRole("tablist", { name: "Working tabs" });
|
|
assert.ok(await bar.evaluate(node => node.scrollLeft > 0));
|
|
await tab("note-15.md").press("Alt+Shift+Home");
|
|
assert.equal((await order())[0], "note-15.md");
|
|
assert.equal(await bar.evaluate(node => node.scrollLeft), 0);
|
|
const source = await tab("note-15.md").boundingBox();
|
|
const bounds = await bar.boundingBox();
|
|
await page.mouse.move(source.x + source.width / 2, source.y + source.height / 2);
|
|
await page.mouse.down();
|
|
await page.mouse.move(bounds.x + bounds.width - 3, source.y + source.height / 2, { steps: 10 });
|
|
await page.waitForFunction(() => {
|
|
const bar = document.querySelector('[aria-label="Working tabs"]');
|
|
return bar.scrollLeft >= bar.scrollWidth - bar.clientWidth - 2;
|
|
});
|
|
// Native drag needs a fresh pointer event after the strip scrolls beneath it.
|
|
await page.mouse.move(bounds.x + bounds.width - 4, source.y + source.height / 2);
|
|
await page.mouse.move(bounds.x + bounds.width - 3, source.y + source.height / 2);
|
|
await page.mouse.up();
|
|
await settle();
|
|
assert.equal((await order()).at(-1), "note-15.md");
|
|
console.log("PASS: automatic scrolling and drag to the end of an overflowing tab bar");
|
|
if (process.env.SCREENSHOT_PATH) await page.screenshot({ path: process.env.SCREENSHOT_PATH });
|
|
});
|