Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

2.6 KB
Raw Blame
import { readFileSync } from "node:fs";
import { parse } from "vue/compiler-sfc";
import ts from "typescript";
import { describe, expect, it } from "vitest";
import { gbaseProfileFromConfig } from "@/lib/connection/gbaseProfiles";

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;
  // The merged dialog checks plugin providers before the profile table; the
  // plugin branch is stubbed out so this harness pins the GBase profile path.
  const selectedProfile = new Function("driverProfiles", "selectedType", "form", "parsePluginConnectionProviderOptionValue", "selectedPluginProvider", "gbaseProfileFromConfig", `${javascript}\nreturn selectedProfile;`)(
    {
      mysql: { label: "MySQL" },
      gbase: { label: "南大通用 GBase 8a" },
      gbase8a: { label: "南大通用 GBase 8a" },
      gbase8s: { label: "南大通用 GBase 8s" },
      gbase8c: { label: "南大通用 GBase 8c" },
    },
    { value: selectedTypeValue },
    { value: { db_type: driverProfile === "gbase8c" ? "gbase8c" : driverProfile === "gbase8s" ? "gbase8s" : "gbase", driver_profile: driverProfile } },
    () => null,
    { value: null },
    gbaseProfileFromConfig,
  ) as () => { label: string };
  return selectedProfile();
}

describe("GBase 8s connection dialog", () => {
  it.each([
    ["gbase8a", "南大通用 GBase 8a"],
    ["gbase8s", "南大通用 GBase 8s"],
    ["gbase8c", "南大通用 GBase 8c"],
  ])("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");
  });
});