Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113import { describe, expect, it } from "vite-plus/test";
import type { Node } from "@/features/learner-map/lib/comparator";
import { getLayoutedElements } from "./layout";
describe("getLayoutedElements", () => { it("should layout nodes in left-to-right direction", () => { const nodes: Node[] = [ { id: "1", type: "text", position: { x: 0, y: 0 }, data: { label: "A" } }, { id: "2", type: "text", position: { x: 0, y: 0 }, data: { label: "B" } }, ]; const edges = [{ id: "e1", source: "1", target: "2" }];
const result = getLayoutedElements(nodes, edges, "LR");
expect(result.nodes).toHaveLength(2); expect(result.nodes[0].position!.x).toBeLessThan(result.nodes[1].position!.x); });
it("should layout nodes in top-to-bottom direction", () => { const nodes: Node[] = [ { id: "1", type: "text", position: { x: 0, y: 0 }, data: { label: "A" } }, { id: "2", type: "text", position: { x: 0, y: 0 }, data: { label: "B" } }, ]; const edges = [{ id: "e1", source: "1", target: "2" }];
const result = getLayoutedElements(nodes, edges, "TB");
expect(result.nodes).toHaveLength(2); expect(result.nodes[0].position!.y).toBeLessThan(result.nodes[1].position!.y); });
it("should handle multiple connected nodes", () => { const nodes: Node[] = [ { id: "1", type: "text", position: { x: 0, y: 0 }, data: { label: "A" } }, { id: "2", type: "text", position: { x: 0, y: 0 }, data: { label: "B" } }, { id: "3", type: "text", position: { x: 0, y: 0 }, data: { label: "C" } }, ]; const edges = [ { id: "e1", source: "1", target: "2" }, { id: "e2", source: "2", target: "3" }, ];
const result = getLayoutedElements(nodes, edges, "LR");
expect(result.nodes).toHaveLength(3); expect(result.edges).toHaveLength(2); });
it("should preserve node data", () => { const nodes: Node[] = [ { id: "1", type: "text", position: { x: 0, y: 0 }, data: { label: "Test" }, }, ]; const edges: Array<{ id: string; source: string; target: string }> = [];
const result = getLayoutedElements(nodes, edges, "LR");
expect(result.nodes[0].data.label).toBe("Test"); });
it("should handle empty nodes", () => { const result = getLayoutedElements([], [], "LR");
expect(result.nodes).toHaveLength(0); expect(result.edges).toHaveLength(0); });
it("should handle disconnected nodes", () => { const nodes: Node[] = [ { id: "1", type: "text", position: { x: 0, y: 0 }, data: { label: "A" } }, { id: "2", type: "text", position: { x: 0, y: 0 }, data: { label: "B" } }, ]; const edges: Array<{ id: string; source: string; target: string }> = [];
const result = getLayoutedElements(nodes, edges, "LR");
expect(result.nodes).toHaveLength(2); expect(result.edges).toHaveLength(0); });
it("should use default LR direction when not specified", () => { const nodes: Node[] = [ { id: "1", type: "text", position: { x: 0, y: 0 }, data: { label: "A" } }, { id: "2", type: "text", position: { x: 0, y: 0 }, data: { label: "B" } }, ]; const edges = [{ id: "e1", source: "1", target: "2" }];
const result = getLayoutedElements(nodes, edges);
expect(result.nodes).toHaveLength(2); });
it("should preserve edges", () => { const nodes: Node[] = [ { id: "1", type: "text", position: { x: 0, y: 0 }, data: { label: "A" } }, { id: "2", type: "text", position: { x: 0, y: 0 }, data: { label: "B" } }, ]; const edges = [{ id: "e1", source: "1", target: "2" }];
const result = getLayoutedElements(nodes, edges, "LR");
expect(result.edges).toHaveLength(1); expect(result.edges[0].source).toBe("1"); expect(result.edges[0].target).toBe("2"); });});