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

composerFooterLayout.test.ts

150 lines4.4 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { resolveContextStripLabelsCompact } from "./BranchToolbar.logic";
4import {
5 resolveComposerTimelineInset,
6 resolveRestingComposerControlsLayout,
7 resolveRestingComposerControlsNaturalWidth,
8} from "./composerFooterLayout";
9​
10describe("resolveComposerTimelineInset", () => {
11 it("keeps timeline padding stable when the model-only strip appears on collapse", () => {
12 const expanded = resolveComposerTimelineInset({
13 currentInset: 0,
14 overlayHeight: 172,
15 isResting: false,
16 });
17 const collapsed = resolveComposerTimelineInset({
18 currentInset: expanded,
19 overlayHeight: 110,
20 isResting: true,
21 restingOnlyHeight: 32,
22 });
23 expect(collapsed).toBe(expanded);
24 expect(
25 resolveComposerTimelineInset({
26 currentInset: collapsed,
27 overlayHeight: 172,
28 isResting: false,
29 }),
30 ).toBe(expanded);
31 });
32​
33 it("keeps the timeline reservation stable through notice expansion and collapse", () => {
34 const collapsed = resolveComposerTimelineInset({
35 currentInset: 0,
36 overlayHeight: 172,
37 isResting: false,
38 });
39 const expanded = resolveComposerTimelineInset({
40 currentInset: collapsed,
41 overlayHeight: 532,
42 isResting: false,
43 expandedNoticesHeight: 360,
44 });
45 expect(expanded).toBe(collapsed);
46 const resting = resolveComposerTimelineInset({
47 currentInset: expanded,
48 overlayHeight: 470,
49 isResting: true,
50 expandedNoticesHeight: 360,
51 });
52 expect(resting).toBe(collapsed);
53 expect(
54 resolveComposerTimelineInset({
55 currentInset: resting,
56 overlayHeight: 110,
57 isResting: true,
58 }),
59 ).toBe(collapsed);
60 });
61});
62​
63describe("context strip labels and resting composer controls", () => {
64 const stripWidth = 724;
65 const labelWidth = 327;
66 const chromeWidth = 125;
67 const measurement = {
68 gap: 4,
69 naturalFixedWidth: 96.3828125 + 5 + 4,
70 minimumFixedWidth: 52 + 5 + 4,
71 blockWidths: [130.6953125, 119.671875],
72 overflowWidth: 28,
73 };
74 const naturalWidth = resolveRestingComposerControlsNaturalWidth(measurement);
75​
76 function hostWidth(compact: boolean): number {
77 return stripWidth - chromeWidth - (compact ? 0 : labelWidth);
78 }
79​
80 it("keeps the labels compact when the full controls only fit beside compact labels", () => {
81 const layout = resolveRestingComposerControlsLayout({
82 ...measurement,
83 hostWidth: hostWidth(true),
84 });
85 expect(layout).toEqual({ hiddenCount: 0, visible: true });
86​
87 const compact = resolveContextStripLabelsCompact({
88 compact: true,
89 neededWidth: chromeWidth + labelWidth + naturalWidth,
90 availableWidth: stripWidth,
91 });
92 expect(compact).toBe(true);
93​
94 expect(
95 resolveRestingComposerControlsLayout({ ...measurement, hostWidth: hostWidth(compact) }),
96 ).toEqual(layout);
97 });
98});
99​
100describe("resolveRestingComposerControlsLayout hysteresis", () => {
101 const base = {
102 gap: 4,
103 naturalFixedWidth: 149,
104 minimumFixedWidth: 105,
105 blockWidths: [60, 140],
106 overflowWidth: 24,
107 };
108​
109 it("settles when the measured picker width jitters below a pixel", () => {
110 let layout = { hiddenCount: 0, visible: true };
111 const settled: string[] = [];
112 for (let index = 0; index < 10; index += 1) {
113 layout = resolveRestingComposerControlsLayout({
114 ...base,
115 naturalFixedWidth: index % 2 === 0 ? 149 : 149.5,
116 hostWidth: 357,
117 previous: layout,
118 });
119 if (index >= 2) settled.push(`${layout.hiddenCount}:${layout.visible}`);
120 }
121 expect(new Set(settled).size).toBe(1);
122 });
123});
124​
125describe("progressive composer controls", () => {
126 const measurement = {
127 gap: 4,
128 naturalFixedWidth: 140,
129 minimumFixedWidth: 80,
130 blockWidths: [80, 140],
131 iconOnlyBlockWidths: [40, 60],
132 overflowWidth: 24,
133 };
134​
135 it("settles through fractional label-width changes at each threshold", () => {
136 for (const hostWidth of [368, 288, 248]) {
137 let previous = resolveRestingComposerControlsLayout({ ...measurement, hostWidth });
138 for (let index = 0; index < 10; index += 1) {
139 const next = resolveRestingComposerControlsLayout({
140 ...measurement,
141 hostWidth,
142 previous,
143 naturalFixedWidth: 140 + (index % 2) * 0.5,
144 });
145 if (index > 1) expect(next).toEqual(previous);
146 previous = next;
147 }
148 }
149 });
150});