import assert from 'node:assert/strict'; import { mkdir } from 'node:fs/promises'; import { createRequire } from 'node:module'; const require = createRequire(import.meta.url); const { chromium } = require(process.env.PLAYWRIGHT_MODULE || 'playwright'); const origin = process.env.SMOKE_URL || 'http://127.0.0.1:1420'; const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) }); const errors = []; await mkdir('.audit/appearance-language', { recursive: true }); try { const context = await browser.newContext({ viewport: { width: 1100, height: 800 } }); await context.addInitScript(() => { window.isTauri = true; const root = "C:\\appearance-smoke"; const files = new Map(Array.from({ length: 12 }, (_, index) => [`theme-${index}.py`, `# Theme sample ${index}\ndef sample(parameter):\n return parameter\nname = "RuneStone"\nprint(name, 42)\n`])); const callbacks = new Map(); let sequence = 0; window.__TAURI_INTERNALS__ = { metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } }, transformCallback: callback => { const id = ++sequence; callbacks.set(id, callback); return id; }, unregisterCallback: id => callbacks.delete(id), invoke: async (command, args = {}) => { if (command === "plugins_snapshot") return { root: "C:/appearance-smoke-plugins", plugins: [] }; if (command === "workspace_last_path") return root; if (command === "workspace_open") return { root, name: "appearance-smoke", watch_mode: "native" }; if (command === "workspace_read") { if (!files.has(args.rel)) throw new Error("File absent"); return files.get(args.rel); } if (command === "workspace_write") { files.set(args.rel, args.contents); return; } if (command === "workspace_list") return [...files.keys()].filter(path => !path.startsWith(".")).map(path => ({ name: path, rel_path: path, kind: "file" })); if (command === "workspace_search") return []; if (command === "plugin:event|listen") return args.handler; if (command === "plugin:window|is_maximized") return false; return null; }, }; window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} }; }); const settings = await context.newPage(); const main = await context.newPage(); for (const page of [settings, main]) { page.on('pageerror', error => errors.push(error.message)); page.setDefaultTimeout(15000); } await main.goto(origin); await settings.goto(`${origin}/?settingsWindow=true`); await settings.locator('#language-picker').waitFor(); for (const [language, name, heading, appearance, enabled, files] of [ ['fr', 'Français', 'Paramètres', 'Apparence', 'Surfaces transparentes', 'Fichiers'], ['ja', '日本語', '設定', '外観', '背景を透過', 'ファイル'], ['zh-CN', '简体中文', '设置', '外观', '透明界面', '文件'], ['en', 'English', 'Settings', 'Appearance', 'Transparent surfaces', 'Files'], ]) { await settings.locator('#language-picker').click(); await settings.getByRole('menuitemradio', { name, exact: true }).click(); await settings.getByRole('heading', { name: heading, exact: true }).waitFor(); await main.getByRole('button', { name: files, exact: true }).waitFor(); assert.equal(await settings.locator('html').getAttribute('lang'), language); assert.equal(await main.locator('html').getAttribute('lang'), language); assert.equal(await settings.evaluate(() => localStorage.getItem('runestone.language')), language); await settings.reload(); await settings.getByRole('heading', { name: heading, exact: true }).waitFor(); // Arrow keys and Escape retain shared menu focus behavior. await settings.locator('#language-picker').focus(); await settings.keyboard.press('Enter'); await settings.keyboard.press('End'); await settings.keyboard.press('Home'); await settings.keyboard.press('Escape'); assert(await settings.locator('#language-picker').evaluate(node => node === document.activeElement)); assert(await main.evaluate(async () => { const { imageControls } = await import('/src/lib/editor/imageControls.ts'); const root = document.createElement('div'); root.innerHTML = 'sample'; document.body.append(root); let removed = false; const cleanup = imageControls(root, { remove: () => { removed = true; } }); root.querySelector('.md-image-frame').dispatchEvent(new KeyboardEvent('keydown', { key: 'Delete', bubbles: true })); cleanup(); root.remove(); return removed; }), `${language}: Delete image keyboard action`); assert(await main.evaluate(async () => { const { tableSelectionControls } = await import('/src/lib/editor/tableSelectionControls.ts'); const root = document.createElement('div'); root.innerHTML = '
AB
onetwo
'; document.body.append(root); const wrapper = root.firstElementChild, table = root.querySelector('table'); let text = '| A | B |\n| --- | --- |\n| one | two |'; const view = { posAtDOM: () => 0, dom: root, focus() {} }; const controls = tableSelectionControls(root, wrapper, table, view, () => text, () => {}, next => { text = next; }, { get: () => undefined, activate() {}, editSource() {} }, {}); controls.select({ anchor: { row: 1, column: 0 }, head: { row: 1, column: 0 } }); wrapper.dispatchEvent(new KeyboardEvent('keydown', { key: 'Delete', bubbles: true })); controls.destroy(); root.remove(); return !text.includes('one') && text.includes('two'); }), `${language}: Delete selected table cell keyboard action`); await settings.screenshot({ path: `.audit/appearance-language/${language}-general.png` }); await main.locator('[data-tree-rel="theme-0.py"]').click(); await main.locator('.monaco-editor textarea').waitFor(); await main.locator('.view-lines').first().click({ button: 'right' }); await main.locator('.rs-menu').waitFor(); const copyLabels = { fr: 'Copier', ja: 'コピー', 'zh-CN': '复制', en: 'Copy' }; await main.locator('.rs-menu .action-label').filter({ hasText: new RegExp('^' + copyLabels[language] + '$') }).waitFor(); await main.screenshot({ path: `.audit/appearance-language/${language}-workbench-editor-menu.png` }); await main.keyboard.press('Escape'); await settings.getByRole('button', { name: appearance, exact: true }).click(); for (const mode of ['dark', 'light']) { await settings.evaluate(async mode => { const appearance = await import('/src/lib/theme/appearance.ts'); appearance.saveAppearance({ theme: 'default', mode, transparency: { enabled: true, amount: 18 } }); window.dispatchEvent(new Event('focus')); }, mode); const toggle = settings.getByRole('switch', { name: enabled, exact: true }); await toggle.uncheck(); assert.equal(await settings.locator('html').getAttribute('data-transparency'), 'off'); await main.waitForFunction(() => document.documentElement.dataset.transparency === 'off'); const opacity = await settings.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue('--rs-surface-opacity').trim()); assert.equal(opacity, '100%'); await settings.locator('.picker').first().click(); const menu = settings.getByRole('menu'); const bg = await menu.evaluate(node => getComputedStyle(node).backgroundColor); assert(!bg.endsWith('/ 0.82)') && !bg.startsWith('rgba'), `Opaque menu: ${bg}`); await settings.screenshot({ path: `.audit/appearance-language/${language}-${mode}-opaque-menu.png` }); await settings.keyboard.press('Escape'); await toggle.check(); await settings.locator('#surface-transparency').fill('30'); assert.equal(await settings.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue('--rs-surface-opacity').trim()), '70%'); await settings.setViewportSize({ width: 360, height: 640 }); await settings.locator("#surface-transparency").scrollIntoViewIfNeeded(); assert(await settings.locator('.content').evaluate(node => node.scrollWidth <= node.clientWidth), `${language} ${mode}: narrow overflow`); await settings.screenshot({ path: `.audit/appearance-language/${language}-${mode}-narrow.png` }); await settings.setViewportSize({ width: 1100, height: 800 }); } await settings.reload(); } assert.deepEqual(errors, []); console.log('PASS: 4 locales, persistence, cross-window updates, keyboard menu focus, both themes, opaque menus, transparency levels, narrow layout.'); } finally { await browser.close(); }