Skip to content

Commit 1b2e565

Browse files
fix(interface): persist theme change from command palette (#748)
1 parent 118e144 commit 1b2e565

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

public/components/command-palette/command-palette.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,22 @@ class CommandPalette extends LitElement {
378378
switch (action.id) {
379379
case "toggle_theme": {
380380
const nextTheme = window.settings.config.theme === "dark" ? "light" : "dark";
381+
const config = window.settings.config;
382+
fetch("/config", {
383+
method: "put",
384+
body: JSON.stringify({
385+
...config,
386+
theme: nextTheme,
387+
ignore: {
388+
warnings: [...config.ignore.warnings],
389+
flags: [...config.ignore.flags]
390+
}
391+
}),
392+
headers: { "content-type": "application/json" }
393+
}).catch(console.error);
394+
381395
window.dispatchEvent(new CustomEvent(EVENTS.SETTINGS_SAVED, {
382-
detail: { ...window.settings.config, theme: nextTheme }
396+
detail: { ...config, theme: nextTheme }
383397
}));
384398
break;
385399
}

test/e2e/command-palette.spec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ import { test, expect } from "@playwright/test";
33

44
test.describe("[command-palette] presets and actions", () => {
55
let i18n;
6+
let initialConfig;
7+
8+
test.beforeAll(async({ request }) => {
9+
const response = await request.get("/config");
10+
initialConfig = await response.json();
11+
});
12+
13+
test.afterAll(async({ request }) => {
14+
await request.put("/config", { data: initialConfig });
15+
});
616

717
test.beforeEach(async({ page }) => {
818
await page.goto("/");
@@ -85,6 +95,25 @@ test.describe("[command-palette] presets and actions", () => {
8595
expect(newTheme).toBe(expectedTheme);
8696
});
8797

98+
test("theme toggle from command palette persists after page reload", async({ page }) => {
99+
const initialTheme = await page.evaluate(() => window.settings.config.theme);
100+
const expectedTheme = initialTheme === "dark" ? "light" : "dark";
101+
102+
const actionsSection = page.locator(".section").filter({ hasText: i18n.section_actions });
103+
const toggleLabel = i18n[`action_toggle_theme_to_${expectedTheme}`];
104+
const [response] = await Promise.all([
105+
page.waitForResponse((resp) => resp.url().includes("/config") && resp.request().method() === "PUT"),
106+
actionsSection.locator(".range-preset").filter({ hasText: toggleLabel }).click()
107+
]);
108+
expect(response.status()).toBe(204);
109+
110+
await page.reload();
111+
await page.waitForSelector(`[data-menu="network--view"].active`);
112+
113+
const themeAfterReload = await page.evaluate(() => window.settings.config.theme);
114+
expect(themeAfterReload).toBe(expectedTheme);
115+
});
116+
88117
test("pressing Escape closes the palette", async({ page }) => {
89118
await page.keyboard.press("Escape");
90119

0 commit comments

Comments
 (0)