import { describe, expect, it } from "vitest"; import { placeCards } from "./masonry"; const heights = (entries: Record) => new Map(Object.entries(entries)); describe("placing cards on the board", () => { it("uses every column before stacking", () => { const { slots } = placeCards(["a", "b", "c", "d"], heights({ a: 100, b: 100, c: 100, d: 100 }), 4, 16); expect([...slots.values()].map((s) => s.column)).toEqual([0, 1, 2, 3]); }); it("puts the next card under the shortest column, with the gap above it", () => { const { slots } = placeCards(["a", "b", "c"], heights({ a: 300, b: 50, c: 80 }), 2, 16); expect(slots.get("c")).toEqual({ column: 1, top: 66 }); }); it("takes the leftmost column on a tie", () => { const { slots } = placeCards(["a", "b", "c"], heights({ a: 100, b: 100, c: 10 }), 2, 16); expect(slots.get("c")).toEqual({ column: 0, top: 116 }); }); it("reports the tallest column as the board's height", () => { const { height } = placeCards(["a", "b", "c"], heights({ a: 300, b: 50, c: 80 }), 2, 16); expect(height).toBe(316); }); it("counts an unmeasured card as zero tall", () => { const { slots } = placeCards(["a", "b"], heights({ b: 100 }), 1, 16); expect(slots.get("b")).toEqual({ column: 0, top: 16 }); }); it("is an empty board with no cards", () => { const { slots, height } = placeCards([], new Map(), 4, 16); expect(slots.size).toBe(0); expect(height).toBe(0); }); });