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.1 KB
Raw Blame
import { strict as assert } from "node:assert";
import { test } from "vitest";
import { pruneTreeSelectionToVisibleNodes, selectedTreeNodesInVisibleOrder, treeSelectionRangeIdsByIndex, treeSelectionRangeIds } from "../../apps/desktop/src/lib/sidebar/sidebarTreeSelection.ts";
import type { TreeNode } from "../../apps/desktop/src/types/database.ts";

const nodes: TreeNode[] = [
  { id: "orders", label: "orders", type: "table" },
  { id: "order_lines", label: "order_lines", type: "table" },
  { id: "products", label: "products", type: "table" },
  { id: "customers", label: "customers", type: "table" },
];

test("tree range selection uses the current visible node order", () => {
  const filtered = [nodes[0], nodes[1], nodes[3]];

  assert.deepEqual(treeSelectionRangeIds(filtered, "customers", "orders"), ["orders", "order_lines", "customers"]);
});

test("tree range selection falls back to the current node when the anchor is filtered out", () => {
  const filtered = [nodes[1], nodes[3]];

  assert.deepEqual(treeSelectionRangeIds(filtered, "customers", "orders"), ["customers"]);
});

test("tree range selection can reuse precomputed visible indexes", () => {
  const filtered = [nodes[0], nodes[1], nodes[3]];

  assert.deepEqual(treeSelectionRangeIdsByIndex(filtered, 2, 0, "customers"), ["orders", "order_lines", "customers"]);
});

test("selected tree nodes are ordered and limited by visible nodes", () => {
  const filtered = [nodes[1], nodes[3]];

  assert.deepEqual(
    selectedTreeNodesInVisibleOrder(filtered, ["products", "customers", "order_lines"]).map((node) => node.id),
    ["order_lines", "customers"],
  );
});

test("hidden selections are removed before a filtered tree becomes visible again", () => {
  const filtered = [nodes[1]];
  const selection = pruneTreeSelectionToVisibleNodes(filtered, {
    nodeIds: ["order_lines", "products"],
    activeNodeId: "products",
    anchorNodeId: "products",
  });

  assert.deepEqual(selection, {
    nodeIds: ["order_lines"],
    activeNodeId: "order_lines",
    anchorNodeId: "order_lines",
  });
  assert.deepEqual(selectedTreeNodesInVisibleOrder(nodes, selection.nodeIds).map((node) => node.id), ["order_lines"]);
});