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。

5.2 KB
Raw Blame
import { strict as assert } from "node:assert";
import { readFileSync } from "node:fs";
import { test } from "vitest";

const app = readFileSync("apps/desktop/src/App.vue", "utf8");
const dangerHost = readFileSync("apps/desktop/src/components/sidebar/SidebarDangerDialogHost.vue", "utf8");
const connectionTree = readFileSync("apps/desktop/src/components/sidebar/ConnectionTree.vue", "utf8");
const treeItem = readFileSync("apps/desktop/src/components/sidebar/TreeItem.vue", "utf8");
const runtimeHost = readFileSync("apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue", "utf8");
const dialogHost = readFileSync("apps/desktop/src/components/sidebar/SidebarTreeItemDialogs.vue", "utf8");
const objectBrowser = readFileSync("apps/desktop/src/components/objects/ObjectBrowser.vue", "utf8");
const dialogState = readFileSync("apps/desktop/src/components/sidebar/sidebarTreeDialogState.ts", "utf8");
const visibleDatabasesDialog = readFileSync("apps/desktop/src/components/sidebar/VisibleDatabasesDialog.vue", "utf8");
const visibleSchemasDialog = readFileSync("apps/desktop/src/components/sidebar/VisibleSchemasDialog.vue", "utf8");

function occurrences(source: string, value: string): number {
  return source.split(value).length - 1;
}

test("sidebar routes destructive confirmations through one application-level host", () => {
  assert.match(runtimeHost, /emit\("open-danger-dialog", route\.createRequest\(\)\)/);
  assert.match(dangerHost, /function showSidebarDangerDialog\(request: SidebarDangerDialogRequest\)/);
  assert.match(connectionTree, /@open-danger-dialog="openSidebarDangerDialog"/);
  assert.equal(occurrences(app, "<SidebarDangerDialogHost"), 1);
  assert.equal(occurrences(dangerHost, "<SidebarDangerConfirmDialog"), 1);
  assert.doesNotMatch(treeItem, /<DangerConfirmDialog/);
});

test("application-level danger routing preserves cancel and close-on-confirm behavior", () => {
  assert.match(dangerHost, /v-model:open="sidebarDangerDialogOpen"/);
  assert.match(dangerHost, /if \(request\.closeOnConfirm !== false\) sidebarDangerDialogOpen\.value = false/);
  assert.match(dangerHost, /await request\.confirm\(\)/);
  assert.match(dangerHost, /sidebarDangerDialogOpen\.value = false/);
  assert.match(dangerHost, /sidebarDangerDialogConfirming\.value = false/);
});

test("remaining form dialogs render once at tree level and keep confirm/cancel bindings", () => {
  assert.equal(occurrences(connectionTree, "<SidebarTreeItemDialogs"), 1);
  assert.doesNotMatch(treeItem, /<Dialog(?:\s|>)/);
  assert.doesNotMatch(treeItem, /<InstallExtensionDialog/);
  assert.match(dialogHost, /<p class="min-w-0 break-words text-sm text-muted-foreground \[overflow-wrap:anywhere\]">\s*\{\{ connectionDeleteConfirmMessage\(\) \}\}/);
  assert.match(dialogHost, /v-model:open="showCreateDatabaseDialog"/);
  assert.match(dialogHost, /@click="showCreateDatabaseDialog = false"/);
  assert.match(dialogHost, /@click="confirmCreateDatabase"/);
  assert.match(dialogHost, /v-model:open="showPasteDialog"/);
  assert.match(dialogHost, /@click="confirmPasteTable"/);
});

test("rename dialogs preserve their layout while scrolling unbounded identifiers", () => {
  const previewClass = "max-h-32 min-w-0 max-w-full overflow-auto rounded bg-muted p-3 text-xs whitespace-pre-wrap";
  const errorClass = "min-w-0 max-w-full overflow-x-auto text-sm text-destructive";

  assert.equal(occurrences(dialogHost, previewClass), 2);
  assert.equal(occurrences(dialogHost, errorClass), 2);
  assert.ok(objectBrowser.includes(previewClass));
  assert.ok(objectBrowser.includes(errorClass));
});

test("dialog controller routing preserves shared open-flag refs instead of spreading them", () => {
  assert.match(runtimeHost, /createRoutedSidebarDialogController\(/);
  assert.doesNotMatch(runtimeHost, /reactive<Record<string, any>>\(\{ \.\.\.controller/);
});

test("saved object dialogs refresh the immutable active target", () => {
  assert.match(connectionTree, /<SidebarObjectSourceDialog[\s\S]*?@saved="refreshSidebarActionTarget"/);
  assert.match(connectionTree, /<InstallExtensionDialog[\s\S]*?@close="refreshSidebarActionTarget"/);
  assert.match(connectionTree, /findSidebarActionTarget\(store\.treeNodes, target\)/);
});

test("lazy visible object dialogs load when first mounted open", () => {
  assert.match(visibleDatabasesDialog, /watch\([\s\S]*?loadDatabases\(\)[\s\S]*?\{ immediate: true \}/);
  assert.match(visibleSchemasDialog, /watch\([\s\S]*?loadSchemas\(\)[\s\S]*?\{ immediate: true \}/);
});

test("shared dialog state is owner-gated and confirm handlers use snapshots", () => {
  assert.match(dialogState, /export const sidebarTreeDialogOwner = shallowRef<symbol \| null>\(null\)/);
  assert.match(dialogState, /export const sidebarDangerTarget = shallowRef<TreeNode \| null>\(null\)/);
  assert.match(dialogState, /export const sidebarFormTarget = shallowRef<TreeNode \| null>\(null\)/);
  assert.match(runtimeHost, /sidebarTreeDialogOwner\.value !== treeItemDialogOwner/);
  assert.match(runtimeHost, /const node = sidebarDangerTarget\.value \?\? activeNode\.value/);
  assert.match(runtimeHost, /const node = sidebarFormTarget\.value \?\? activeNode\.value/);
  assert.match(runtimeHost, /batchTruncateTargets\.value = targets\.slice\(\)/);
  assert.match(runtimeHost, /activateActionTarget\(target\)/);
});