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.8 KB
Raw Blame
// @vitest-environment happy-dom

import { createApp, type App } from "vue";
import { afterEach, describe, expect, it } from "vitest";
import i18n from "@/i18n";
import RoutineMetadataPanel from "@/components/objects/RoutineMetadataPanel.vue";

const mountedApps: Array<{ app: App; host: HTMLElement }> = [];

afterEach(() => {
  for (const { app, host } of mountedApps.splice(0)) {
    app.unmount();
    host.remove();
  }
});

describe("RoutineMetadataPanel", () => {
  it("renders parameter modes, defaults, and a function return type", () => {
    const host = document.createElement("div");
    document.body.append(host);
    const app = createApp(RoutineMetadataPanel, {
      returnType: "NUMERIC(12,3)",
      parameters: [
        { name: "p_amount", dataType: "NUMERIC(10,2)", mode: "IN", ordinal: 1, hasDefault: false },
        { name: "p_rate", dataType: "NUMERIC(5,2)", mode: "INOUT", ordinal: 2, hasDefault: true, defaultValue: "0.10" },
        { name: "p_status", dataType: "VARCHAR(20)", mode: "OUT", ordinal: 3, hasDefault: false },
      ],
    });
    app.use(i18n);
    app.mount(host);
    mountedApps.push({ app, host });

    expect(host.querySelector("[data-routine-return-type]")?.textContent).toContain("NUMERIC(12,3)");
    const rows = [...host.querySelectorAll("[data-routine-parameter]")];
    expect(rows).toHaveLength(3);
    expect(rows[0].textContent).toContain("p_amount");
    expect(rows[1].textContent).toContain("INOUT");
    expect(rows[1].textContent).toContain("0.10");
    expect(rows[2].textContent).toContain("OUT");
  });

  it("shows return metadata without rendering an empty parameter table", () => {
    const host = document.createElement("div");
    document.body.append(host);
    const app = createApp(RoutineMetadataPanel, { returnType: "INTEGER", parameters: [] });
    app.use(i18n);
    app.mount(host);
    mountedApps.push({ app, host });

    expect(host.querySelector("[data-routine-return-type]")?.textContent).toContain("INTEGER");
    expect(host.querySelectorAll("[data-routine-parameter]")).toHaveLength(0);
  });

  it("renders known JDBC nullability without changing legacy parameter rows", () => {
    const host = document.createElement("div");
    document.body.append(host);
    const app = createApp(RoutineMetadataPanel, {
      parameters: [
        { name: "required_id", dataType: "BIGINT", mode: "IN", ordinal: 1, nullable: false },
        { name: "optional_note", dataType: "VARCHAR(64)", mode: "OUT", ordinal: 2, nullable: true },
        { name: "unknown", dataType: "OTHER", mode: "UNKNOWN", ordinal: 3, nullable: null },
      ],
    });
    app.use(i18n);
    app.mount(host);
    mountedApps.push({ app, host });

    const nullability = [...host.querySelectorAll("[data-routine-nullable]")].map((cell) => cell.textContent?.trim());
    expect(nullability).toEqual(["Not null", "Nullable", "-"]);
  });
});