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。

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

import { createApp, defineComponent, h, nextTick, reactive, type App } from "vue";
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
import i18n from "@/i18n";

const store = reactive({
  connections: [],
  mongoImportSource: null as { connectionId: string; database: string; collection: string } | null,
  transferSource: null,
  schemaDiffSource: null,
  dataCompareSource: null,
  sqlFileSource: null,
  diagramSource: null,
  docsSource: null,
  tableImportSource: null,
  tableDataGenerateSource: null,
  fieldLineageSource: null,
  databaseSearchSource: null,
  databaseExportSource: null,
});

vi.mock("@/stores/connectionStore", () => ({ useConnectionStore: () => store }));
vi.mock("@/composables/useToast", () => ({ useToast: () => ({ toast: vi.fn() }) }));

import { useDialogSources } from "@/composables/useDialogSources";

const mountedApps: App[] = [];
let dialogs: ReturnType<typeof useDialogSources>;

async function mountDialogs() {
  const container = document.createElement("div");
  document.body.append(container);
  const app = createApp(
    defineComponent({
      setup() {
        dialogs = useDialogSources();
        return () => h("div");
      },
    }),
  );
  mountedApps.push(app);
  app.use(i18n);
  app.mount(container);
  await nextTick();
}

describe("useDialogSources mongo import/export", () => {
  beforeAll(async () => {
    await mountDialogs();
  });

  afterAll(() => {
    for (const app of mountedApps.splice(0)) app.unmount();
  });

  it("opens the mongo import dialog from a collection source", async () => {
    store.mongoImportSource = { connectionId: "c1", database: "shop", collection: "orders" };
    await nextTick();
    expect(dialogs.showMongoImportDialog.value).toBe(true);
    expect(dialogs.mongoImportPrefillCollection.value).toBe("orders");
    expect(store.mongoImportSource).toBeNull();
  });
});