Open History to see the last commit
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
34describe("context strip labels and resting composer controls", () => {
35 const stripWidth = 724;
36 const labelWidth = 327;
37 const chromeWidth = 125;
38 const measurement = {
39 gap: 4,
40 naturalFixedWidth: 96.3828125 + 5 + 4,
41 minimumFixedWidth: 52 + 5 + 4,
42 blockWidths: [130.6953125, 119.671875],
43 overflowWidth: 28,
44 };
45 const naturalWidth = resolveRestingComposerControlsNaturalWidth(measurement);
46
47 function hostWidth(compact: boolean): number {
48 return stripWidth - chromeWidth - (compact ? 0 : labelWidth);
49 }
50
51 it("keeps the labels compact when the full controls only fit beside compact labels", () => {
52 const layout = resolveRestingComposerControlsLayout({
53 ...measurement,
54 hostWidth: hostWidth(true),
55 });
56 expect(layout).toEqual({ hiddenCount: 0, visible: true });
57
58 const compact = resolveContextStripLabelsCompact({
59 compact: true,
60 neededWidth: chromeWidth + labelWidth + naturalWidth,
61 availableWidth: stripWidth,
62 });
63 expect(compact).toBe(true);
64
65 expect(
66 resolveRestingComposerControlsLayout({ ...measurement, hostWidth: hostWidth(compact) }),
67 ).toEqual(layout);
68 });
69});
70
71describe("resolveRestingComposerControlsLayout hysteresis", () => {
72 const base = {
73 gap: 4,
74 naturalFixedWidth: 149,
75 minimumFixedWidth: 105,
76 blockWidths: [60, 140],
77 overflowWidth: 24,
78 };
79
80 it("settles when the measured picker width jitters below a pixel", () => {
81 let layout = { hiddenCount: 0, visible: true };
82 const settled: string[] = [];
83 for (let index = 0; index < 10; index += 1) {
84 layout = resolveRestingComposerControlsLayout({
85 ...base,
86 naturalFixedWidth: index % 2 === 0 ? 149 : 149.5,
87 hostWidth: 357,
88 previous: layout,
89 });
90 if (index >= 2) settled.push(`${layout.hiddenCount}:${layout.visible}`);
91 }
92 expect(new Set(settled).size).toBe(1);
93 });
94});
95
96describe("progressive composer controls", () => {
97 const measurement = {
98 gap: 4,
99 naturalFixedWidth: 140,
100 minimumFixedWidth: 80,
101 blockWidths: [80, 140],
102 iconOnlyBlockWidths: [40, 60],
103 overflowWidth: 24,
104 };
105
106 it("settles through fractional label-width changes at each threshold", () => {
107 for (const hostWidth of [368, 288, 248]) {
108 let previous = resolveRestingComposerControlsLayout({ ...measurement, hostWidth });
109 for (let index = 0; index < 10; index += 1) {
110 const next = resolveRestingComposerControlsLayout({
111 ...measurement,
112 hostWidth,
113 previous,
114 naturalFixedWidth: 140 + (index % 2) * 0.5,
115 });
116 if (index > 1) expect(next).toEqual(previous);
117 previous = next;
118 }
119 }
120 });
121});