test: drop source-text assertion tests and merge locale checks

This commit is contained in:
t8y2 committed 2026-09-23 22:10:06 +08:00
1 parent 349d77d180
commit 8897e12714
257 files changed
+166 -12815

No files matched your search

@@ -1,4 +1,3 @@
import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
import {
EDITOR_SETTINGS_DRAFT_KEYS,
@@ -12,8 +11,6 @@ import {
} from "../editorSettingsDraft";
import type { EditorSettings } from "@/stores/settingsStore";
const settingsDialogSource = readFileSync(new URL("../../../components/editor/EditorSettingsDialog.vue", import.meta.url), "utf8");
function makeSettings(overrides: Partial<EditorSettings> = {}): EditorSettings {
return {
autoCalculateTotalRows: false,
@@ -143,16 +140,6 @@ describe("EDITOR_SETTINGS_DRAFT_KEYS", () => {
});
});
describe("cell detail button settings control", () => {
it("binds the switch through apply and both reset paths", () => {
expect(settingsDialogSource).toContain("const editDataGridCellDetailButtonVisible = ref(settingsStore.editorSettings.dataGridCellDetailButtonVisible)");
expect(settingsDialogSource).toContain("dataGridCellDetailButtonVisible: editDataGridCellDetailButtonVisible.value");
expect(settingsDialogSource).toContain("editDataGridCellDetailButtonVisible.value = settingsStore.editorSettings.dataGridCellDetailButtonVisible");
expect(settingsDialogSource.match(/editDataGridCellDetailButtonVisible\.value = DEFAULT_EDITOR_SETTINGS\.dataGridCellDetailButtonVisible/g)).toHaveLength(2);
expect(settingsDialogSource).toContain('id="data-grid-cell-detail-button-visible" v-model="editDataGridCellDetailButtonVisible"');
});
});
describe("editorSettingsDraftFromSettings", () => {
it("round-trips a hidden line-number preference through the draft patch", () => {
const settings = makeSettings({ showLineNumbers: true });
@@ -504,13 +491,4 @@ describe("editorSettingsDraftPatchFromSettings", () => {
const patch = editorSettingsDraftPatchFromSettings({ pageSize: 999999 } as Partial<EditorSettings>);
expect(patch.pageSize).toBe(normalizeTableOpenPageSizeDraft(999999));
});
it("is the base for the settings import path in the dialog", () => {
// The import must patch only imported keys into the edit refs; rebuilding
// the whole draft would drop unsaved state the file does not cover (e.g. a
// half-filled table-column template row, which serialization drops).
expect(settingsDialogSource).toContain("const patch = editorSettingsDraftPatchFromSettings(imported);");
expect(settingsDialogSource).toContain("applyEditorSettingsKeysToRefs(patch as EditorSettingsDraft, Object.keys(patch) as EditorSettingsDraftKey[]);");
expect(settingsDialogSource).not.toContain("const merged = editorSettingsDraftFromSettings({");
});
});
@@ -1,40 +0,0 @@
import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
const appSource = readFileSync(new URL("../../../App.vue", import.meta.url), "utf8");
const settingsDialogSource = readFileSync(new URL("../../../components/editor/EditorSettingsDialog.vue", import.meta.url), "utf8");
describe("settings page navigation", () => {
it("keeps query, settings, and driver-manager surfaces mutually exclusive", () => {
expect(appSource).toContain('type MainContentSurface = "query" | "settings" | "driverStore" | "pluginCenter";');
expect(appSource).toMatch(/function activateMainContentSurface\(surface: MainContentSurface\) \{\s*settingsStore\.settingsPageActive = surface === "settings";\s*driverStoreActive\.value = surface === "driverStore";\s*pluginCenterActive\.value = surface === "pluginCenter";/);
expect(appSource).toMatch(/function activateSettingsPage\(\) \{\s*settingsPageTabOpen\.value = true;\s*activateMainContentSurface\("settings"\);/);
expect(appSource).toMatch(/function activateQuerySurface\(\) \{\s*activateMainContentSurface\("query"\);/);
expect(appSource).toMatch(/driverStoreTabOpen\.value = true;\s*activateMainContentSurface\("driverStore"\);/);
});
it("replays repeated navigation requests for the same tab", () => {
expect(appSource).toContain("settingsNavigationRequestId.value += 1");
expect(appSource).toContain(':navigation-request-id="settingsNavigationRequestId"');
expect(settingsDialogSource).toContain("navigationRequestId?: number;");
expect(settingsDialogSource).toMatch(/watch\(\s*\(\) => props\.navigationRequestId,/);
});
it("routes AI configuration drafts into the unsaved new-config form", () => {
const handlerStart = settingsDialogSource.indexOf("async function applyPendingAiConfigDeepLinkDraft()");
const handlerEnd = settingsDialogSource.indexOf("async function aiSaveConfig()", handlerStart);
const handlerSource = settingsDialogSource.slice(handlerStart, handlerEnd);
expect(appSource).toContain('openSettings("ai")');
expect(appSource).toContain(':ai-config-draft="settingsAiConfigDraft"');
expect(appSource).toContain(':ai-config-request-id="settingsAiConfigRequestId"');
expect(settingsDialogSource).toContain("aiEnterEditMode();");
expect(handlerSource).toContain("aiEditProviderPresetId.value = getAiProviderPresetId(draft.provider, draft.endpoint);");
expect(settingsDialogSource).toContain('aiEditApiKey.value = "";');
expect(settingsDialogSource).toContain("importClipboardApiKeyAfterConfirmation");
expect(handlerStart).toBeGreaterThanOrEqual(0);
expect(handlerEnd).toBeGreaterThan(handlerStart);
expect(handlerSource).not.toContain("aiSaveConfig(");
expect(handlerSource).not.toContain("aiTestConn(");
});
});
@@ -1,4 +1,3 @@
import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
import {
SETTINGS_SEARCH_DEFINITIONS,
@@ -13,8 +12,6 @@ import {
type SettingsSearchDefinition,
} from "@/lib/settings/settingsSearch";
const settingsDialogSource = readFileSync(new URL("../../../components/editor/EditorSettingsDialog.vue", import.meta.url), "utf8");
const categoryLabels = {
editor: "Editor",
formatter: "SQL Formatter",
@@ -94,9 +91,6 @@ describe("settings search", () => {
expect(withoutSqlServer.map((entry) => entry.id)).not.toContain("editor-sqlserver-space-completion");
expect(importedWithoutSqlServer.map((entry) => entry.id)).toContain("editor-sqlserver-space-completion");
expect(withSqlServer.map((entry) => entry.id)).toContain("editor-sqlserver-space-completion");
expect(settingsDialogSource).toContain('const hasSqlServerConnection = computed(() => connectionStore.connections.some((connection) => effectiveDatabaseTypeForConnection(connection) === "sqlserver"));');
expect(settingsDialogSource).toContain("const showSqlServerSpaceConfirmsCompletion = computed(");
expect(settingsDialogSource).toContain('<div v-if="showSqlServerSpaceConfirmsCompletion" class="settings-item flex items-center justify-between gap-4 rounded-md border bg-muted/20 px-3 py-2">');
});
it("does not index connection or query timeout under editor settings", () => {
@@ -112,8 +106,6 @@ describe("settings search", () => {
descriptionKey: "settings.multiStatementDefaultViewDescription",
targetId: "multi-statement-default-view",
});
expect(settingsDialogSource).toContain('data-settings-search-id="multi-statement-default-view"');
expect(settingsDialogSource).toContain('v-model="editMultiStatementDefaultView"');
});
it("places SQL file limits in their owning settings categories", () => {
@@ -138,17 +130,12 @@ describe("settings search", () => {
expect(desktopEntries.map((entry) => entry.id)).toContain("sql-file-editor-max-mb");
expect(desktopEntries.map((entry) => entry.id)).not.toContain("sql-file-web-upload-max-mb");
expect(webEntries.map((entry) => entry.id)).toEqual(expect.arrayContaining(["sql-file-editor-max-mb", "sql-file-web-upload-max-mb"]));
expect(settingsDialogSource).toContain('data-settings-search-id="editor-sql-file"');
expect(settingsDialogSource).toContain('data-settings-search-id="data-sql-file-upload"');
});
it("maps legacy SQL file settings navigation to the editor", () => {
expect(resolveSettingsCategory("sqlFile")).toBe("editor");
expect(resolveSettingsCategory()).toBe("appearance");
expect(resolveSettingsCategory("removed-category")).toBe("appearance");
expect(settingsDialogSource).not.toContain('value: "sqlFile"');
expect(settingsDialogSource).not.toContain("activeSettingsTab === 'sqlFile'");
expect(settingsDialogSource).toMatch(/if \(tab === "data" && isWeb\) void loadWebSqlFileUploadMaxMbSetting\(\)/);
});
it("matches translated title, description, and category without changing declared order", () => {
@@ -168,16 +155,6 @@ describe("settings search", () => {
const webEntries = resolveSettingsSearchEntries(SETTINGS_SEARCH_DEFINITIONS, { isWeb: true, visibleCategories: new Set<SettingsCategory>(["sync"]) }, translate, categoryLabels);
expect(webEntries.map((entry) => entry.id)).toEqual(["sync-webdav", "sync-webdav-endpoint", "sync-webdav-username", "sync-webdav-password", "sync-webdav-remote-path", "sync-webdav-auto-upload", "sync-secrets", "sync-secrets-passphrase"]);
expect(settingsDialogSource).toContain('{ value: "sync", label: t("settings.syncTab") }');
expect(settingsDialogSource).not.toContain('...(isWeb ? [] : [{ value: "sync"');
expect(settingsDialogSource).toContain('<TabsList v-if="!isWeb"');
});
it("defines the WebDAV Web-runtime notice in every supported locale", () => {
for (const locale of ["zh-CN", "zh-TW", "en", "es", "it", "ja", "ko", "pt-BR", "tr", "az"]) {
const source = readFileSync(new URL(`../../../i18n/locales/${locale}.ts`, import.meta.url), "utf8");
expect(source, locale).toContain("syncWebDavWebDescription:");
}
});
it("matches Chinese text as a Unicode substring", () => {
@@ -208,13 +185,6 @@ describe("settings search", () => {
expect(entry).toMatchObject({ targetId: "sync-snippet", route: { syncMethodTab: "snippet" } });
});
it("uses the open state for result visibility and applies nested routes before revealing targets", () => {
expect(settingsDialogSource).toContain("const settingsSearchVisible = computed(() => settingsSearchOpen.value && settingsSearchActive.value)");
expect(settingsDialogSource).toContain('v-if="settingsSearchVisible" id="settings-search-results"');
expect(settingsDialogSource).toMatch(/function applySettingsSearchRoute[\s\S]*?syncMethodTab\.value = result\.route\.syncMethodTab/);
expect(settingsDialogSource).toMatch(/async function selectSettingsSearchResult[\s\S]*?applySettingsSearchRoute\(result\)[\s\S]*?revealSettingsSearchTarget/);
});
it("derives one search result for every built-in shortcut", () => {
expect(
createShortcutSettingsSearchDefinitions([
@@ -285,30 +255,6 @@ describe("settings search", () => {
);
});
it("renders the metadata cache memory limit in a performance section after export", () => {
const exportSectionStart = settingsDialogSource.indexOf('t("settings.exportSection")');
const performanceSectionStart = settingsDialogSource.indexOf('data-settings-search-id="data-performance"');
const tableStructureSectionStart = settingsDialogSource.indexOf('t("settings.tableStructureSection")');
const metadataCacheControl = settingsDialogSource.indexOf('id="metadata-cache-memory-limit"');
expect(exportSectionStart).toBeGreaterThan(-1);
expect(performanceSectionStart).toBeGreaterThan(exportSectionStart);
expect(tableStructureSectionStart).toBeGreaterThan(performanceSectionStart);
expect(metadataCacheControl).toBeGreaterThan(performanceSectionStart);
expect(metadataCacheControl).toBeLessThan(tableStructureSectionStart);
});
it("defines the performance section title in every supported locale", () => {
for (const locale of ["zh-CN", "zh-TW", "en", "es", "it", "ja", "ko", "pt-BR", "tr", "az"]) {
const source = readFileSync(new URL(`../../../i18n/locales/${locale}.ts`, import.meta.url), "utf8");
expect(source, locale).toContain("performanceSection:");
}
});
it("activates result buttons through click for keyboard and assistive technology", () => {
expect(settingsDialogSource).toMatch(/role="option"[\s\S]*?@mousedown\.prevent[\s\S]*?@click="void selectSettingsSearchResult\(result\)"/);
});
it("registers every fixed settings control that needs a dedicated search result", () => {
const expectedControls: ReadonlyArray<Pick<SettingsSearchDefinition, "titleKey" | "category" | "targetId">> = [
{ titleKey: "settings.savedSqlOpenTarget", category: "editor", targetId: "editor" },