1import { describe, expect, it } from "vite-plus/test";
2import { threadDragAction, threadOrderAfterMove } from "./threadOrder";
3import { threadDragGapOffset } from "./threadDragGap";
4
5describe("live thread insertion gap", () => {
6 // Header, pinned row, Active header, two active rows. Geometry stays fixed for hit testing.
7 const offsets = [0, 48, 120, 168, 240];
8 const shifts = (source: number, insertion: number) =>
9 offsets.map((offset) => threadDragGapOffset(offset, source, 72, insertion));
10
11 it("moves the Active header and intervening rows up when unpinning", () => {
12 expect(shifts(48, 312)).toEqual([0, 0, -72, -72, -72]);
13 });
14 it("opens a full gap below the Pinned header when pinning", () => {
15 expect(shifts(240, 48)).toEqual([0, 72, 72, 72, 0]);
16 });
17 it("leaves the source gap in place for cancellation or its current destination", () => {
18 expect(shifts(168, 168)).toEqual([0, 0, 0, 0, 0]);
19 expect(shifts(168, 240)).toEqual([0, 0, 0, 0, 0]);
20 });
21 it("moves only crossed rows for an adjacent reorder", () => {
22 expect(shifts(168, 312)).toEqual([0, 0, 0, 0, -72]);
23 expect(shifts(240, 168)).toEqual([0, 0, 0, 72, 0]);
24 });
25});
26
27describe("drag action labels", () => {
28 it("names the action for each destination instead of its section", () => {
29 expect(threadDragAction("active", "pinned")).toBe("Pin");
30 expect(threadDragAction("pinned", "active")).toBe("Unpin");
31 expect(threadDragAction("settled", "active")).toBe("Unsettle");
32 expect(threadDragAction("snoozed", "active")).toBe("Unsnooze");
33 expect(threadDragAction("active", "settled")).toBe("Settle");
34 expect(threadDragAction("pinned", "settled")).toBe("Settle");
35 expect(threadDragAction("active", "active")).toBe("Reorder");
36 });
37 it("does not offer a parked-section reorder or snooze without a wake time", () => {
38 expect(threadDragAction("settled", "settled")).toBeNull();
39 expect(threadDragAction("active", "snoozed")).toBeNull();
40 expect(
41 threadOrderAfterMove(["a", "b"], "a", {
42 section: "settled",
43 targetId: null,
44 placement: "before",
45 }),
46 ).toBeNull();
47 });
48});