Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

timelineHeight.test.ts

107 lines2.8 KB

1import { describe, expect, it } from "vitest";
2​
3import { estimateTimelineMessageHeight } from "./timelineHeight";
4​
5describe("estimateTimelineMessageHeight", () => {
6 it("uses assistant sizing rules for assistant messages", () => {
7 expect(
8 estimateTimelineMessageHeight({
9 role: "assistant",
10 text: "a".repeat(144),
11 }),
12 ).toBe(122);
13 });
14​
15 it("uses assistant sizing rules for system messages", () => {
16 expect(
17 estimateTimelineMessageHeight({
18 role: "system",
19 text: "a".repeat(144),
20 }),
21 ).toBe(122);
22 });
23​
24 it("adds one attachment row for one or two user attachments", () => {
25 expect(
26 estimateTimelineMessageHeight({
27 role: "user",
28 text: "hello",
29 attachments: [{ id: "1" }],
30 }),
31 ).toBe(346);
32​
33 expect(
34 estimateTimelineMessageHeight({
35 role: "user",
36 text: "hello",
37 attachments: [{ id: "1" }, { id: "2" }],
38 }),
39 ).toBe(346);
40 });
41​
42 it("adds a second attachment row for three or four user attachments", () => {
43 expect(
44 estimateTimelineMessageHeight({
45 role: "user",
46 text: "hello",
47 attachments: [{ id: "1" }, { id: "2" }, { id: "3" }],
48 }),
49 ).toBe(574);
50​
51 expect(
52 estimateTimelineMessageHeight({
53 role: "user",
54 text: "hello",
55 attachments: [{ id: "1" }, { id: "2" }, { id: "3" }, { id: "4" }],
56 }),
57 ).toBe(574);
58 });
59​
60 it("does not cap long user message estimates", () => {
61 expect(
62 estimateTimelineMessageHeight({
63 role: "user",
64 text: "a".repeat(56 * 120),
65 }),
66 ).toBe(2736);
67 });
68​
69 it("counts explicit newlines for user message estimates", () => {
70 expect(
71 estimateTimelineMessageHeight({
72 role: "user",
73 text: "first\nsecond\nthird",
74 }),
75 ).toBe(162);
76 });
77​
78 it("uses narrower width to increase user line wrapping", () => {
79 const message = {
80 role: "user" as const,
81 text: "a".repeat(52),
82 };
83​
84 expect(estimateTimelineMessageHeight(message, { timelineWidthPx: 320 })).toBe(140);
85 expect(estimateTimelineMessageHeight(message, { timelineWidthPx: 768 })).toBe(118);
86 });
87​
88 it("does not clamp user wrapping too aggressively on very narrow layouts", () => {
89 const message = {
90 role: "user" as const,
91 text: "a".repeat(20),
92 };
93​
94 expect(estimateTimelineMessageHeight(message, { timelineWidthPx: 100 })).toBe(184);
95 expect(estimateTimelineMessageHeight(message, { timelineWidthPx: 320 })).toBe(118);
96 });
97​
98 it("uses narrower width to increase assistant line wrapping", () => {
99 const message = {
100 role: "assistant" as const,
101 text: "a".repeat(200),
102 };
103​
104 expect(estimateTimelineMessageHeight(message, { timelineWidthPx: 320 })).toBe(188);
105 expect(estimateTimelineMessageHeight(message, { timelineWidthPx: 768 })).toBe(122);
106 });
107});