172 lines
11 KiB
JavaScript
172 lines
11 KiB
JavaScript
// A drag of the tab that a pane shows, with real mouse input: the tab moves to a new pane on the right or bottom side of
|
|
// its pane, and the pane shows the next tab. A browser tab that covers the area moves beside the document below it.
|
|
// With only one tab, the drag shows no hint.
|
|
import assert from "node:assert/strict";
|
|
import path from "node:path";
|
|
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
|
|
|
await runSmoke("layout/visibleTabDrag", async ({ page }) => {
|
|
const output = await outputDir("layout/visibleTabDrag");
|
|
await page.addInitScript(() => localStorage.setItem("runestone.settings", JSON.stringify({ autosaveEnabled: false })));
|
|
await mockTauri(page, {
|
|
commands: test => {
|
|
const workspace = test.workspace({
|
|
root: "C:\\visible-tab-drag-workspace",
|
|
files: { "a.md": "# Alpha\n\nAlpha text.\n", "b.md": "# Bravo\n\nBravo text.\n", "c.md": "# Charlie\n\nCharlie text.\n" },
|
|
});
|
|
const snapshot = { profiles: [{ id: "user", name: "User" }], tabs: [], bookmarks: [], settings: { search: "duckduckgo", adblock: true, linkDestination: "internal", personalRules: "", homepage: "", filterLists: [] } };
|
|
let next = 0;
|
|
return {
|
|
...workspace,
|
|
browser_connect: () => "window-session",
|
|
browser_request: ({ command }) => {
|
|
if (command === "newTab") { const tabId = "native-" + (++next); snapshot.tabs.push({ id: tabId, profileId: "user", url: "about:blank", title: "Browser", loading: false, blocked: 0, canBack: false, canForward: false }); return { tabId }; }
|
|
return structuredClone(snapshot);
|
|
},
|
|
};
|
|
},
|
|
});
|
|
|
|
const pane = rel => page.locator(`[data-document-path="${rel}"]`);
|
|
const browserPane = page.locator(".plugin-pane:not(.inactive)").filter({ has: page.locator('[data-browser-state="ready"]') });
|
|
const tab = name => page.getByRole("tab", { name: new RegExp(name) });
|
|
const hint = page.locator(".drop-hint");
|
|
async function box(locator) { const value = await locator.boundingBox(); assert.ok(value, "The element is visible"); return value; }
|
|
const shown = () => page.locator("[data-document-path]").evaluateAll(nodes => nodes.map(node => node.getAttribute("data-document-path")));
|
|
const activeTab = () => page.locator('[role="tab"][aria-selected="true"]').innerText();
|
|
/** Press the mouse button on a tab and move the pointer to a part of a target. The button stays down. */
|
|
async function dragTo(name, target, where) {
|
|
const from = await box(tab(name)), to = await box(target);
|
|
const point = where === "right" ? { x: to.x + to.width - 30, y: to.y + to.height / 2 }
|
|
: where === "left" ? { x: to.x + 30, y: to.y + to.height / 2 }
|
|
: where === "down" ? { x: to.x + to.width / 2, y: to.y + to.height - 30 }
|
|
: { x: to.x + to.width / 2, y: to.y + to.height / 2 };
|
|
await page.mouse.move(from.x + from.width / 2, from.y + from.height / 2);
|
|
await page.mouse.down();
|
|
await page.mouse.move(from.x + from.width / 2 + 8, from.y + from.height / 2 + 8, { steps: 3 });
|
|
await page.mouse.move(point.x, point.y, { steps: 10 });
|
|
// The browser fires dragover on the next move. A target that a step only enters gets no dragover.
|
|
await page.mouse.move(point.x + 2, point.y + 2, { steps: 2 });
|
|
}
|
|
async function open(name) {
|
|
await page.locator(`[data-tree-rel="${name}"]`).click();
|
|
await pane(name).locator(".cm-content").waitFor();
|
|
}
|
|
|
|
await page.goto(smokeUrl);
|
|
await open("a.md");
|
|
assert.equal(await page.getByRole("tab").count(), 1);
|
|
|
|
// The only tab has no other tab to leave in its pane. The drag shows no hint and changes nothing.
|
|
await dragTo("a.md", pane("a.md"), "right");
|
|
await page.waitForTimeout(200);
|
|
assert.equal(await hint.count(), 0, "The only tab cannot open a pane");
|
|
await page.mouse.up();
|
|
assert.deepEqual(await shown(), ["a.md"]);
|
|
|
|
// A click in the file tree replaces the current tab, so each more file opens from a new tab.
|
|
for (const name of ["b.md", "c.md"]) {
|
|
await page.getByRole("button", { name: "New tab (Ctrl+T)", exact: true }).click();
|
|
await open(name);
|
|
}
|
|
assert.deepEqual(await shown(), ["c.md"]);
|
|
|
|
// The middle of the pane already shows the tab, so it is no drop target. The right part opens a new pane.
|
|
await dragTo("c.md", pane("c.md"), "center");
|
|
await page.waitForTimeout(200);
|
|
assert.equal(await hint.count(), 0, "The middle of the pane does not take its own tab");
|
|
const area = await box(page.locator("main.center"));
|
|
await page.mouse.move(area.x + area.width - 30, area.y + area.height / 2, { steps: 5 });
|
|
await page.locator('.drop-hint[data-drop-zone="right"]').waitFor();
|
|
await page.screenshot({ path: path.join(output, "visible-tab-hint.png") });
|
|
await page.mouse.up();
|
|
await pane("b.md").locator(".cm-content").waitFor();
|
|
assert.equal(await hint.count(), 0);
|
|
// c.md is the last tab, so its pane shows the tab before it.
|
|
assert.deepEqual(await shown(), ["b.md", "c.md"], "The tab moves to the right, and its pane shows the tab before it");
|
|
assert.match(await activeTab(), /c\.md/, "The moved tab stays the active tab");
|
|
const left = await box(pane("b.md")), right = await box(pane("c.md"));
|
|
assert.ok(right.x >= left.x + left.width - 1 && Math.abs(left.y - right.y) < 2, "The panes show side by side");
|
|
assert.equal(await page.getByRole("tab").count(), 3, "All tabs stay open");
|
|
|
|
// The tab of the left pane moves below it. The pane shows the only tab that no pane shows.
|
|
await dragTo("b.md", pane("b.md"), "down");
|
|
await page.locator('.drop-hint[data-drop-zone="down"]').waitFor();
|
|
await page.mouse.up();
|
|
await pane("a.md").locator(".cm-content").waitFor();
|
|
assert.equal(await page.locator(".document-pane").count(), 3);
|
|
const top = await box(pane("a.md")), bottom = await box(pane("b.md"));
|
|
assert.ok(bottom.y >= top.y + top.height - 1 && Math.abs(top.x - bottom.x) < 2, "The moved tab shows below its old pane");
|
|
assert.match(await activeTab(), /b\.md/);
|
|
|
|
// Each tab now shows in a pane, so a pane has no other tab to show. The drag shows no hint.
|
|
await dragTo("a.md", pane("a.md"), "right");
|
|
await page.waitForTimeout(200);
|
|
assert.equal(await hint.count(), 0, "No tab is free for the pane");
|
|
await page.mouse.up();
|
|
assert.equal(await page.locator(".document-pane").count(), 3);
|
|
|
|
// A browser tab that covers the area moves to a new pane on the right. The document below it shows on the left.
|
|
for (let panes = 3; panes > 1; panes--) await page.getByRole("button", { name: "Close split", exact: true }).first().click();
|
|
assert.equal(await page.locator(".document-pane").count(), 1);
|
|
const below = (await shown())[0];
|
|
await page.waitForFunction(async () => { const { pluginHost } = await import("/src/lib/plugins/registry.ts"); return !!pluginHost.get("browser"); });
|
|
await page.evaluate(async () => { const { pluginHost } = await import("/src/lib/plugins/registry.ts"); await pluginHost.get("browser").newTab(); });
|
|
await page.locator('[data-browser-state="ready"]').waitFor();
|
|
assert.ok((await box(browserPane)).width > area.width - 4, "The browser covers the area");
|
|
await dragTo("Browser", page.locator("main.center"), "right");
|
|
await page.locator('.drop-hint[data-drop-zone="right"]').waitFor();
|
|
await page.mouse.up();
|
|
await pane(below).locator(".cm-content").waitFor();
|
|
const documentBox = await box(pane(below)), webBox = await box(browserPane);
|
|
assert.ok(webBox.x >= documentBox.x + documentBox.width - 1, "The browser shows to the right of the document");
|
|
assert.match(await activeTab(), /Browser/);
|
|
|
|
// A tab that no pane shows opens in a new pane on the left side of the browser pane (card 156758f1).
|
|
const free = ["a.md", "b.md", "c.md"].find(name => name !== below);
|
|
await dragTo(free, browserPane, "left");
|
|
await page.locator('.drop-hint[data-drop-zone="left"]').waitFor();
|
|
const leftHint = await box(hint), browserBefore = await box(browserPane);
|
|
assert.ok(Math.abs(leftHint.x - browserBefore.x) < 2 && leftHint.width < browserBefore.width * 0.6, "The hint covers the left half of the pane");
|
|
assert.equal((await hint.innerText()).trim(), "Open to the left");
|
|
await page.screenshot({ path: path.join(output, "left-drop-hint.png") });
|
|
await page.mouse.up();
|
|
await pane(free).locator(".cm-content").waitFor();
|
|
const first = await box(pane(below)), middle = await box(pane(free)), last = await box(browserPane);
|
|
assert.ok(first.x + first.width <= middle.x + 1 && middle.x + middle.width <= last.x + 1, "The new pane shows between the document and the browser");
|
|
assert.match(await activeTab(), new RegExp(free.replace(".", "\\.")));
|
|
|
|
// The tab menu closes the split of a tab. The tab stays open, and the other panes stay.
|
|
const tabCount = await page.getByRole("tab").count();
|
|
const closeButtons = page.getByRole("button", { name: "Close split", exact: true });
|
|
assert.equal(await closeButtons.count(), 3, "Each pane bar has a Close split button");
|
|
assert.equal((await closeButtons.first().innerText()).trim(), "Close split", "The button shows its name");
|
|
await closeButtons.first().screenshot({ path: path.join(output, "close-split-button.png") });
|
|
// Screenshots of the pane bars in both themes and in a narrow window.
|
|
const viewport = page.viewportSize();
|
|
for (const mode of ["light", "dark"]) {
|
|
await page.evaluate(async mode => { const { saveAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ theme: "default", mode }); }, mode);
|
|
await page.waitForTimeout(150);
|
|
await page.screenshot({ path: path.join(output, `close-split-${mode}.png`) });
|
|
}
|
|
await page.setViewportSize({ width: 760, height: viewport.height });
|
|
await page.waitForTimeout(200);
|
|
await page.screenshot({ path: path.join(output, "close-split-narrow.png") });
|
|
// A narrow pane shows only the icon of the button. The tooltip gives its name.
|
|
await closeButtons.last().hover();
|
|
await page.locator(".rs-tooltip:popover-open").filter({ hasText: "Close split" }).waitFor();
|
|
await page.mouse.move(0, 0);
|
|
await page.setViewportSize(viewport);
|
|
await tab(free).click({ button: "right" });
|
|
await page.getByRole("menuitem", { name: "Close split", exact: true }).click();
|
|
await page.waitForFunction(count => document.querySelectorAll(".document-pane").length + document.querySelectorAll(".plugin-pane:not(.inactive)").length <= count, 3);
|
|
assert.deepEqual((await shown()).filter(Boolean), [below], "The pane of the tab closes. The browser pane stays.");
|
|
assert.equal(await page.getByRole("tab").count(), tabCount, "The tab stays open");
|
|
// A tab that no pane shows has no Close split item.
|
|
await tab(free).click({ button: "right" });
|
|
assert.equal(await page.getByRole("menuitem", { name: "Close split", exact: true }).count(), 0);
|
|
await page.keyboard.press("Escape");
|
|
|
|
console.log(JSON.stringify({ passed: ["one tab shows no hint", "own pane middle is no target", "visible tab moves right", "visible tab moves below", "no free tab shows no hint", "covering browser tab moves right", "free tab opens left of a pane", "tab menu closes a split and keeps the tab"], nativeDesktop: "not tested" }, null, 2));
|
|
});
|