From f0a628843b10099b36d4f9d7a42e153943696fb9 Mon Sep 17 00:00:00 2001 From: zipg Date: Sun, 27 Sep 2026 10:20:53 +0800 Subject: [PATCH] fix(settings): point debug-logging search hit at the About tab --- ...ngsDialog.debugLoggingSearchTarget.spec.ts | 36 +++++++++++++++++++ .../settings/__tests__/settingsSearch.spec.ts | 25 +++++++++++++ .../src/lib/settings/settingsSearch.ts | 2 +- 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 apps/desktop/src/components/editor/__tests__/EditorSettingsDialog.debugLoggingSearchTarget.spec.ts diff --git a/apps/desktop/src/components/editor/__tests__/EditorSettingsDialog.debugLoggingSearchTarget.spec.ts b/apps/desktop/src/components/editor/__tests__/EditorSettingsDialog.debugLoggingSearchTarget.spec.ts new file mode 100644 index 0000000000..168f79f490 --- /dev/null +++ b/apps/desktop/src/components/editor/__tests__/EditorSettingsDialog.debugLoggingSearchTarget.spec.ts @@ -0,0 +1,36 @@ +// Guards the settings-search "reveal" contract for the debug logging switch +// (#10308): searching 日志 and picking the result must land on the tab that +// actually renders the switch, because the dialog switches tabs from the search +// entry's category. The entry used to declare "appearance" while the control +// lives in the About section, so the highlight never appeared. Checked against +// the real dialog source instead of mounting the multi-thousand-line dialog. +import { describe, expect, it } from "vitest"; +import { SETTINGS_SEARCH_DEFINITIONS } from "@/lib/settings/settingsSearch"; +import dialogSource from "../EditorSettingsDialog.vue?raw"; + +const DEBUG_LOGGING_SWITCH_ID = 'id="debug-logging-enabled"'; + +function tabRenderingSnippet(snippet: string, marker: string): string | null { + const sectionPattern = /activeSettingsTab === '([a-z-]+)'/g; + const sections: { tab: string; index: number }[] = []; + let match: RegExpExecArray | null; + while ((match = sectionPattern.exec(snippet))) sections.push({ tab: match[1], index: match.index }); + const markerIndex = snippet.indexOf(marker); + if (markerIndex < 0) return null; + let owningTab: string | null = null; + for (const section of sections) { + if (section.index < markerIndex) owningTab = section.tab; + } + return owningTab; +} + +describe("EditorSettingsDialog settings search targets", () => { + it("renders the debug logging switch in the tab its search entry points at", () => { + const owningTab = tabRenderingSnippet(dialogSource, DEBUG_LOGGING_SWITCH_ID); + expect(owningTab).toBe("about"); + + const entry = SETTINGS_SEARCH_DEFINITIONS.find((definition) => definition.id === "about-debug-logs"); + expect(entry?.category).toBe(owningTab); + expect(dialogSource).toContain(`data-settings-search-id="${entry?.targetId}"`); + }); +}); diff --git a/apps/desktop/src/lib/settings/__tests__/settingsSearch.spec.ts b/apps/desktop/src/lib/settings/__tests__/settingsSearch.spec.ts index 2f45003825..a935949271 100644 --- a/apps/desktop/src/lib/settings/__tests__/settingsSearch.spec.ts +++ b/apps/desktop/src/lib/settings/__tests__/settingsSearch.spec.ts @@ -132,6 +132,31 @@ describe("settings search", () => { expect(webEntries.map((entry) => entry.id)).toEqual(expect.arrayContaining(["sql-file-editor-max-mb", "sql-file-web-upload-max-mb"])); }); + it("points the debug logging result at the About tab that renders the switch", () => { + // The 启用调试日志 switch (id="debug-logging-enabled") is rendered inside the + // About section, next to the debug log copy/download/clear actions. The + // search entry used to claim "appearance", so picking the result switched + // to 外观 and never revealed the control (regression from #10308). + expect(SETTINGS_SEARCH_DEFINITIONS).toContainEqual({ + id: "about-debug-logs", + category: "about", + titleKey: "settings.debugLoggingEnabled", + descriptionKey: "settings.debugLoggingEnabledDescription", + targetId: "about", + visible: expect.any(Function), + }); + expect(SETTINGS_SEARCH_DEFINITIONS.map((definition) => definition.id)).not.toContain("appearance-debug-logs"); + + const desktopEntries = resolveSettingsSearchEntries(SETTINGS_SEARCH_DEFINITIONS, { isWeb: false, visibleCategories: new Set(["appearance", "about"]) }, translate, categoryLabels); + const entry = desktopEntries.find((item) => item.id === "about-debug-logs"); + expect(entry?.category).toBe("about"); + expect(entry?.categoryLabel).toBe("About"); + expect(entry?.targetId).toBe("about"); + + const webEntries = resolveSettingsSearchEntries(SETTINGS_SEARCH_DEFINITIONS, { isWeb: true, visibleCategories: new Set(["appearance", "about"]) }, translate, categoryLabels); + expect(webEntries.map((item) => item.id)).not.toContain("about-debug-logs"); + }); + it("maps legacy SQL file settings navigation to the editor", () => { expect(resolveSettingsCategory("sqlFile")).toBe("editor"); expect(resolveSettingsCategory()).toBe("appearance"); diff --git a/apps/desktop/src/lib/settings/settingsSearch.ts b/apps/desktop/src/lib/settings/settingsSearch.ts index 9dc0aeed8c..8a22456f71 100644 --- a/apps/desktop/src/lib/settings/settingsSearch.ts +++ b/apps/desktop/src/lib/settings/settingsSearch.ts @@ -189,7 +189,7 @@ export const SETTINGS_SEARCH_DEFINITIONS: readonly SettingsSearchDefinition[] = { id: "appearance-icons", category: "appearance", titleKey: "settings.iconTheme", targetId: "appearance", visible: desktopOnly }, { id: "appearance-tray", category: "appearance", titleKey: "settings.showTrayIcon", descriptionKey: "settings.showTrayIconDescription", targetId: "appearance", visible: desktopOnly }, { id: "appearance-quit", category: "appearance", titleKey: "settings.quitOnClose", descriptionKey: "settings.quitOnCloseDescription", targetId: "appearance", visible: desktopOnly }, - { id: "appearance-debug-logs", category: "appearance", titleKey: "settings.debugLoggingEnabled", descriptionKey: "settings.debugLoggingEnabledDescription", targetId: "appearance", visible: desktopOnly }, + { id: "about-debug-logs", category: "about", titleKey: "settings.debugLoggingEnabled", descriptionKey: "settings.debugLoggingEnabledDescription", targetId: "about", visible: desktopOnly }, { id: "navigation", category: "navigation", titleKey: "settings.navigationTab", targetId: "navigation" }, { id: "navigation-sidebar", category: "navigation", titleKey: "settings.sidebarActivation", targetId: "navigation" }, { id: "navigation-routine-source", category: "navigation", titleKey: "settings.routineSourceOpenMode", descriptionKey: "settings.routineSourceOpenModeDescription", targetId: "navigation" },