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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
import { describe, expect, it } from "vitest";
import type { TreeNode } from "@/types/database";
import { createSidebarActionRequest, createSidebarActionTarget, findSidebarActionTarget, matchesSidebarActionTarget, releaseRemovedSidebarActionTarget } from "@/lib/sidebar/sidebarActionTarget";
function tableNode(): TreeNode {
return {
id: "table-1",
label: "users",
type: "table",
connectionId: "connection-1",
database: "app",
schema: "public",
children: [{ id: "column-1", label: "id", type: "column" }],
};
}
describe("sidebar action targets", () => {
it("captures a frozen shallow snapshot without retaining children", () => {
const node = tableNode();
const target = createSidebarActionTarget(node);
node.label = "recycled-row";
node.connectionId = "connection-2";
expect(target).toMatchObject({ label: "users", connectionId: "connection-1", children: undefined, hiddenChildren: undefined });
expect(Object.isFrozen(target)).toBe(true);
});
it("captures selection independently from later selection changes", () => {
const selectedNodeIds = ["table-1", "table-2"];
const request = createSidebarActionRequest(tableNode(), selectedNodeIds, { initialEditing: true });
selectedNodeIds.splice(0, selectedNodeIds.length, "table-3");
expect(request.selectedNodeIds).toEqual(["table-1", "table-2"]);
expect(request.payload).toEqual({ initialEditing: true });
expect(Object.isFrozen(request.selectedNodeIds)).toBe(true);
expect(Object.isFrozen(request)).toBe(true);
});
it("matches a live node with the same action target identity", () => {
const node = tableNode();
expect(matchesSidebarActionTarget(node, createSidebarActionTarget(node))).toBe(true);
});
it("does not match the same id after identity fields change", () => {
const target = createSidebarActionTarget(tableNode());
const changedNode = { ...tableNode(), connectionId: "connection-2", label: "accounts" };
expect(matchesSidebarActionTarget(changedNode, target)).toBe(false);
});
it("does not resolve a recycled row with the same local id", () => {
const target = createSidebarActionTarget(tableNode());
const recycled = tableNode();
recycled.connectionId = "connection-2";
expect(findSidebarActionTarget([recycled], target)).toBeNull();
});
it("returns null when the action target was removed", () => {
const target = createSidebarActionTarget(tableNode());
expect(findSidebarActionTarget([], target)).toBeNull();
});
it("releases a removed active node's child tree", () => {
const node = tableNode();
const released = releaseRemovedSidebarActionTarget(node, [node.id]);
expect(released).not.toBe(node);
expect(released.children).toBeUndefined();
expect(released.hiddenChildren).toBeUndefined();
});
it("keeps an active node that was not removed", () => {
const node = tableNode();
expect(releaseRemovedSidebarActionTarget(node, ["other-node"])).toBe(node);
});
it("resolves targets stored only in hidden children", () => {
const node = tableNode();
const target = createSidebarActionTarget(node);
const root: TreeNode = { id: "root", label: "root", type: "database", hiddenChildren: [node] };
expect(findSidebarActionTarget([root], target)).toBe(node);
});
});