Something went wrong. Try again.
Monorepo for Tangled forked from tangled.org/core
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243import { describe, expect, it } from "vitest";import { dropIndex, shiftFor } from "#lib/components/profile/pinnedReorder.ts";
// two columns of 100x50 cards with 10px gapsconst grid = [0, 1, 2, 3, 4].map((index) => ({ left: (index % 2) * 110, top: Math.floor(index / 2) * 60, width: 100, height: 50}));
describe("dropIndex", () => { it("picks the slot nearest the pointer", () => { expect(dropIndex(grid, 10, 10)).toBe(0); expect(dropIndex(grid, 200, 20)).toBe(1); expect(dropIndex(grid, 160, 90)).toBe(3); expect(dropIndex(grid, 40, 400)).toBe(4); expect(dropIndex(grid, -90, -90)).toBe(0); });
it("handles an empty list", () => { expect(dropIndex([], 10, 10)).toBe(0); });});
describe("shiftFor", () => { const shifts = (from: number, to: number) => grid.map((_, index) => shiftFor(index, from, to, grid)); const still = { x: 0, y: 0 };
it("slides the passed cards back one slot when a card moves later", () => { expect(shifts(0, 2)).toEqual([still, { x: -110, y: 0 }, { x: 110, y: -60 }, still, still]); });
it("slides the passed cards on one slot when a card moves earlier", () => { expect(shifts(3, 1)).toEqual([still, { x: -110, y: 60 }, { x: 110, y: 0 }, still, still]); });
it("leaves everything in place when the drag has not moved", () => { expect(shifts(1, 1)).toEqual(grid.map(() => still)); });});