// Theme variants: transparency slider in eight variants, custom theme fonts, a single tooltip, and slideshow command icons. import assert from 'node:assert/strict'; import path from 'node:path'; import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs'; await runSmoke('appearance/themeVariants', async ({ browser }) => { const output = await outputDir('appearance/themeVariants'); const context = await browser.newContext({ viewport: { width: 1100, height: 800 } }); await mockTauri(context, { commands: test => ({ ...test.workspace({ root: 'C:\\appearance-smoke', files: Object.fromEntries(Array.from({ length: 12 }, (_, index) => [`theme-${index}.py`, `# Theme sample ${index}\ndef sample(parameter):\n return parameter\nname = "RuneStone"\nprint(name, 42)\n`])), }), plugins_snapshot: () => ({ root: 'C:/appearance-smoke-plugins', plugins: [] }), 'plugin:window|is_maximized': () => false, }), }); const page = await openPage(context); await page.goto(`${smokeUrl}/?settingsWindow=true`); await page.getByRole('button', { name: 'Appearance', exact: true }).click(); const transparent = page.getByRole('switch', { name: 'Transparent surfaces', exact: true }); for (const [theme, mode] of [['default', 'dark'], ['default', 'light'], ['claude', 'dark'], ['claude', 'light'], ['sakura', 'light'], ['harvest-moon', 'dark'], ['crimson-pilot', 'dark'], ['silver-serpent', 'dark']]) { await page.evaluate(async ({ theme, mode }) => { (await import('/src/lib/theme/appearance.ts')).saveAppearance({ theme, mode, transparency: { enabled: true, amount: 18 } }); window.dispatchEvent(new Event('focus')); }, { theme, mode }); const slider = page.locator('#surface-transparency'); await slider.fill('100'); assert.equal(await page.evaluate(() => window.__TEST__.settings('appearance').transparency.amount), 100); await slider.focus(); await page.keyboard.press('Home'); assert.equal(await slider.inputValue(), '0'); await page.keyboard.press('End'); assert.equal(await slider.inputValue(), '100'); await page.screenshot({ path: path.join(output, `${theme}-${mode}-slider-focus.png`) }); await transparent.uncheck(); assert(await slider.isDisabled()); await page.screenshot({ path: path.join(output, `${theme}-${mode}-slider-disabled.png`) }); await transparent.check(); await page.setViewportSize({ width: 360, height: 740 }); await slider.scrollIntoViewIfNeeded(); assert(await page.locator('.content').evaluate(node => node.scrollWidth <= node.clientWidth)); await page.screenshot({ path: path.join(output, `${theme}-${mode}-narrow.png`) }); await page.setViewportSize({ width: 1100, height: 800 }); } await page.evaluate(async () => { const { installTheme } = await import('/src/lib/theme/customThemes.ts'); const { saveAppearance, exportAppearanceTheme } = await import('/src/lib/theme/appearance.ts'); const theme = exportAppearanceTheme('default'); theme.fonts = { ui: 'Arial, sans-serif', prose: 'Georgia, serif', heading: 'Georgia, serif', mono: 'Consolas, monospace' }; installTheme(theme); saveAppearance({ theme: 'custom:my-theme', mode: 'dark' }); window.dispatchEvent(new Event('focus')); }); assert.match(await page.locator('.preview-prose').evaluate(node => getComputedStyle(node).fontFamily), /Georgia/); assert.match(await page.evaluate(async () => (await import('/src/lib/theme/appearance.ts')).exportAppearanceTheme('custom:my-theme').fonts.ui), /Arial/); await page.screenshot({ path: path.join(output, 'custom-fonts.png') }); const main = await openPage(context); await main.goto(smokeUrl); await main.bringToFront(); await main.getByRole('button', { name: 'Files', exact: true }).waitFor(); await main.evaluate(async () => { const loaded = performance.getEntriesByType('resource').map(entry => entry.name).find(name => new URL(name).pathname === '/src/lib/plugins/external.ts'); const { pluginTools, refreshPlugins } = await import(loaded || '/src/lib/plugins/external.ts'); await refreshPlugins(); const invoke = window.__TAURI_INTERNALS__.invoke; window.__TAURI_INTERNALS__.invoke = (command, args) => command === 'plugins_snapshot' ? Promise.resolve(null) : invoke(command, args); const commands = [{ owner: 'runestone.background-slideshow', id: 'next-image', title: 'Next background image', kind: 'command', surface: 'commands', icon: 'skip-forward' }, { owner: 'runestone.background-slideshow', id: 'pause-resume', title: 'Pause or resume background slideshow', kind: 'command', surface: 'commands', icon: 'pause' }]; pluginTools.set(commands); }); const visibleTooltips = () => main.locator('[role=tooltip]:visible').count(); for (const mode of ['dark', 'light']) { await main.evaluate(async mode => (await import('/src/lib/theme/appearance.ts')).saveAppearance({ theme: 'default', mode }), mode); const button = main.getByRole('button', { name: 'Commands', exact: true }); assert.equal(await button.getAttribute('title'), null); await button.hover(); await main.waitForTimeout(1100); assert.equal(await visibleTooltips(), 1); await main.screenshot({ path: path.join(output, `${mode}-single-tooltip.png`) }); await main.keyboard.press('Escape'); assert.equal(await visibleTooltips(), 0); await main.mouse.move(400, 400); await button.evaluate(node => node.blur()); await button.focus(); await main.waitForTimeout(600); assert.equal(await visibleTooltips(), 1); await button.click(); await main.getByRole('menu').waitFor(); const paths = await main.locator('.rs-menu svg').evaluateAll(nodes => nodes.map(node => node.innerHTML)); assert(paths.some(path => path.includes('M7 4v16'))); assert(paths.some(path => path.includes('m4 4 12 8'))); await main.screenshot({ path: path.join(output, `${mode}-slideshow-command-icons.png`) }); await main.keyboard.press('Escape'); } assert.deepEqual([...page.errors, ...main.errors], []); console.log('PASS: eight theme variants, slider endpoints, persistence, disabled states, narrow layout, font import/export, single tooltip, and command icons.'); });