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
import { expect, test } from "vitest";
import { calculateDataGridColumnWidth, DATA_GRID_AUTO_FIT_VALUE_TEXT_LIMIT, DATA_GRID_COL_AUTO_FIT_MAX_WIDTH, DATA_GRID_COL_MAX_WIDTH, DATA_GRID_HEADER_MAX_WIDTH } from "../../apps/desktop/src/lib/dataGrid/dataGridColumnWidth.ts";

test("default data grid column width remains compact for long values", () => {
  const width = calculateDataGridColumnWidth({
    columnName: "description",
    sampleValues: ["x".repeat(120)],
  });

  // standard: valueTextLimit=40, so 120 chars truncated to 40 → 40×8+24+12=356
  expect(width).toBe(356);
});

test("auto-fit data grid column width expands long values beyond default width", () => {
  const width = calculateDataGridColumnWidth({
    columnName: "description",
    sampleValues: ["x".repeat(120)],
    maxWidth: DATA_GRID_COL_AUTO_FIT_MAX_WIDTH,
    valueTextLimit: DATA_GRID_AUTO_FIT_VALUE_TEXT_LIMIT,
  });

  expect(width).toBeGreaterThan(356);
});

test("auto-fit data grid column width stays bounded for very long values", () => {
  const width = calculateDataGridColumnWidth({
    columnName: "description",
    sampleValues: ["x".repeat(1000)],
    maxWidth: DATA_GRID_COL_AUTO_FIT_MAX_WIDTH,
    valueTextLimit: DATA_GRID_AUTO_FIT_VALUE_TEXT_LIMIT,
  });

  expect(width).toBe(DATA_GRID_COL_AUTO_FIT_MAX_WIDTH);
});

test("data grid column width uses measured header text as the normal minimum", () => {
  const width = calculateDataGridColumnWidth({
    columnName: "AMOUNT",
    sampleValues: ["1"],
    density: "comfortable",
    compactColumnHeaderActions: true,
    headerTextWidth: 54,
  });

  expect(width).toBe(113);
});

test("data grid caps pathological field names independently of density", () => {
  const width = calculateDataGridColumnWidth({
    columnName: "x".repeat(100),
    sampleValues: ["1"],
    density: "compact",
    compactColumnHeaderActions: true,
    headerTextWidth: 700,
  });

  expect(width).toBe(DATA_GRID_HEADER_MAX_WIDTH);
});