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