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。

3.2 KB
Raw Blame
// @vitest-environment happy-dom

import { createApp, nextTick } from "vue";
import { afterEach, describe, expect, it } from "vitest";
import DatabaseIcon from "./DatabaseIcon.vue";

describe("DatabaseIcon", () => {
  afterEach(() => {
    document.body.innerHTML = "";
  });

  it("uses the OceanBase asset for Oracle mode", async () => {
    const container = document.createElement("div");
    document.body.appendChild(container);
    const app = createApp(DatabaseIcon, { dbType: "oceanbase-oracle" });
    app.mount(container);
    await nextTick();

    expect(container.querySelector("img")?.getAttribute("src")).toBe("/icons/database/oceanbase.svg");
    app.unmount();
  });

  it("uses the Apache Phoenix asset for the Phoenix JDBC profile", async () => {
    const container = document.createElement("div");
    document.body.appendChild(container);
    const app = createApp(DatabaseIcon, { dbType: "phoenix" });
    app.mount(container);
    await nextTick();

    expect(container.querySelector("img")?.getAttribute("src")).toBe("/icons/database/phoenix.svg");
    app.unmount();
  });

  it("uses the Apache Impala asset instead of the Hive asset", async () => {
    const container = document.createElement("div");
    document.body.appendChild(container);
    const app = createApp(DatabaseIcon, { dbType: "impala" });
    app.mount(container);
    await nextTick();

    const icon = container.querySelector("img");
    expect(icon?.getAttribute("src")).toBe("/icons/database/impala.svg");
    expect(icon?.classList.contains("database-logo-impala")).toBe(true);
    app.unmount();
  });

  it("uses the Apache Kyuubi asset instead of the Hive asset", async () => {
    const container = document.createElement("div");
    document.body.appendChild(container);
    const app = createApp(DatabaseIcon, { dbType: "kyuubi" });
    app.mount(container);
    await nextTick();

    expect(container.querySelector("img")?.getAttribute("src")).toBe("/icons/database/kyuubi.png");
    app.unmount();
  });

  it.each(["transwarp", "transwarp-inceptor"])("uses the Inceptor asset for %s", async (dbType) => {
    const container = document.createElement("div");
    document.body.appendChild(container);
    const app = createApp(DatabaseIcon, { dbType });
    app.mount(container);
    await nextTick();

    expect(container.querySelector("img")?.getAttribute("src")).toBe("/icons/database/transwarp-inceptor.png");
    app.unmount();
  });

  it("uses the Meilisearch asset", async () => {
    const container = document.createElement("div");
    document.body.appendChild(container);
    const app = createApp(DatabaseIcon, { dbType: "meilisearch" });
    app.mount(container);
    await nextTick();

    expect(container.querySelector("img")?.getAttribute("src")).toBe("/icons/database/meilisearch.svg");
    app.unmount();
  });

  it("falls back to the generic icon when the database type is missing", async () => {
    const container = document.createElement("div");
    document.body.appendChild(container);
    const app = createApp(DatabaseIcon);
    app.mount(container);
    await nextTick();

    expect(container.querySelector("img")).toBeNull();
    expect(container.querySelector("svg")).not.toBeNull();
    app.unmount();
  });
});