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: 20, 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("hides when a readable chat lane cannot fit beside it", () => {
26 expect(resolve(984, 900)).toMatchObject({ x: 692 });
27 expect(resolve(983, 900)).toBeNull();
28 });
29 it("keeps the card at the top right while the preview is freely dragged vertically", () => {
30 for (const y of [12, 170, 250, 400, 648]) {
31 expect(resolve(1600, 900, y)).toEqual({ x: 1308, y: 12, width: 280, height: 876 });
32 }
33 });
34 it("keeps full height while a preview stays clear of the card", () => {
35 expect(resolve(1344, 900, 600)).toMatchObject({ width: 280, height: 876 });
36 expect(
37 resolveThreadDetailsCardLayout({
38 container: { width: 1600, height: 900 },
39 lane,
40 frame: { x: 12, y: 100, width: 320, height: 240 },
41 })?.height,
42 ).toBe(876);
43 });
44});
45
46describe("card content fitting", () => {
47 const place = (previewY: number, previewHeight = 365, overlapsDetailsCard = false) =>
48 resolveThreadDetailsCardLayout({
49 container: { width: 1584, height: 988 },
50 lane,
51 frame: { x: 1260, y: previewY, width: 240, height: previewHeight },
52 overlapsDetailsCard,
53 });
54 it("does not fold in response to a drag while the full card can be kept clear", () => {
55 for (const y of [12, 170, 225, 240, 340, 380, 611]) {
56 const placement = place(y)!;
57 expect(placement).toMatchObject({ x: 1292, y: 12, height: 964 });
58 expect(resolveThreadDetailsCardDensity(placement.height, { full: 327, compact: 182 })).toBe(
59 "full",
60 );
61 }
62 });
63 it("folds only after the preview cannot fit around the full card", () => {
64 const content = { full: 327, compact: 182 };
65 expect(resolveThreadDetailsCardDensity(place(351, 625, true)!.height, content)).toBe("full");
66 expect(resolveThreadDetailsCardDensity(place(350, 626, true)!.height, content)).toBe("compact");
67 expect(resolveThreadDetailsCardDensity(place(12)!.height, content)).toBe("full");
68 });
69 it("hides only when the available height cannot hold readable controls", () => {
70 expect(place(184, 792, true)).toMatchObject({ y: 12, height: 160 });
71 expect(place(183, 793, true)).toBeNull();
72 });
73 it("keeps all content as a freely moved preview approaches without colliding", () => {
74 const content = { full: 162, compact: 126 };
75 for (const y of [650, 450, 350, 250]) {
76 expect(resolveThreadDetailsCardDensity(resolve(1600, 900, y)!.height, content)).toBe("full");
77 }
78 });
79 it("folds only detail that cannot fit and restores it when space returns", () => {
80 const content = { full: 570, compact: 180 };
81 expect(resolveThreadDetailsCardDensity(600, content)).toBe("full");
82 expect(resolveThreadDetailsCardDensity(400, content)).toBe("compact");
83 expect(resolveThreadDetailsCardDensity(170, content)).toBe("essential");
84 expect(resolveThreadDetailsCardDensity(570, content)).toBe("full");
85 });
86 it("measures unseen content before deciding to fold it", () => {
87 expect(resolveThreadDetailsCardDensity(300, { full: 0, compact: 0 })).toBe("full");
88 expect(resolveThreadDetailsCardDensity(300, { full: 570, compact: 0 })).toBe("compact");
89 });
90});