From 3858cf1e59830836eedc0c774a7b025ed7013647 Mon Sep 17 00:00:00 2001 From: zipg Date: Sat, 22 Aug 2026 12:57:55 +0800 Subject: [PATCH] fix(gbase): sync type label after version switch --- .../connection/ConnectionDialog.vue | 3 +- .../gbase8sConnectionDialog.spec.ts | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/apps/desktop/src/components/connection/ConnectionDialog.vue b/apps/desktop/src/components/connection/ConnectionDialog.vue index 63736f324f..adaec26922 100644 --- a/apps/desktop/src/components/connection/ConnectionDialog.vue +++ b/apps/desktop/src/components/connection/ConnectionDialog.vue @@ -1331,7 +1331,8 @@ function profileForConfig(config: ConnectionConfig) { } function selectedProfile() { - return driverProfiles[selectedType.value] ?? driverProfiles.mysql; + const profile = selectedType.value === "gbase" && (form.value.driver_profile === "gbase8a" || form.value.driver_profile === "gbase8s") ? form.value.driver_profile : selectedType.value; + return driverProfiles[profile] ?? driverProfiles.mysql; } function mqExtraRecord(config?: Partial): Record { diff --git a/apps/desktop/src/lib/__tests__/connection/gbase8sConnectionDialog.spec.ts b/apps/desktop/src/lib/__tests__/connection/gbase8sConnectionDialog.spec.ts index 6e13849d7d..8ebec16ad0 100644 --- a/apps/desktop/src/lib/__tests__/connection/gbase8sConnectionDialog.spec.ts +++ b/apps/desktop/src/lib/__tests__/connection/gbase8sConnectionDialog.spec.ts @@ -1,10 +1,47 @@ import { readFileSync } from "node:fs"; +import { parse } from "vue/compiler-sfc"; +import ts from "typescript"; import { describe, expect, it } from "vitest"; const dialogSource = readFileSync(new URL("../../../components/connection/ConnectionDialog.vue", import.meta.url), "utf8"); +const parsedDialog = parse(dialogSource, { filename: "ConnectionDialog.vue" }); + +function selectedProfileHarness(selectedTypeValue: string, driverProfile: string) { + const script = parsedDialog.descriptor.scriptSetup; + expect(parsedDialog.errors).toEqual([]); + expect(script).toBeDefined(); + const source = ts.createSourceFile("ConnectionDialog.vue.ts", script!.content, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS); + const declaration = source.statements.find((statement): statement is ts.FunctionDeclaration => ts.isFunctionDeclaration(statement) && statement.name?.text === "selectedProfile"); + expect(declaration).toBeDefined(); + const javascript = ts.transpileModule(declaration!.getText(), { + compilerOptions: { module: ts.ModuleKind.None, target: ts.ScriptTarget.ES2022 }, + }).outputText; + const selectedProfile = new Function("driverProfiles", "selectedType", "form", `${javascript}\nreturn selectedProfile;`)( + { + mysql: { label: "MySQL" }, + gbase: { label: "南大通用 GBase 8a" }, + gbase8a: { label: "南大通用 GBase 8a" }, + gbase8s: { label: "南大通用 GBase 8s" }, + }, + { value: selectedTypeValue }, + { value: { driver_profile: driverProfile } }, + ) as () => { label: string }; + return selectedProfile(); +} describe("GBase 8s connection dialog", () => { it("hydrates DBSERVERNAME when editing a saved connection", () => { expect(dialogSource).toContain('gbase_server: config.gbase_server || ""'); }); + + it.each([ + ["gbase8a", "南大通用 GBase 8a"], + ["gbase8s", "南大通用 GBase 8s"], + ])("shows the active %s profile in the merged GBase type field", (profile, label) => { + expect(selectedProfileHarness("gbase", profile).label).toBe(label); + }); + + it("keeps non-GBase type labels based on the selected picker type", () => { + expect(selectedProfileHarness("mysql", "gbase8s").label).toBe("MySQL"); + }); });