Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import {
3 resolveThreadDetailsCardDensity,
4 resolveThreadDetailsCardLayout,
5} from "./threadDetailsCardLayout";
6
7const lane = { padding: 48, minChatWidth: 640 };
8const resolve = (width: number, height: number, previewY: number | null = null) =>
9 resolveThreadDetailsCardLayout({
10 container: { width, height },
11 lane,
12 frame: previewY === null ? null : { x: width - 332, y: previewY, width: 320, height: 240 },
13 });
14
15describe("workspace card", () => {
16 it("pins to the top right at a fixed width", () => {
17 expect(resolve(1600, 900)).toEqual({
18 x: 1308,
19 y: 12,
20 width: 280,
21 height: 876,
22 });
23 expect(resolve(1344, 900)).toMatchObject({ x: 1052, width: 280 });
24 });
25 it("starts below the open find bar, keeping the bottom inset", () => {
26 expect(
27 resolveThreadDetailsCardLayout({
28 container: { width: 1600, height: 900 },
29 lane,
30 frame: null,
31 topInset: 48,
32 }),
33 ).toEqual({ x: 1308, y: 60, width: 280, height: 828 });
34 });
35 it("hides when a readable chat lane cannot fit beside it", () => {
36 expect(resolve(1012, 900)).toMatchObject({ x: 720 });
37 expect(resolve(1011, 900)).toBeNull();
38 });
39 it("keeps the card at the top right while the preview is freely dragged vertically", () => {
40 for (const y of [12, 170, 250, 400, 648]) {
41 expect(resolve(1600, 900, y)).toEqual({ x: 1308, y: 12, width: 280, height: 876 });
42 }
43 });
44 it("keeps full height while a preview stays clear of the card", () => {
45 expect(resolve(1344, 900, 600)).toMatchObject({ width: 280, height: 876 });
46 expect(
47 resolveThreadDetailsCardLayout({
48 container: { width: 1600, height: 900 },
49 lane,
50 frame: { x: 12, y: 100, width: 320, height: 240 },
51 })?.height,
52 ).toBe(876);
53 });
54});
55
56describe("card content fitting", () => {
57 const place = (previewY: number, previewHeight = 365, overlapsDetailsCard = false) =>
58 resolveThreadDetailsCardLayout({
59 container: { width: 1584, height: 988 },
60 lane,
61 frame: { x: 1260, y: previewY, width: 240, height: previewHeight },
62 overlapsDetailsCard,
63 });
64 it("does not fold in response to a drag while the full card can be kept clear", () => {
65 for (const y of [12, 170, 225, 240, 340, 380, 611]) {
66 const placement = place(y)!;
67 expect(placement).toMatchObject({ x: 1292, y: 12, height: 964 });
68 expect(resolveThreadDetailsCardDensity(placement.height, { full: 327, compact: 182 })).toBe(
69 "full",
70 );
71 }
72 });
73 it("folds only after the preview cannot fit around the full card", () => {
74 const content = { full: 327, compact: 182 };
75 expect(resolveThreadDetailsCardDensity(place(351, 625, true)!.height, content)).toBe("full");
76 expect(resolveThreadDetailsCardDensity(place(350, 626, true)!.height, content)).toBe("compact");
77 expect(resolveThreadDetailsCardDensity(place(12)!.height, content)).toBe("full");
78 });
79 it("hides only when the available height cannot hold readable controls", () => {
80 expect(place(184, 792, true)).toMatchObject({ y: 12, height: 160 });
81 expect(place(183, 793, true)).toBeNull();
82 });
83 it("keeps all content as a freely moved preview approaches without colliding", () => {
84 const content = { full: 162, compact: 126 };
85 for (const y of [650, 450, 350, 250]) {
86 expect(resolveThreadDetailsCardDensity(resolve(1600, 900, y)!.height, content)).toBe("full");
87 }
88 });
89 it("folds only detail that cannot fit and restores it when space returns", () => {
90 const content = { full: 570, compact: 180 };
91 expect(resolveThreadDetailsCardDensity(600, content)).toBe("full");
92 expect(resolveThreadDetailsCardDensity(400, content)).toBe("compact");
93 expect(resolveThreadDetailsCardDensity(170, content)).toBe("essential");
94 expect(resolveThreadDetailsCardDensity(570, content)).toBe("full");
95 });
96 it("measures unseen content before deciding to fold it", () => {
97 expect(resolveThreadDetailsCardDensity(300, { full: 0, compact: 0 })).toBe("full");
98 expect(resolveThreadDetailsCardDensity(300, { full: 570, compact: 0 })).toBe("compact");
99 });
100});