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.3 KB
Raw Blame
import { describe, expect, it } from "vitest";
import { savedSqlFolderBranchFileCount, type SavedSqlFolderCountNode } from "@/lib/savedSql/savedSqlFolderCounts";

describe("savedSqlFolderBranchFileCount", () => {
  const folders: SavedSqlFolderCountNode[] = [{ id: "root" }, { id: "child", parentFolderId: "root" }, { id: "grandchild", parentFolderId: "child" }, { id: "sibling", parentFolderId: "root" }, { id: "other" }];
  const filesByFolder = new Map<string, unknown[]>([
    ["root", ["root.sql"]],
    ["child", []],
    ["grandchild", ["nested.sql", "report.sql"]],
    ["sibling", ["side.sql"]],
    ["other", ["other.sql"]],
  ]);

  it("counts files in descendant folders", () => {
    const count = savedSqlFolderBranchFileCount("root", folders, (folderId) => filesByFolder.get(folderId) ?? []);

    expect(count).toBe(4);
  });

  it("does not count files outside the folder branch", () => {
    const count = savedSqlFolderBranchFileCount("child", folders, (folderId) => filesByFolder.get(folderId) ?? []);

    expect(count).toBe(2);
  });

  it("does not loop on cyclic folder data", () => {
    const cyclicFolders: SavedSqlFolderCountNode[] = [
      { id: "a", parentFolderId: "b" },
      { id: "b", parentFolderId: "a" },
    ];

    const count = savedSqlFolderBranchFileCount("a", cyclicFolders, () => ["file.sql"]);

    expect(count).toBe(2);
  });
});