// Background image position and size: menu choices, a stable surface under overflow, persistence, keyboard choice, both themes, narrow settings. import assert from 'node:assert/strict'; import { writeFile } from 'node:fs/promises'; import path from 'node:path'; import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs'; // The image is painted on .workarea-background, not on the empty tab (src/lib/layout/Workbench.svelte:1258, 1543). await runSmoke('appearance/backgroundLayout', async ({ browser }) => { const output = await outputDir('appearance/backgroundLayout'); const context = await browser.newContext({ viewport: { width: 1100, height: 780 } }); await mockTauri(context, { commands: () => ({ plugins_snapshot: () => ({ root: 'C:/plugins', plugins: [] }), 'plugin:window|is_maximized': () => false, }), }); const main = await openPage(context), settings = await openPage(context); const screenshots = []; await main.goto(smokeUrl); await main.locator('.empty').waitFor(); await settings.goto(smokeUrl + '/?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('.workarea-background')).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('.workarea-background')).backgroundPosition.endsWith('0% 0%')); const layout = () => main.locator('.workarea-background').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('.workarea-background')).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('.workarea-background')).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 = path.join(output, `settings-${mode}-${width}.png`); await settings.screenshot({ path: file }); screenshots.push(file); assert.equal(await settings.locator('.content').evaluate(node => node.scrollWidth <= node.clientWidth + 1), true); } } await writeFile(path.join(output, '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)); assert.deepEqual([...main.errors, ...settings.errors], []); console.log('PASS: background alignment, size, stable surface, persistence, keyboard, both themes, narrow settings.'); });