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.7 KB
Raw Blame
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { test } from "vitest";
import { createDataGridCellContextMenuItems } from "../../apps/desktop/src/lib/dataGrid/dataGridContextMenu";

const dataGridPath = "apps/desktop/src/components/grid/DataGrid.vue";
const dataGridSource = readFileSync(dataGridPath, "utf8");

test("set NULL applies a real null value only to editable selections", () => {
  const handler = dataGridSource.match(/function setSelectionNull\(\) \{[^]*?\n\}/)?.[0] ?? "";

  assert.match(dataGridSource, /const resolvedConnectionConfig = computed\(\(\) => connectionStore\.getConfig\(props\.connectionId \?\? ""\)\);/);
  assert.match(dataGridSource, /const compatibilityReadOnly = computed\(\(\) => mysqlDataCharsetEnabled\(resolvedConnectionConfig\.value\)\);/);
  assert.match(dataGridSource, /const effectiveEditable = computed\(\(\) => !!props\.editable && !compatibilityReadOnly\.value\);/);
  assert.match(handler, /if \(!effectiveEditable\.value \|\| !selectionHasEditableCells\(\)\) return;/);
  assert.match(handler, /fillSelectionWithValue\(null\);/);
  assert.doesNotMatch(handler, /fillSelectionWithValue\(["'](?:NULL)?["']\)/);
});

test("hide identical columns compares full-width rows, not visibility-projected ones", () => {
  const fn = dataGridSource.match(/function getComparisonRows\(\)[^{]*\{[^]*?\n\}/)?.[0] ?? "";
  assert.ok(fn, "getComparisonRows not found");
  assert.match(fn, /\bdisplayItems\.value/);
  assert.doesNotMatch(fn, /visibleDisplayItems/);
});

test("editable cell selections expose generation after bulk edit", () => {
  const icon = {};
  const action = () => {};
  const items = createDataGridCellContextMenuItems({
    hasCell: false,
    hasColumn: false,
    headerColumn: false,
    editable: true,
    hasCellSelection: true,
    hasEditableSelection: false,
    hasSelection: false,
    labels: { cellDetails: "cell", columnDetails: "column", rowDetails: "row", setNull: "set null", bulkEdit: "bulk edit", transpose: "transpose" },
    icons: { cellDetails: icon, columnDetails: icon, rowDetails: icon, setNull: icon, bulkEdit: icon, transpose: icon },
    actions: { cellDetails: action, columnDetails: action, rowDetails: action, setNull: action, bulkEdit: action, transpose: action },
    copySubmenu: { label: "copy" },
    selectionSubmenu: { label: "selection" },
    generateSubmenu: { label: "generate", disabled: true },
  });

  assert.deepEqual(
    items.map((item) => ({ label: item.label, disabled: item.disabled })),
    [
      { label: "copy", disabled: undefined },
      { label: "set null", disabled: true },
      { label: "bulk edit", disabled: true },
      { label: "generate", disabled: true },
    ],
  );
});