diff --git a/src/client/src/components/SettingsDialog.general.test.ts b/src/client/src/components/SettingsDialog.general.test.ts index 7ca56c5..3a8d715 100644 --- a/src/client/src/components/SettingsDialog.general.test.ts +++ b/src/client/src/components/SettingsDialog.general.test.ts @@ -1,7 +1,7 @@ import { afterEach, describe, expect, it, vi } from "vitest"; import { configApi, type PiWebConfigResponse } from "../api"; -import { SettingsDialog } from "./SettingsDialog"; -import { callDialogPromise, callDialogUpdated, collectTemplateStrings, configResponse, deferred, getDialogProperty, remoteMachine, secondRemoteMachine, setDialogProperty, stubWindowTimers } from "./SettingsDialog.testSupport"; +import { activeSettingsPanelTag, SettingsDialog } from "./SettingsDialog"; +import { callDialogPromise, callDialogUpdated, configResponse, deferred, getDialogProperty, remoteMachine, secondRemoteMachine, setDialogProperty, stubWindowTimers } from "./SettingsDialog.testSupport"; afterEach(() => { vi.restoreAllMocks(); @@ -9,16 +9,15 @@ afterEach(() => { }); describe("settings-dialog general settings machine targeting", () => { - it("renders the active settings panel without the old global scope note", () => { - const dialog = new SettingsDialog(); - dialog.section = "general"; - dialog.machine = remoteMachine; - - const strings = collectTemplateStrings(dialog.render()).join(""); - - expect(strings).toContain(" { + // The old global "scope-note"/"This tab edits:" wrapper is gone: each section + // now maps to exactly one panel element. Assert that public routing contract + // (`activeSettingsPanelTag`) instead of scraping the rendered template markup. + expect(activeSettingsPanelTag("general")).toBe("settings-general-panel"); + expect(activeSettingsPanelTag("sessiond")).toBe("settings-sessiond-panel"); + expect(activeSettingsPanelTag("packages")).toBe("settings-packages-panel"); + expect(activeSettingsPanelTag("plugins")).toBe("settings-plugins-panel"); + expect(activeSettingsPanelTag("shortcuts")).toBe("settings-shortcuts-panel"); }); it("keeps gateway server config saves on the gateway config endpoint", async () => { diff --git a/src/client/src/components/SettingsDialog.testSupport.ts b/src/client/src/components/SettingsDialog.testSupport.ts index 24fb928..6658996 100644 --- a/src/client/src/components/SettingsDialog.testSupport.ts +++ b/src/client/src/components/SettingsDialog.testSupport.ts @@ -1,4 +1,3 @@ -import type { TemplateResult } from "lit"; import { vi } from "vitest"; import { PI_WEB_CAPABILITIES } from "../../../shared/capabilities"; import type { Machine, MachineRuntime, PiPackageInfo, PiPackageMutationResponse, PiWebConfigResponse, PiWebConfigValues, PiWebPluginInfo, PiWebPluginsResponse } from "../api"; @@ -58,43 +57,6 @@ function isDialogMethod(value: unknown): value is (this: SettingsDialog, ...args return typeof value === "function"; } -export function collectTemplateStrings(template: TemplateResult): string[] { - const strings: string[] = []; - visitTemplate(template); - return strings; - - function visitTemplate(current: TemplateResult): void { - strings.push(...templateStrings(current)); - for (const value of templateValues(current)) { - if (Array.isArray(value)) { - for (const item of value) if (isTemplateResult(item)) visitTemplate(item); - } else if (isTemplateResult(value)) { - visitTemplate(value); - } - } - } -} - -function templateStrings(template: TemplateResult): readonly string[] { - const strings = Reflect.get(template, "strings"); - if (!isStringArray(strings)) throw new Error("TemplateResult strings were unavailable"); - return strings; -} - -function templateValues(template: TemplateResult): readonly unknown[] { - const values = Reflect.get(template, "values"); - if (!Array.isArray(values)) throw new Error("TemplateResult values were unavailable"); - return values.map((value: unknown) => value); -} - -function isTemplateResult(value: unknown): value is TemplateResult { - return typeof value === "object" && value !== null && isStringArray(Reflect.get(value, "strings")) && Array.isArray(Reflect.get(value, "values")); -} - -function isStringArray(value: unknown): value is string[] { - return Array.isArray(value) && value.every((item: unknown) => typeof item === "string"); -} - export function configResponse(config: PiWebConfigValues): PiWebConfigResponse { return { path: "/tmp/pi-web/config.json", diff --git a/src/client/src/components/SettingsDialog.ts b/src/client/src/components/SettingsDialog.ts index 97571a2..fa9b99a 100644 --- a/src/client/src/components/SettingsDialog.ts +++ b/src/client/src/components/SettingsDialog.ts @@ -129,6 +129,9 @@ export class SettingsDialog extends LitElement { } private renderActiveSection(): TemplateResult { + // Keep the section -> panel routing in sync with the public + // `activeSettingsPanelTag` seam below, which tests assert against instead of + // scraping this template's markup. if (this.section === "sessiond") { return html`