import { createRequire } from "node:module"; import assert from "node:assert/strict"; import { mkdir } from "node:fs/promises"; const require = createRequire(import.meta.url); const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright"); const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) }); const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } }); page.setDefaultTimeout(15000); const errors = []; page.on("pageerror", error => errors.push(error.message)); await mkdir(".audit", { recursive: true }); await page.addInitScript(() => { window.isTauri = true; const root = "C:\\tab-menu-workspace"; const files = new Map(["a.md", "b.md", "c.md", "d.md"].map(name => [name, `# ${name}\n\nOriginal [guide](docs/guide.md) text.\n\n| Name | Value |\n| --- | --- |\n| [Roadmap](docs/roadmap.md) | [[guide\\|Guide]] |\n| [One](same.md) + [Two](same.md) | Empty |\n`])); window.tabMenuTest = { prompts: [], answer: "Cancel", revealed: null, clipboard: null }; Object.defineProperty(navigator, "clipboard", { value: { writeText: async text => { window.tabMenuTest.clipboard = text; } } }); let sequence = 0; const callbacks = new Map(), listeners = new Map(); window.spellingTest = { commands: [], emit: payload => callbacks.get(listeners.get("spelling-menu"))?.({ event: "spelling-menu", id: 1, payload }) }; window.__TAURI_INTERNALS__ = { metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } }, transformCallback: callback => { callbacks.set(++sequence, callback); return sequence; }, unregisterCallback: id => callbacks.delete(id), invoke: async (command, args = {}) => { if (command === "plugin:event|listen") { listeners.set(args.event, args.handler); return ++sequence; } if (command === "plugin:event|unlisten") return; if (command.startsWith("spelling_menu_")) { window.spellingTest.commands.push({ method: command, ...args }); return; } if (command === "spelling_suggestions") return { language: "en-US", words: [], misspelled: false }; if (command === "workspace_last_path") return root; if (command === "workspace_open") return { root, name: "tab-menu-workspace", watch_mode: "native" }; if (command === "workspace_read") { if (!files.has(args.rel)) throw new Error("missing"); return files.get(args.rel); } if (command === "workspace_list") return args.rel ? [] : [{ name: "notes", rel_path: "notes", kind: "folder" }, ...[...files.keys()].map(name => ({ name, rel_path: name, kind: "file" }))]; if (command === "workspace_search") return []; if (command === "workspace_write") { files.set(args.rel, args.contents); return; } if (command === "workspace_rename") { files.set(args.to, files.get(args.from)); files.delete(args.from); return; } if (command === "workspace_abs_path") return `${root}\\${args.rel}`; if (command === "workspace_reveal") { window.tabMenuTest.revealed = args.rel; return; } if (command === "plugin:dialog|message") { window.tabMenuTest.prompts.push(args.message); return window.tabMenuTest.answer; } throw new Error(`Unhandled IPC: ${command}`); }, }; window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} }; }); try { await page.goto(process.env.SMOKE_URL || 'http://127.0.0.1:1420'); await page.locator('[data-tree-rel="a.md"]').click(); await page.locator('.writer-table').waitFor(); for(const theme of ['dark','light']) { await page.evaluate(async mode => (await import('/src/lib/theme/appearance.ts')).saveAppearance({theme:'default',mode}), theme); const prose = page.locator('.writer-link').filter({hasText:'guide'}).first(); await prose.hover(); await page.locator('.rs-tooltip:popover-open').waitFor(); assert.equal(await prose.getAttribute('title'),null); await page.screenshot({path:'.audit/editor-link-tooltip-'+theme+'.png'}); await page.keyboard.press('Escape'); await prose.click(); assert.equal(await page.locator('.writer-link-source').count(),1); const colored = await page.locator('.writer-link-source').evaluate(el => ({color:getComputedStyle(el).color, parent:getComputedStyle(el.parentElement).color})); assert.notEqual(colored.color,colored.parent); await page.screenshot({path:'.audit/editor-link-source-'+theme+'.png'}); const cell=page.locator('.writer-table td').first(); await cell.locator('a').click({position:{x:22,y:8}}); assert.ok(await page.evaluate(()=>getSelection().anchorOffset > 0)); await cell.click({button:'right'}); await page.getByRole('menuitem',{name:'Edit link',exact:true}).click(); assert.equal(await page.getByRole('dialog').count(),0); assert.equal(await page.evaluate(()=>getSelection().toString()),theme === 'dark' ? 'docs/roadmap.md' : 'docs/new-roadmap.md'); await page.screenshot({path:'.audit/editor-table-source-'+theme+'.png'}); await page.keyboard.type('docs/new-roadmap.md'); await page.keyboard.press('Enter'); assert.equal(await cell.locator('a').getAttribute('href'),'docs/new-roadmap.md'); if(theme === 'dark') { await page.locator('.cm-line').filter({hasText:'Original'}).click(); await page.keyboard.press('Control+z'); assert.equal(await cell.locator('a').getAttribute('href'),'docs/roadmap.md'); await page.keyboard.press('Control+Shift+z'); assert.equal(await cell.locator('a').getAttribute('href'),'docs/new-roadmap.md'); } await cell.locator('a').click({position:{x:22,y:8}}); const selection=await page.evaluate(()=>{const s=getSelection();return {offset:s.anchorOffset,length:s.anchorNode.textContent.length};}); assert.ok(selection.offset>0 && selection.offsetgetSelection().toString()),theme==='dark'?'guide':'new-guide'); await page.keyboard.type('new-guide'); await page.keyboard.press('Enter'); assert.equal(await wiki.locator('a').getAttribute('href'),'new-guide'); } const multi=page.locator('.writer-table td').nth(2); await multi.locator('a').nth(1).click({button:'right'}); await page.getByRole('menuitem',{name:'Edit link',exact:true}).click(); assert.equal(await page.evaluate(()=>getSelection().toString()),'same.md'); await page.keyboard.type('second.md'); await page.keyboard.press('Enter'); assert.equal(await multi.locator('a').first().getAttribute('href'),'same.md'); assert.equal(await multi.locator('a').nth(1).getAttribute('href'),'second.md'); await page.getByRole('button',{name:'Hide outline',exact:true}).click(); await page.getByRole('button',{name:'Files',exact:true}).click(); await page.setViewportSize({width:620,height:700}); await page.waitForTimeout(250); await page.locator('.table-add-row').scrollIntoViewIfNeeded(); await page.waitForTimeout(100); await page.locator('.table-add-row').focus(); await page.locator('.rs-tooltip:popover-open').waitFor(); const rect=await page.locator('.rs-tooltip:popover-open').boundingBox(); assert.ok(rect.x>=0 && rect.x+rect.width<=620); await page.screenshot({path:'.audit/editor-tooltip-narrow-focus.png'}); await page.keyboard.press('Escape'); assert.equal(await page.locator('.rs-tooltip:popover-open').count(),0); assert.equal(await page.locator('.table-edit-help:visible').count(),0); for (const mode of ['light','dark']) { await page.evaluate(async mode => (await import('/src/lib/theme/appearance.ts')).saveAppearance({theme:'default',mode}),mode); await page.locator('.writer-table td').nth(1).hover(); await page.locator('.rs-tooltip:popover-open').waitFor(); assert.match(await page.locator('.rs-tooltip:popover-open').innerText(),/Row 2, column 2/); await page.screenshot({path:'.audit/editor-cell-tooltip-narrow-'+mode+'.png'}); await page.keyboard.press('Escape'); await page.mouse.move(5,90); } assert.deepEqual(errors,[]); console.log('Editor link and tooltip checks passed'); } finally { await browser.close(); }