fix(settings): point debug-logging search hit at the About tab
This commit is contained in:
3 files changed
+62
-1
No files matched your search
Vendored
+36
@@ -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}"`);
|
||||
});
|
||||
});
|
||||
@@ -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<SettingsCategory>(["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<SettingsCategory>(["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");
|
||||
|
||||
@@ -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" },
|
||||
|
||||
Reference in new issue
Block a user