import assert from 'node:assert/strict'; import { createRequire } from 'node:module'; import { mkdir } from 'node:fs/promises'; const { chromium } = createRequire(import.meta.url)(process.env.PLAYWRIGHT_MODULE || '../browser-runtime/node_modules/playwright'); const browser = await chromium.launch({ headless: true, executablePath: process.env.CHROME_PATH || 'C:/Program Files/Google/Chrome/Application/chrome.exe' }); const output = '.audit/todo-ui'; await mkdir(output, { recursive: true }); try { for (const theme of ['light', 'dark']) { const page = await browser.newPage({ viewport: { width: 1100, height: 780 } }); const errors = []; page.on('pageerror', error => errors.push(error.message)); await page.addInitScript(() => { window.isTauri = true; window.__TAURI_INTERNALS__ = { metadata: { currentWindow: { label: 'main' }, currentWebview: { label: 'main' } }, transformCallback: () => 1, unregisterCallback() {}, invoke: async (command, args = {}) => { if (command === 'workspace_last_path') return 'C:/todo-ui'; if (command === 'workspace_open') return { root: 'C:/todo-ui', name: 'todo-ui', watch_mode: 'native' }; if (command === 'workspace_list') return [{ name: 'sample.md', rel_path: 'sample.md', kind: 'file' }]; if (command === 'workspace_read') return '# Selection sample\n\nThe same text color applies to each editor.\n'; if (command === 'plugins_snapshot') return { root: 'C:/plugins', plugins: [] }; if (command === 'workspace_search') return []; if (command === 'browser_request') { if (args.command === 'frameAck') window.blankAcks = (window.blankAcks || 0) + 1; return window.browserSnapshot; } return null; }, }; window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener() {} }; }); await page.goto(process.env.SMOKE_URL || 'http://127.0.0.1:1420'); await page.getByText('todo-ui', { exact: true }).waitFor(); await page.evaluate(async theme => { const { saveAppearance } = await import('/src/lib/theme/appearance.ts'); saveAppearance({ theme: 'default', mode: theme }); const { attachTooltip } = await import('/src/lib/ui/tooltip.ts'); const cell = document.createElement('button'); cell.id = 'tooltip-test'; cell.textContent = 'Formula cell'; Object.assign(cell.style, { position: 'fixed', left: '20px', top: '100px', zIndex: '2000' }); document.body.append(cell); window.disposeTip = attachTooltip(cell, () => 'B6 · Click to edit · Type = for a formula'); }, theme); const target = page.locator('#tooltip-test'); await target.hover(); const tooltip = page.locator('.rs-tooltip:popover-open'); await tooltip.waitFor(); assert.equal(await target.getAttribute('title'), null); assert.equal(await tooltip.evaluate(node => getComputedStyle(node).borderRadius), '5px'); await page.screenshot({ path: `${output}/${theme}-tooltip.png` }); await page.keyboard.press('Escape'); assert.equal(await page.locator('.rs-tooltip:popover-open').count(), 0); await target.focus(); await tooltip.waitFor(); await page.setViewportSize({ width: 390, height: 620 }); await page.locator('header').first().hover(); await target.hover(); await tooltip.waitFor(); const bounds = await tooltip.boundingBox(); assert(bounds.x >= 8 && bounds.x + bounds.width <= 382); await page.screenshot({ path: `${output}/${theme}-narrow-tooltip.png` }); await page.evaluate(() => { window.disposeTip(); document.getElementById('tooltip-test').remove(); }); await page.setViewportSize({ width: 1100, height: 780 }); await page.keyboard.press('Control+p'); await page.getByRole('textbox', { name: 'Find a file' }).fill('sample.md'); await page.getByRole('textbox', { name: 'Find a file' }).press('Enter'); const writer = page.getByRole('textbox', { name: 'Writing editor', exact: true }); await writer.waitFor(); await writer.click(); await page.keyboard.press('Control+a'); const colors = await writer.evaluate(node => { const probe = document.createElement('span'); probe.style.backgroundColor = 'var(--rs-selection)'; node.append(probe); const expected = getComputedStyle(probe).backgroundColor; probe.remove(); return { expected, native: getComputedStyle(node, '::selection').backgroundColor, layer: getComputedStyle(document.querySelector('.cm-selectionBackground')).backgroundColor }; }); assert.equal(colors.native, colors.expected); assert.equal(colors.layer, colors.expected); await page.screenshot({ path: `${output}/${theme}-writer-selection.png` }); await page.getByRole('group', { name: 'Document view', exact: true }).hover(); await page.getByRole('button', { name: 'Read', exact: true }).click(); const reader = page.locator('.reading'); await reader.waitFor(); assert.equal(await reader.evaluate(node => getComputedStyle(node, '::selection').backgroundColor), colors.expected); await page.evaluate(async () => { const { mount } = await import('/node_modules/svelte/src/index-client.js'); const { default: Browser } = await import('/src/lib/browser/Browser.svelte'); const client = await import('/src/lib/browser/client.ts'); const container = document.createElement('div'); container.id = 'browser-test'; Object.assign(container.style, { position: 'fixed', inset: '50px 10px 20px', zIndex: '2000', background: 'linear-gradient(120deg,#945975,#395c72)' }); document.body.append(container); window.browserSnapshot = { profiles: [{ id: 'user', name: 'User' }], tabs: [{ id: 'blank', profileId: 'user', url: 'about:blank', title: '', loading: false }], bookmarks: [], settings: {} }; client.state.set(window.browserSnapshot); mount(Browser, { target: container, props: { initial: { tabId: 'blank' }, onSessionChange() {}, async newTab() {} } }); window.browserClient = client; }); const surface = page.locator('#browser-test .surface'); await page.locator('#browser-test [data-browser-state="ready"]').waitFor(); await page.evaluate(() => window.browserClient.frames.get('blank')({ tabId: 'blank', frameId: 1, width: 10, height: 10, mime: 'image/png', data: 'AA==' })); assert.equal(await surface.evaluate(node => getComputedStyle(node).backgroundColor), 'rgba(0, 0, 0, 0)'); assert.equal(await surface.locator('img').count(), 0); assert.equal(await page.evaluate(() => window.blankAcks), 1); await page.screenshot({ path: `${output}/${theme}-blank-browser.png` }); await page.evaluate(() => { window.browserSnapshot.tabs[0].url = 'https://example.com/minimal'; window.browserClient.state.set({ ...window.browserSnapshot }); const canvas = document.createElement('canvas'); canvas.width = 10; canvas.height = 10; const ctx = canvas.getContext('2d'); ctx.fillStyle = 'white'; ctx.fillRect(0, 0, 10, 10); window.browserClient.frames.get('blank')({ tabId: 'blank', frameId: 2, width: 10, height: 10, mime: 'image/png', data: canvas.toDataURL().split(',')[1] }); }); await surface.locator('img').waitFor(); assert.notEqual(await surface.evaluate(node => getComputedStyle(node).backgroundColor), 'rgba(0, 0, 0, 0)'); assert.deepEqual(errors, []); await page.close(); } console.log('To do UI smoke passed: tooltips, selection, blank browser, light/dark/narrow.'); } finally { await browser.close(); }