fix(web): apply the selected theme preset
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled

The preset was written to data-theme in uppercase, while the CSS selectors
use lowercase/hyphenated values, so switching themes had no visual effect.

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
mes123456
2026-11-14 09:44:13 +08:00
parent c507c01a71
commit 8925869f74
4 changed files with 61 additions and 2 deletions

View File

@@ -0,0 +1,49 @@
#!/usr/bin/env node
/**
* Focused case: switch the theme preset in Preferences and observe the shell.
*
* node tools/web/complete/probe-theme.mjs --base-url http://127.0.0.1:5176
*/
import { ASSETS, parseArgs, launchBrowser, newPage, openFile, waitScene } from "../course/lib/lesson-recorder.mjs";
const args = parseArgs();
const BASE = args.baseUrl || "http://127.0.0.1:5176";
const browser = await launchBrowser(args.gpu);
const { context, page, consoleErrors } = await newPage(browser, { baseUrl: BASE });
page.setDefaultTimeout(60_000);
const log = (...parts) => console.log(new Date().toISOString().slice(11, 19), ...parts);
const themeState = async () => page.evaluate(() => ({
theme: document.documentElement.dataset.theme ?? null,
background: getComputedStyle(document.body).backgroundColor,
status: document.querySelector('[data-testid="engine-status"]')?.textContent ?? "",
}));
try {
await openFile(page, ASSETS.studio);
await waitScene(page, { objects: 6, timeout: 240_000 });
log("before", JSON.stringify(await themeState()));
await page.getByRole("button", { name: "编辑", exact: true }).click();
await page.getByRole("menuitem", { name: "偏好设置", exact: true }).click();
await page.getByRole("dialog", { name: "Web Blender 偏好设置" }).waitFor({ timeout: 30_000 });
await page.getByRole("button", { name: "主题", exact: true }).click();
const select = page.getByRole("combobox", { name: "主题预设", exact: true });
await select.waitFor({ timeout: 30_000 });
log("theme options", JSON.stringify(await select.locator("option").evaluateAll((nodes) => nodes.map((node) => node.value))));
await select.selectOption("LIGHT");
await page.getByRole("button", { name: "关闭偏好设置", exact: true }).click();
await page.waitForTimeout(800);
log("light", JSON.stringify(await themeState()));
await page.getByRole("button", { name: "编辑", exact: true }).click();
await page.getByRole("menuitem", { name: "偏好设置", exact: true }).click();
await page.getByRole("button", { name: "主题", exact: true }).click();
await page.getByRole("combobox", { name: "主题预设", exact: true }).selectOption("DARK");
await page.getByRole("button", { name: "关闭偏好设置", exact: true }).click();
await page.waitForTimeout(800);
log("dark", JSON.stringify(await themeState()));
} catch (error) {
log("probe error", error instanceof Error ? error.message : String(error));
log("state", JSON.stringify(await themeState().catch(() => null)));
} finally {
log("consoleErrors", JSON.stringify(consoleErrors.slice(-8)));
await context.close();
await browser.close();
}