// A PDF file beside a note: "Open to the right" in the file tree opens the PDF in a new pane beside the note. // The user writes in the note and turns the pages of the PDF, and both panes stay visible. A drag of the divider resizes // both panes. A PDF that covers the area moves into the left pane when a note opens to its right. Both themes. import assert from "node:assert/strict"; import path from "node:path"; import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs"; import { samplePdf } from "../../fixtures/pdf/fixtures.mjs"; await runSmoke("layout/pdfBesideNote", async ({ page }) => { const output = await outputDir("layout/pdfBesideNote"); await page.addInitScript(() => localStorage.setItem("runestone.settings", JSON.stringify({ autosaveEnabled: false }))); await mockTauri(page, { state: { sample: [...samplePdf()] }, commands: test => ({ ...test.workspace({ root: "C:\\pdf-beside-note", files: { "Sample.pdf": "", "note.md": "# Note\n\nReading notes.\n" } }), plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }), spelling_menu_install: () => null, workspace_read_bytes: () => new Uint8Array(test.state.sample).buffer, }), }); const row = name => page.locator(`[data-tree-rel="${name}"]`); const note = page.locator('[data-document-path="note.md"]'); const pdf = page.locator(".plugin-pane:not(.inactive)").filter({ has: page.locator(".pdf-viewer") }); const status = pdf.locator(".pdf-viewer .status"); async function box(locator) { const value = await locator.boundingBox(); assert.ok(value, "The pane is visible"); return value; } async function besideEachOther(left, right, message) { const a = await box(left), b = await box(right); assert.ok(b.x >= a.x + a.width - 1 && Math.abs(a.y - b.y) < 2, message); return [a, b]; } await page.goto(smokeUrl); await row("note.md").click(); await note.locator(".cm-content").waitFor(); // The file tree opens the PDF in a new pane to the right of the note. await row("Sample.pdf").click({ button: "right" }); await page.getByRole("menuitem", { name: "Open to the right", exact: true }).click(); await status.filter({ hasText: /^Page 1 of 2$/ }).waitFor(); assert.equal(await page.locator(".document-pane").count(), 2); await besideEachOther(note, pdf, "The PDF shows to the right of the note"); // Write in the note. The PDF stays visible. await note.locator(".cm-content").click(); await page.keyboard.press("Control+End"); await page.keyboard.type("Typed beside the PDF."); assert.match(await note.locator(".cm-content").innerText(), /Typed beside the PDF\./); assert.equal(await pdf.count(), 1); // Turn a page of the PDF. The note stays visible and keeps the text. await pdf.getByRole("button", { name: "Next page", exact: true }).click(); await status.filter({ hasText: /^Page 2 of 2$/ }).waitFor(); assert.match(await note.locator(".cm-content").innerText(), /Typed beside the PDF\./); // Back to the note: the keyboard goes to the note. await note.locator(".cm-content").click(); await page.keyboard.type(" More."); assert.match(await note.locator(".cm-content").innerText(), /Typed beside the PDF\. More\./); await page.waitForFunction(() => document.querySelector('[role="tab"][aria-selected="true"]')?.textContent?.includes("note.md")); // The divider gives the PDF more space. const divider = page.getByRole("separator", { name: "Resize panes" }); const handle = await box(divider), area = await box(page.locator(".center")); 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.15, handle.y + handle.height / 2, { steps: 4 }); await page.mouse.up(); const [left, right] = await besideEachOther(note, pdf, "The panes stay side by side after a resize"); assert.ok(right.width > left.width + area.width * 0.2, "The PDF pane is wider than the note pane"); 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.screenshot({ path: path.join(output, `pdf-beside-note-${mode}.png`) }); } // A PDF that covers the area moves into the left pane when a note opens to its right. await pdf.getByRole("button", { name: "Close split", exact: true }).click(); await page.getByRole("tab", { name: /Sample/ }).click(); await status.waitFor(); assert.ok((await box(pdf)).width > area.width - 4, "The PDF covers the area"); await row("note.md").click({ button: "right" }); await page.getByRole("menuitem", { name: "Open to the right", exact: true }).click(); await note.locator(".cm-content").waitFor(); await besideEachOther(pdf, note, "The PDF keeps the left pane"); console.log(JSON.stringify({ passed: ["file tree opens a PDF to the right", "typing in the note beside the PDF", "page turn in the PDF beside the note", "divider resize", "covering PDF moves into a pane", "light/dark screenshots"], nativeDesktop: "not tested" }, null, 2)); }, { timeout: 30000 });