// Import custom theme files in Settings > Appearance: schema 1 palettes for each mode, and a short schema 3 file with a base theme. import assert from "node:assert/strict"; import path from "node:path"; import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs"; const name = "appearance/themeImport"; await runSmoke(name, async ({ page }) => { const output = await outputDir(name); await mockTauri(page, { commands: test => ({ ...test.workspace({ root: "C:\\theme-import", files: { "a.md": "# Alpha\n" } }), plugins_snapshot: () => ({ plugins: [], issues: [] }), }), }); await page.goto(smokeUrl + "/?settingsWindow=true"); await page.getByRole("button", { name: "Appearance", exact: true }).click(); const theme = { schema: 1, id: "smoke", name: "Smoke theme", light: { bg: "#fefefe", text: "#222222", accent: "#334499" }, dark: { bg: "#181820", text: "#eeeeee", accent: "#aabbff" } }; const importTheme = (file = theme) => page.locator('input[type=file][aria-label="Theme JSON file"]').setInputFiles({ name: "smoke.json", mimeType: "application/json", buffer: Buffer.from(JSON.stringify(file)) }); const token = name => page.evaluate(name => getComputedStyle(document.documentElement).getPropertyValue(`--rs-${name}`).trim(), name); const background = () => token("bg"); await importTheme(); await page.waitForFunction(() => document.documentElement.dataset.palette === "custom:smoke"); assert.equal(await background(), "#181820"); // A custom theme now keeps one palette. A schema 1 file converts with the current mode (src/lib/theme/customThemes.ts:38, // src/lib/theme/AppearanceSettings.svelte:70), and the light/dark select became the Color theme menu (AppearanceSettings.svelte:20-31, :113). await page.getByRole("button", { name: "Color theme", exact: true }).click(); await page.getByRole("menuitemradio", { name: "RuneStone Light", exact: true }).click(); await page.waitForFunction(() => document.documentElement.dataset.palette !== "custom:smoke"); await importTheme(); await page.waitForFunction(() => document.documentElement.dataset.palette === "custom:smoke"); assert.equal(await background(), "#fefefe"); await page.screenshot({ path: path.join(output, "custom-theme-light.png") }); // A short schema 3 file takes the missing colors and fonts from its base theme. An earlier theme ID names the base. await importTheme({ schema: 3, id: "short", name: "Short theme", mode: "dark", base: "holo", colors: { accent: "#00c8ff" } }); await page.waitForFunction(() => document.documentElement.dataset.palette === "custom:short"); assert.deepEqual([await background(), await token("accent"), await token("link"), await token("syntax-keyword")], ["#251b17", "#00c8ff", "#00c8ff", "#ff6740"]); assert.match(await token("font-ui"), /Candara/); assert.equal(await page.evaluate(() => document.documentElement.dataset.theme), "dark"); await page.screenshot({ path: path.join(output, "custom-theme-short.png") }); // A base without a palette in the file's mode stops the installation with an error. await importTheme({ schema: 3, id: "wrong", name: "Wrong base", mode: "dark", base: "sakura", colors: {} }); await page.getByRole("alert").filter({ hasText: "Use a built-in theme with a dark palette as the base." }).waitFor(); assert.equal(await page.evaluate(() => document.documentElement.dataset.palette), "custom:short"); console.log("PASS: custom theme import applies schema 1 palettes, a short schema 3 file with a base, and rejects a wrong base"); }, { timeout: 15000 });