Files
WRNexusJS/packages/dnd/test/reorder.test.ts
T
Clintchiz 0bd2a6860d
Quality / quality (ubuntu-latest) (push) Failing after 11m26s
Quality / quality (windows-latest) (push) Canceled after 0s
feat(builder): add dynamic blocks email and dnd packages
2026-09-03 14:00:41 +05:30

32 lines
1011 B
TypeScript

import { describe, expect, test } from "bun:test";
import { deepestValidTarget, reorderGroups, visualIndex } from "../src/index.ts";
describe("dnd pure behavior", () => {
test("moves across groups without mutation", () => {
const input = new Map([
["a", ["1", "2"]],
["b", ["3"]],
]);
const result = reorderGroups(input, {
ids: ["2"],
from: [{ group: "a", index: 1 }],
to: { group: "b", index: 0 },
});
expect(result.get("a")).toEqual(["1"]);
expect(result.get("b")).toEqual(["2", "3"]);
expect(input.get("a")).toEqual(["1", "2"]);
});
test("mirrors horizontal RTL index", () =>
expect(visualIndex(0, 4, "horizontal", "rtl")).toBe(3));
test("selects deepest valid target", () =>
expect(
deepestValidTarget(
[
{ depth: 1, location: { group: "a", index: 0 } },
{ depth: 3, location: { group: "b", index: 0 } },
],
(location) => location.group === "b",
)?.depth,
).toBe(3));
});