Files
RuneStone/tests/smoke/layout/mixedSplits.smoke.mjs
T
Knotty Wyvern 61976191d0 Show different tabs side by side in split view
Each tab menu has "Open to the right". It shows the tab in a new pane to
the right of the active pane. A pane shows a document or a plugin tab,
for example a browser tab.

- A plugin view stays in the plugin layer above the panes, so a move
  between panes does not mount it again.
- A browser tab that covers the area moves to the left pane when a tab
  opens beside it. The last pane gives its plugin tab the whole area.
- The "Split" toggle of a document is now "Read beside".

Card 565874b2.
2026-11-10 06:40:44 -07:00

107 lines
7.0 KiB
JavaScript

// Split view with different tabs: two documents side by side, a browser tab beside a document, a browser tab that covers
// the area and then moves into a pane, the close control of a plugin pane, and the Read beside toggle, in both themes.
import assert from "node:assert/strict";
import path from "node:path";
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("layout/mixedSplits", async ({ page }) => {
const output = await outputDir("layout/mixedSplits");
await page.addInitScript(() => localStorage.setItem("runestone.settings", JSON.stringify({ autosaveEnabled: false })));
await mockTauri(page, {
commands: test => {
const workspace = test.workspace({
root: "C:\\mixed-split-workspace",
files: { "a.md": "# Alpha\n\nAlpha text.\n", "b.md": "# Bravo\n\nBravo 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, args }) => {
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 }; }
if (command === "closeTab") snapshot.tabs = snapshot.tabs.filter(tab => tab.id !== args.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) });
async function openToRight(name) {
await tab(name).click({ button: "right" });
await page.getByRole("menuitem", { name: "Open to the right", exact: true }).click();
}
async function box(locator) { const value = await locator.boundingBox(); assert.ok(value, "The pane is visible"); return value; }
async function newBrowserTab() {
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"]').last().waitFor();
}
await page.goto(smokeUrl);
await page.locator('[data-tree-rel="a.md"]').click(); await pane("a.md").locator(".cm-content").waitFor();
// A click in the file tree replaces the current tab, so the second file opens from a new tab.
await page.getByRole("button", { name: "New tab (Ctrl+T)", exact: true }).click();
await page.locator('[data-tree-rel="b.md"]').click(); await pane("b.md").locator(".cm-content").waitFor();
assert.equal(await page.getByRole("tab").count(), 2);
await page.waitForFunction(async () => { const { pluginHost } = await import("/src/lib/plugins/registry.ts"); return !!pluginHost.get("browser"); });
// Two different documents side by side.
await openToRight("a.md");
await pane("a.md").locator(".cm-content").waitFor();
assert.equal(await page.locator(".document-pane").count(), 2);
const left = await box(pane("b.md")), right = await box(pane("a.md"));
assert.ok(right.x >= left.x + left.width - 1 && Math.abs(left.y - right.y) < 2, "The documents show side by side");
assert.equal(await pane("a.md").locator(".breadcrumb").innerText(), "a.md", "A pane beside another pane names its file");
await tab("a.md").click({ button: "right" });
assert.equal(await page.getByRole("menuitem", { name: "Open to the right", exact: true }).isDisabled(), true, "A visible tab cannot open again");
await page.keyboard.press("Escape");
// A new browser tab opens in the focused pane. The document that it replaces stays open as a tab.
await newBrowserTab();
assert.equal(await pane("a.md").count(), 0);
assert.equal(await tab("a.md").count(), 1);
const documentBox = await box(pane("b.md")), webBox = await box(browserPane);
assert.ok(webBox.x >= documentBox.x + documentBox.width - 1, "The browser shows beside the document");
assert.ok(Math.abs(webBox.width - documentBox.width) < 4, "The panes share the area");
for (const theme of ["light", "dark"]) {
await page.evaluate(async mode => { const { saveAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ theme: "default", mode }); }, theme);
await page.screenshot({ path: path.join(output, `document-and-browser-${theme}.png`) });
}
// A click in the document pane makes its tab active. The browser stays visible.
await pane("b.md").locator(".cm-content").click();
await page.waitForFunction(() => document.querySelector('[role="tab"][aria-selected="true"]')?.textContent?.includes("b.md"));
assert.equal(await browserPane.count(), 1);
// The document opens beside the browser, and the close control of the browser pane leaves the tab open.
await openToRight("a.md");
await pane("a.md").locator(".cm-content").waitFor();
assert.equal(await page.locator(".document-pane").count(), 3);
await browserPane.getByRole("button", { name: "Close split", exact: true }).click();
assert.equal(await page.locator(".document-pane").count(), 2);
assert.equal(await page.getByRole("tab", { name: /Browser/ }).count(), 1);
await pane("a.md").getByRole("button", { name: "Close split", exact: true }).click();
assert.equal(await page.locator(".document-pane").count(), 1);
// A browser tab that covers the whole area moves into the left pane when a document opens to the right.
await page.getByRole("tab", { name: /Browser/ }).click();
await browserPane.waitFor();
assert.ok((await box(browserPane)).width > (await box(page.locator(".center"))).width - 4, "The browser covers the area");
await openToRight("a.md");
await pane("a.md").locator(".cm-content").waitFor();
const coverLeft = await box(browserPane), coverRight = await box(pane("a.md"));
assert.ok(coverRight.x >= coverLeft.x + coverLeft.width - 1, "The browser keeps the left pane");
await pane("a.md").getByRole("button", { name: "Close split", exact: true }).click();
await browserPane.waitFor();
assert.ok((await box(browserPane)).width > (await box(page.locator(".center"))).width - 4, "The last pane gives the browser the whole area");
// Read beside is the toggle for the Read view beside the editor.
await tab("b.md").click();
await pane("b.md").locator(".cm-content").waitFor();
await pane("b.md").getByRole("button", { name: "Read beside", exact: true }).click();
await pane("b.md").locator(".md-page").waitFor();
console.log(JSON.stringify({ passed: ["two documents side by side", "browser beside a document", "replaced document stays a tab", "focus by click", "plugin pane close control", "covering browser moves into a pane", "last pane releases the browser", "Read beside toggle", "light/dark screenshots"], nativeDesktop: "not tested" }, null, 2));
}, { timeout: 30000 });