// 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. // Also the divider that resizes two panes, a tab that the user drags into a pane, and the new browser tab beside a browser tab. 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") { globalThis.newTabUrls = [...(globalThis.newTabUrls || []), args.url ?? null]; 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; } // A native tab drag: dragstart on the tab button, dragover at a place of the target, then the drop and dragend. async function dragOver(source, target, where) { const point = await target.evaluate((node, where) => { const r = node.getBoundingClientRect(); return where === "down" ? { x: r.left + r.width / 2, y: r.bottom - 12 } : where === "right" ? { x: r.right - 12, y: r.top + r.height / 2 } : { x: r.left + r.width / 2, y: r.top + r.height / 2 }; }, where); return source.evaluate((node, point) => { const transfer = new DataTransfer(); node.dispatchEvent(new DragEvent("dragstart", { bubbles: true, cancelable: true, dataTransfer: transfer })); const over = new DragEvent("dragover", { bubbles: true, cancelable: true, clientX: point.x, clientY: point.y, dataTransfer: transfer }); document.elementFromPoint(point.x, point.y).dispatchEvent(over); globalThis.tabDrag = { node, transfer, point }; return over.defaultPrevented; }, point); } async function drop() { return page.evaluate(() => { const { node, transfer, point } = globalThis.tabDrag; const event = new DragEvent("drop", { bubbles: true, cancelable: true, clientX: point.x, clientY: point.y, dataTransfer: transfer }); document.elementFromPoint(point.x, point.y).dispatchEvent(event); node.dispatchEvent(new DragEvent("dragend", { bubbles: true, clientX: point.x, clientY: point.y, dataTransfer: transfer })); return event.defaultPrevented; }); } async function setMode(mode) { await page.evaluate(async mode => { const { saveAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ theme: "default", mode }); }, mode); } 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(); await pane("b.md").getByRole("button", { name: "Read beside", exact: true }).click(); // The divider between two panes changes their sizes, with the pointer and with the keyboard. await openToRight("a.md"); await pane("a.md").locator(".cm-content").waitFor(); const divider = page.getByRole("separator", { name: "Resize panes" }); assert.equal(await divider.count(), 1); const area = await box(page.locator(".center")); const handle = await box(divider); await page.mouse.move(handle.x + handle.width / 2, handle.y + handle.height / 2); await page.mouse.down(); await page.mouse.move(handle.x + handle.width / 2 - area.width * 0.2, handle.y + handle.height / 2, { steps: 4 }); await page.mouse.up(); const narrow = await box(pane("b.md")), wide = await box(pane("a.md")); assert.ok(Math.abs(narrow.width - area.width * 0.3) < 4, `The left pane has 30% of the area: ${narrow.width} of ${area.width}`); assert.ok(Math.abs(wide.x - (narrow.x + narrow.width)) < 2, "The right pane starts at the divider"); assert.equal(await divider.getAttribute("aria-valuenow"), "30"); await divider.focus(); await page.keyboard.press("ArrowRight"); assert.equal(await divider.getAttribute("aria-valuenow"), "35"); for (const mode of ["light", "dark"]) { await setMode(mode); await divider.hover(); await page.screenshot({ path: path.join(output, `divider-${mode}.png`) }); } await divider.dblclick(); assert.equal(await divider.getAttribute("aria-valuenow"), "50"); // A new browser tab replaces the document in the focused pane. A document tab dragged to the bottom of the browser pane // opens below it. await newBrowserTab(); assert.equal(await pane("a.md").count(), 0); assert.equal(await dragOver(tab("a.md"), browserPane, "down"), true, "The browser pane takes the tab"); await page.locator('.drop-hint[data-drop-zone="down"]').waitFor(); for (const mode of ["light", "dark"]) { await setMode(mode); await page.screenshot({ path: path.join(output, `tab-drop-${mode}.png`) }); } assert.equal(await drop(), true); await pane("a.md").locator(".cm-content").waitFor(); assert.equal(await page.locator(".drop-hint").count(), 0); const web = await box(browserPane), below = await box(pane("a.md")); assert.ok(below.y >= web.y + web.height - 1 && Math.abs(below.x - web.x) < 2, "The document shows below the browser"); assert.equal(await page.getByRole("separator", { name: "Resize panes" }).count(), 2); // The browser tab dragged to the document pane replaces it there, and leaves its old pane. The first browser tab is not visible. assert.equal(await dragOver(tab("Browser").last(), pane("b.md"), "center"), true); assert.equal(await drop(), true); await page.waitForFunction(() => document.querySelectorAll(".document-pane").length === 2); assert.equal(await pane("b.md").count(), 0); assert.equal(await tab("b.md").count(), 1, "The replaced document stays open as a tab"); const moved = await box(browserPane), rest = await box(pane("a.md")); assert.ok(rest.x >= moved.x + moved.width - 1, "The browser shows left of the document"); // A drop on the pane that shows the tab changes nothing. assert.equal(await dragOver(tab("Browser").last(), browserPane, "center"), false); await drop(); // "New tab to the right" of a browser tab that covers the area opens a new browser tab beside it, not a copy of the page. await pane("a.md").getByRole("button", { name: "Close split", exact: true }).click(); await browserPane.waitFor(); assert.ok((await box(browserPane)).width > area.width - 4, "The browser covers the area"); const before = await page.evaluate(() => globalThis.newTabUrls.length); await tab("Browser").last().click({ button: "right" }); await page.getByRole("menuitem", { name: "New tab to the right", exact: true }).click(); await page.waitForFunction(() => document.querySelectorAll(".plugin-pane.embedded:not(.inactive)").length === 2); assert.deepEqual(await page.evaluate(start => globalThis.newTabUrls.slice(start), before), [null], "The new tab opens the home page"); const [first, second] = await page.locator(".plugin-pane.embedded:not(.inactive)").evaluateAll(nodes => nodes.map(node => { const r = node.getBoundingClientRect(); return { x: r.x, width: r.width }; }).sort((a, b) => a.x - b.x)); assert.ok(second.x >= first.x + first.width - 1 && first.width > area.width * 0.4, "The browser tabs show side by side"); await page.screenshot({ path: path.join(output, "browser-beside-browser.png") }); 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", "divider by pointer, keyboard, and double-click", "tab drop below a pane", "tab drop replaces a pane", "new browser tab beside a browser tab", "light/dark screenshots"], nativeDesktop: "not tested" }, null, 2)); }, { timeout: 30000 });