import assert from 'node:assert/strict'; import { createRequire } from 'node:module'; import { mkdir, writeFile } from 'node:fs/promises'; const { chromium } = createRequire(import.meta.url)(process.env.PLAYWRIGHT_MODULE || 'playwright'); const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) }); const context = await browser.newContext({ viewport: { width: 1100, height: 780 } }); await context.addInitScript(() => { window.isTauri = true; let sequence = 0; window.__TAURI_INTERNALS__ = { metadata: { currentWindow: { label: 'main' }, currentWebview: { label: 'main' } }, transformCallback: () => ++sequence, unregisterCallback: () => {}, invoke: async (command) => { if (command === 'plugins_snapshot') return { root: 'C:/plugins', plugins: [] }; if (command === 'plugin:window|is_maximized') return false; if (command === 'plugin:event|listen') return ++sequence; return null; }, }; window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} }; }); const main = await context.newPage(), settings = await context.newPage(); const origin = process.env.SMOKE_URL || 'http://127.0.0.1:5187'; const screenshots = []; await mkdir('output/todo-background', { recursive: true }); try { await main.goto(origin); await settings.goto(origin + '/?settingsWindow=true'); await settings.getByRole('button', { name: 'Appearance', exact: true }).click(); const png = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jM1sAAAAASUVORK5CYII=', 'base64'); await settings.getByLabel('Background image file', { exact: true }).setInputFiles({ name: 'image.png', mimeType: 'image/png', buffer: png }); await main.waitForFunction(() => getComputedStyle(document.querySelector('.empty')).backgroundImage.includes('blob:')); for (const [control, choice] of [['Image position', 'Top left'], ['Image size', 'Actual size']]) { const button = settings.getByRole('button', { name: control, exact: true }); await button.click(); await settings.getByRole('menuitemradio', { name: choice, exact: true }).click(); assert.equal(await button.evaluate(node => node === document.activeElement), true); } await main.waitForFunction(() => getComputedStyle(document.querySelector('.empty')).backgroundPosition.endsWith('0% 0%')); const layout = () => main.locator('.empty').evaluate(node => { const style = getComputedStyle(node), box = node.getBoundingClientRect(); return { position: style.backgroundPosition, size: style.backgroundSize, width: box.width, height: box.height }; }); const before = await layout(); assert.equal(before.size, '100% 100%, auto'); await main.locator('.empty').evaluate(node => { const content = document.createElement('div'); content.style.cssText = 'height:2000px;flex-shrink:0;width:100%'; node.append(content); }); assert.deepEqual(await layout(), before, 'Overflowing content does not resize or reposition the image surface'); await main.reload(); await main.locator('.empty').waitFor(); await main.waitForFunction(() => getComputedStyle(document.querySelector('.empty')).backgroundImage.includes('blob:')); assert.equal((await layout()).position, before.position); assert.equal((await layout()).size, before.size); await settings.getByRole('button', { name: 'Image position', exact: true }).click(); await settings.keyboard.press('End'); await settings.keyboard.press('Enter'); await main.waitForFunction(() => getComputedStyle(document.querySelector('.empty')).backgroundPosition.endsWith('100% 100%')); for (const mode of ['light', 'dark']) { await settings.evaluate(async mode => { const appearance = await import('/src/lib/theme/appearance.ts'); appearance.saveAppearance({ ...appearance.parseAppearance(localStorage.getItem(appearance.APPEARANCE_KEY)), mode }); window.dispatchEvent(new Event('focus')); }, mode); await main.waitForFunction(mode => document.documentElement.dataset.theme === mode, mode); for (const width of [1100, 360]) { await settings.setViewportSize({ width, height: 700 }); const file = `output/todo-background/settings-${mode}-${width}.png`; await settings.screenshot({ path: file }); screenshots.push(file); const pane = settings.locator('.content'); assert.equal(await pane.evaluate(node => node.scrollWidth <= node.clientWidth + 1), true); } } await writeFile('output/todo-background-report.json', JSON.stringify({ card: 'ab7b1a06-fd5a-4b74-aaa1-da64eafdf71c', checks: ['Alignment and sizing choices persist across reload and windows', 'Overflow does not resize the background surface', 'Keyboard choice and focus return', 'Both themes and narrow settings'], screenshots, native: 'Desktop visual acceptance remains pending.' }, null, 2)); console.log('PASS: background alignment, size, stable surface, persistence, keyboard, both themes, narrow settings.'); } finally { await browser.close(); }