// Built-in palettes: modes, light-only Sakura, migration, persistence, typography, cross-window sync, source editor updates, and narrow settings. import assert from "node:assert/strict"; import path from "node:path"; import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs"; await runSmoke("appearance/palettes", async ({ browser }) => { const output = await outputDir("appearance/palettes"); const context = await browser.newContext({ viewport: { width: 1100, height: 780 } }); 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 main = await openPage(context); const settings = await openPage(context); const secondSettings = await openPage(context); const pages = [main, settings, secondSettings]; try { await main.goto(smokeUrl); await main.getByText("appearance-smoke", { exact: true }).waitFor(); async function openCode(index) { await main.keyboard.press("Control+p"); await main.getByRole("textbox", { name: "Find a file" }).fill(`theme-${index}.py`); await main.getByRole("dialog").getByRole("button").filter({ hasText: `theme-${index}.py` }).first().waitFor(); await main.getByRole("textbox", { name: "Find a file" }).press("Enter"); await main.locator(".source-editor .cm-content").waitFor(); await main.waitForFunction(file => document.querySelector(".editor .breadcrumb")?.textContent.endsWith(file) && document.querySelector(".source-editor .cm-content")?.dataset.language === "python", `theme-${index}.py`); await main.locator(".source-editor .cm-line").filter({ hasText: `Theme sample ${index}` }).waitFor(); } async function editorIds() { // Mark each mounted editor once. A new editor has no mark, so it gets a new identifier. return main.evaluate(() => [...document.querySelectorAll(".source-editor .cm-editor")] .map(node => node.dataset.smokeId ||= String(window.__editorSerial = (window.__editorSerial || 0) + 1))); } // Wait until "RuneStone", "def", and "42" have three distinct syntax colors. async function waitForSyntax() { await main.waitForFunction(() => { const spans = [...document.querySelectorAll(".source-editor .cm-line span")]; const colors = ["RuneStone", "def", "42"].map(text => { const span = spans.find(node => !node.children.length && node.textContent.includes(text)); return span ? getComputedStyle(span).color : null; }); return colors.every(Boolean) && new Set(colors).size === 3; }); } const themeName = (theme, mode) => theme === "sakura" ? "Sakura" : `${({ default: "RuneStone", claude: "Claude" })[theme]} ${mode === "light" ? "Light" : "Dark"}`; const picker = (page, name) => page.locator(".picker").filter({ has: page.locator("svg") }).and(page.getByRole("button", { name, exact: true })); async function choose(page, theme, mode) { await picker(page, "Color theme").click(); await page.getByRole("menuitemradio", { name: themeName(theme, mode), exact: true }).click(); } async function openAppearance(page) { await page.goto(`${smokeUrl}/?settingsWindow=true`); await page.getByRole("button", { name: "Appearance", exact: true }).click(); await picker(page, "Color theme").waitFor(); } await openCode(0); await openAppearance(settings); await openAppearance(secondSettings); async function expectAppearance(theme, mode) { for (const page of [settings, secondSettings, main]) { await page.waitForFunction(({ theme, mode }) => document.documentElement.dataset.palette === theme && document.documentElement.dataset.theme === mode, { theme, mode }); assert.equal(await page.evaluate(() => getComputedStyle(document.documentElement).colorScheme), mode); } assert.equal((await picker(secondSettings, "Color theme").textContent()).trim(), themeName(theme, mode)); await main.waitForFunction(() => { const root = document.documentElement; const probe = document.createElement("i"); probe.style.backgroundColor = getComputedStyle(root).getPropertyValue("--rs-workarea-editor-bg"); document.body.append(probe); const expected = getComputedStyle(probe).backgroundColor; probe.remove(); const surfaces = [...document.querySelectorAll(".source-editor .cm-editor")]; const workarea = document.querySelector(".editor > .body"); return surfaces.length > 0 && surfaces.every(element => getComputedStyle(element).backgroundColor === "rgba(0, 0, 0, 0)") && workarea && getComputedStyle(workarea).backgroundColor === expected; }); return settings.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue("--rs-bg").trim()); } let nextCode = 1; const backgrounds = new Set(); for (const theme of ["default", "claude", "sakura"]) { for (const mode of theme === "sakura" ? ["light"] : ["light", "dark"]) { const before = await editorIds(); await choose(settings, theme, mode); backgrounds.add(await expectAppearance(theme, mode)); assert.deepEqual(await editorIds(), before, "Existing source editors keep their identity when a theme changes"); await openCode(nextCode++); assert.notDeepEqual(await editorIds(), before, "A new file creates a new source editor"); await expectAppearance(theme, mode); await waitForSyntax(); assert.deepEqual(await settings.evaluate(() => window.__TEST__.settings("appearance")), { theme, mode }); await settings.screenshot({ path: path.join(output, `appearance-${theme}-${mode}.png`) }); await main.screenshot({ path: path.join(output, `appearance-editor-${theme}-${mode}.png`) }); if (theme === "sakura") { const keywordColor = await main.locator(".source-editor .cm-line span").evaluateAll(spans => { const keyword = spans.find(span => !span.children.length && span.textContent.trim() === "def"); return keyword ? getComputedStyle(keyword).color : null; }); assert.equal(keywordColor, "rgb(160, 68, 107)", "Sakura keywords use the Rose Garden hue"); } const typography = await settings.evaluate(() => ({ body: getComputedStyle(document.body).fontFamily, heading: getComputedStyle(document.querySelector("h2")).fontFamily, prose: getComputedStyle(document.documentElement).getPropertyValue("--rs-font-prose").trim(), })); if (theme === "claude") { assert.match(typography.body, /Lora.*Georgia/); assert.match(typography.prose, /Lora.*Georgia/); assert.match(typography.heading, /Poppins.*Arial/); assert.equal(await settings.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue("--rs-accent").trim()), mode === "light" ? "#ab4e2f" : "#ed8968"); } else assert.doesNotMatch(typography.body, /Lora|Georgia/); console.log(`PASS: ${theme} ${mode}, saved state, cross-window selection, existing and new source editors`); } } assert.equal(backgrounds.size, 5, "All supported combinations have distinct backgrounds"); await picker(settings, "Color theme").click(); assert.deepEqual(await settings.getByRole("menuitemradio").allTextContents(), ["RuneStone Light", "RuneStone Dark", "Claude Light", "Claude Dark", "Sakura", "Harvest Moon", "Crimson Pilot", "Silver Serpent"]); await settings.keyboard.press("Escape"); assert.equal(await picker(settings, "Appearance").count(), 0); assert.equal(await picker(secondSettings, "Appearance").count(), 0); const sakura = await settings.evaluate(() => { const css = getComputedStyle(document.documentElement); return Object.fromEntries(["bg", "border", "selection", "bg-active", "syntax-keyword", "syntax-variable", "syntax-property", "syntax-constant", "syntax-punctuation"].map(key => [key, css.getPropertyValue(`--rs-${key}`).trim()])); }); // The applied selection color caps its alpha at a6 so text backgrounds show through (appliedColors in src/lib/theme/contrast.ts). assert.deepEqual(sakura, { bg: "#fefcfc", border: "#efd3dd", selection: "#ffc9dca6", "bg-active": "#f8dbe6", "syntax-keyword": "#a0446b", "syntax-variable": "#513346", "syntax-property": "#47658e", "syntax-constant": "#316a83", "syntax-punctuation": "#566575" }); for (const [theme, savedMode, expectedTheme, mode] of [ ["gpt", "light", "default", "light"], ["terminal", "dark", "default", "dark"], ["sakura", "dark", "sakura", "light"], ]) { await settings.evaluate(value => window.__TEST__.writeSettings("appearance", value), { theme, mode: savedMode }); await settings.reload(); await settings.getByRole("button", { name: "Appearance", exact: true }).click(); await expectAppearance(expectedTheme, mode); assert.deepEqual(await settings.evaluate(() => window.__TEST__.settings("appearance")), { theme: expectedTheme, mode }); console.log(`PASS: saved ${theme} ${savedMode} migrates to ${expectedTheme} ${mode}`); } for (const [theme, mode] of [["default", "dark"], ["claude", "light"], ["claude", "dark"], ["sakura", "light"]]) { await settings.setViewportSize({ width: 1100, height: 780 }); await choose(settings, theme, mode); await expectAppearance(theme, mode); await settings.setViewportSize({ width: 360, height: 480 }); assert(await settings.evaluate(() => document.documentElement.scrollWidth <= innerWidth), "Narrow settings do not overflow the viewport"); assert(await settings.locator("dialog .content").evaluate(node => node.scrollWidth <= node.clientWidth), "Appearance controls do not overflow the content area"); const control = picker(settings, "Color theme"); await control.scrollIntoViewIfNeeded(); const bounds = await control.boundingBox(); assert(bounds.x >= 0 && bounds.x + bounds.width <= 360 && bounds.height >= 28, "Color theme remains reachable at 360px"); await settings.screenshot({ path: path.join(output, `appearance-${theme}-${mode}-360.png`) }); } assert.deepEqual(pages.flatMap(page => page.errors), []); } catch (error) { for (const [index, page] of pages.entries()) await page.screenshot({ path: path.join(output, `appearance-failure-${index}.png`) }).catch(() => {}); throw error; } });