4-26 树rust-2

This commit is contained in:
lix-2026
2026-04-26 04:29:23 +08:00
parent 94631f3636
commit 338bb2e20f
58 changed files with 11718 additions and 1256 deletions
@@ -0,0 +1,29 @@
import { describe, expect, it } from "vitest";
import { buildParentById, isAncestorOf } from "../../../convex/_utils/documentTree";
describe("document tree helper", () => {
it("构建父链映射时保留页面与父页面关系,供树命令 legality 复用", () => {
const parentById = buildParentById([
{ id: "root", parent_id: null },
{ id: "child", parent_id: "root" },
{ id: "leaf", parent_id: "child" },
]);
expect(parentById.get("root")).toBeNull();
expect(parentById.get("child")).toBe("root");
expect(parentById.get("leaf")).toBe("child");
});
it("祖先判断应能识别多级后代,避免把页面移动到自己的子树下面", () => {
const parentById = buildParentById([
{ id: "root", parent_id: null },
{ id: "child", parent_id: "root" },
{ id: "leaf", parent_id: "child" },
]);
expect(isAncestorOf("root", "leaf", parentById)).toBe(true);
expect(isAncestorOf("child", "leaf", parentById)).toBe(true);
expect(isAncestorOf("leaf", "root", parentById)).toBe(false);
expect(isAncestorOf("missing", "leaf", parentById)).toBe(false);
});
});