Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import {
4 constrainAuxiliaryPaneWidth,
5 constrainPrimarySidebarWidth,
6 deriveCenteredContentHorizontalPadding,
7 deriveFileInspectorPaneLayout,
8 deriveLayout,
9 deriveStableFormSheetDetent,
10 deriveThreadFeedInitialContentInset,
11 deriveThreadWorkLogSizing,
12 deriveWorkspacePaneLayout,
13 SPLIT_LAYOUT_MIN_HEIGHT,
14 SPLIT_LAYOUT_MIN_WIDTH,
15} from "./layout";
16
17describe("thread work-log text sizing", () => {
18 it.each([11, 16, 22])(
19 "keeps exact compact rows at base size %i without OS enlargement",
20 (baseFontSize) => {
21 expect(deriveThreadWorkLogSizing({ baseFontSize, fontScale: 1 })).toMatchObject({
22 estimatedRowHeight: 28,
23 fixedRowHeight: 28,
24 });
25 },
26 );
27
28 it.each([
29 { baseFontSize: 16, fontScale: 1.25, estimatedRowHeight: 28 },
30 { baseFontSize: 16, fontScale: 2, estimatedRowHeight: 38 },
31 { baseFontSize: 22, fontScale: 2, estimatedRowHeight: 52 },
32 ])(
33 "measures accessibility text instead of locking it to the estimate: %j",
34 ({ estimatedRowHeight, ...settings }) => {
35 expect(deriveThreadWorkLogSizing(settings)).toMatchObject({
36 estimatedRowHeight,
37 fixedRowHeight: undefined,
38 });
39 },
40 );
41
42 it("invalidates native text measurements even when the minimum row height is unchanged", () => {
43 const original = deriveThreadWorkLogSizing({ baseFontSize: 16, fontScale: 1 });
44 for (const settings of [
45 { baseFontSize: 16, fontScale: 1.1 },
46 { baseFontSize: 17, fontScale: 1 },
47 ]) {
48 const resized = deriveThreadWorkLogSizing(settings);
49 expect(resized.estimatedRowHeight).toBe(original.estimatedRowHeight);
50 expect(resized.textSizeKey).not.toBe(original.textSizeKey);
51 }
52 });
53});
54
55describe("deriveThreadFeedInitialContentInset", () => {
56 it("seeds Android scroll math with the composer overlay estimate", () => {
57 expect(
58 deriveThreadFeedInitialContentInset({
59 platform: "android",
60 usesNativeAutomaticInsets: false,
61 bottomContentInset: 174,
62 }),
63 ).toEqual({ bottom: 174 });
64 });
65
66 it("does not double native iOS insets", () => {
67 expect(
68 deriveThreadFeedInitialContentInset({
69 platform: "ios",
70 usesNativeAutomaticInsets: true,
71 bottomContentInset: 174,
72 }),
73 ).toBeUndefined();
74 });
75});
76
77describe("resizable pane constraints", () => {
78 it("keeps a preferred sidebar width across large windows and clamps it in a narrow split view", () => {
79 expect(constrainPrimarySidebarWidth(430, 1_366)).toBe(430);
80 expect(constrainPrimarySidebarWidth(430, 744)).toBe(384);
81 expect(constrainPrimarySidebarWidth(100, 1_366)).toBe(280);
82 });
83
84 it("preserves a useful main pane while constraining a trailing pane", () => {
85 expect(constrainAuxiliaryPaneWidth({ preferredWidth: 440, availableWidth: 1_100 })).toBe(440);
86 expect(constrainAuxiliaryPaneWidth({ preferredWidth: 440, availableWidth: 900 })).toBe(340);
87 expect(constrainAuxiliaryPaneWidth({ preferredWidth: 100, availableWidth: 1_100 })).toBe(260);
88 });
89});
90
91describe("deriveCenteredContentHorizontalPadding", () => {
92 it("keeps the minimum padding while the viewport fits the reading width", () => {
93 expect(
94 deriveCenteredContentHorizontalPadding({
95 viewportWidth: 744,
96 maxContentWidth: 960,
97 minimumPadding: 20,
98 }),
99 ).toBe(20);
100 });
101
102 it("centers only the content inside a wider full-width scroll host", () => {
103 expect(
104 deriveCenteredContentHorizontalPadding({
105 viewportWidth: 1_032,
106 maxContentWidth: 960,
107 minimumPadding: 20,
108 }),
109 ).toBe(56);
110 });
111
112 it("supports unconstrained compact content", () => {
113 expect(
114 deriveCenteredContentHorizontalPadding({
115 viewportWidth: 430,
116 maxContentWidth: null,
117 minimumPadding: 16,
118 }),
119 ).toBe(16);
120 });
121});
122
123describe("deriveLayout", () => {
124 it.each([
125 { name: "small iPhone portrait", width: 375, height: 667 },
126 { name: "large iPhone portrait", width: 430, height: 932 },
127 { name: "small iPhone landscape", width: 667, height: 375 },
128 { name: "large iPhone landscape", width: 932, height: 430 },
129 { name: "short wide window", width: 1_024, height: 599 },
130 { name: "narrow tall window", width: 719, height: 1_024 },
131 ])("keeps a $name in the compact shell", ({ width, height }) => {
132 expect(deriveLayout({ width, height })).toEqual({
133 variant: "compact",
134 usesSplitView: false,
135 listPaneWidth: null,
136 shellPadding: 0,
137 });
138 });
139
140 it.each([
141 { name: "small tablet portrait", width: 744, height: 1_133 },
142 { name: "tablet landscape", width: 1_024, height: 768 },
143 { name: "large resizable window", width: 1_366, height: 1_024 },
144 { name: "foldable-sized window", width: 800, height: 700 },
145 ])("uses the split shell for a $name", ({ width, height }) => {
146 expect(deriveLayout({ width, height })).toMatchObject({
147 variant: "split",
148 usesSplitView: true,
149 });
150 });
151
152 it("switches only after both space requirements are met", () => {
153 expect(
154 deriveLayout({ width: SPLIT_LAYOUT_MIN_WIDTH, height: SPLIT_LAYOUT_MIN_HEIGHT }).variant,
155 ).toBe("split");
156 expect(
157 deriveLayout({ width: SPLIT_LAYOUT_MIN_WIDTH - 1, height: SPLIT_LAYOUT_MIN_HEIGHT }).variant,
158 ).toBe("compact");
159 expect(
160 deriveLayout({ width: SPLIT_LAYOUT_MIN_WIDTH, height: SPLIT_LAYOUT_MIN_HEIGHT - 1 }).variant,
161 ).toBe("compact");
162 });
163
164 it("keeps the sidebar within usable native-column bounds", () => {
165 expect(deriveLayout({ width: 720, height: 1_000 }).listPaneWidth).toBe(280);
166 expect(deriveLayout({ width: 1_024, height: 768 }).listPaneWidth).toBe(328);
167 expect(deriveLayout({ width: 1_600, height: 1_000 }).listPaneWidth).toBe(380);
168 });
169});
170
171describe("deriveWorkspacePaneLayout", () => {
172 it("keeps the auxiliary pane out of a standard iPad detail column", () => {
173 const layout = deriveLayout({ width: 1_194, height: 834 });
174
175 expect(
176 deriveWorkspacePaneLayout({
177 layout,
178 viewportWidth: 1_194,
179 primarySidebarPreferredVisible: true,
180 auxiliaryPanePreferredVisible: true,
181 }),
182 ).toEqual({
183 primarySidebarVisible: true,
184 primarySidebarSuppressedByAuxiliary: false,
185 contentPaneWidth: 814,
186 supportsAuxiliaryPane: false,
187 auxiliaryPaneVisible: false,
188 auxiliaryPaneWidth: null,
189 });
190 });
191
192 it("offers an auxiliary pane when maximizing a standard iPad landscape window", () => {
193 const layout = deriveLayout({ width: 1_194, height: 834 });
194
195 expect(
196 deriveWorkspacePaneLayout({
197 layout,
198 viewportWidth: 1_194,
199 primarySidebarPreferredVisible: false,
200 auxiliaryPanePreferredVisible: true,
201 }),
202 ).toEqual({
203 primarySidebarVisible: false,
204 primarySidebarSuppressedByAuxiliary: false,
205 contentPaneWidth: 1_194,
206 supportsAuxiliaryPane: true,
207 auxiliaryPaneVisible: true,
208 auxiliaryPaneWidth: 320,
209 });
210 });
211
212 it("prioritizes a trailing file inspector over the thread sidebar at medium widths", () => {
213 const layout = deriveLayout({ width: 1_024, height: 1_366 });
214
215 expect(
216 deriveWorkspacePaneLayout({
217 layout,
218 viewportWidth: 1_024,
219 primarySidebarPreferredVisible: true,
220 auxiliaryPanePreferredVisible: true,
221 auxiliaryPaneRole: "inspector",
222 }),
223 ).toEqual({
224 primarySidebarVisible: false,
225 primarySidebarSuppressedByAuxiliary: true,
226 contentPaneWidth: 1_024,
227 supportsAuxiliaryPane: true,
228 auxiliaryPaneVisible: true,
229 auxiliaryPaneWidth: 260,
230 });
231 });
232
233 it("keeps threads, content, and the file inspector visible in a large landscape window", () => {
234 const layout = deriveLayout({ width: 1_366, height: 1_024 });
235
236 expect(
237 deriveWorkspacePaneLayout({
238 layout,
239 viewportWidth: 1_366,
240 primarySidebarPreferredVisible: true,
241 auxiliaryPanePreferredVisible: true,
242 auxiliaryPaneRole: "inspector",
243 }),
244 ).toEqual({
245 primarySidebarVisible: true,
246 primarySidebarSuppressedByAuxiliary: false,
247 contentPaneWidth: 986,
248 supportsAuxiliaryPane: true,
249 auxiliaryPaneVisible: true,
250 auxiliaryPaneWidth: 276,
251 });
252 });
253
254 it("keeps an explicitly hidden thread sidebar hidden when the file inspector is visible", () => {
255 const layout = deriveLayout({ width: 1_024, height: 1_366 });
256
257 expect(
258 deriveWorkspacePaneLayout({
259 layout,
260 viewportWidth: 1_024,
261 primarySidebarPreferredVisible: false,
262 auxiliaryPanePreferredVisible: true,
263 auxiliaryPaneRole: "inspector",
264 }),
265 ).toMatchObject({
266 primarySidebarVisible: false,
267 primarySidebarSuppressedByAuxiliary: false,
268 auxiliaryPaneVisible: true,
269 });
270 });
271
272 it("restores the thread sidebar when the file inspector is hidden", () => {
273 const layout = deriveLayout({ width: 1_024, height: 1_366 });
274
275 expect(
276 deriveWorkspacePaneLayout({
277 layout,
278 viewportWidth: 1_024,
279 primarySidebarPreferredVisible: true,
280 auxiliaryPanePreferredVisible: false,
281 auxiliaryPaneRole: "inspector",
282 }),
283 ).toMatchObject({
284 primarySidebarVisible: true,
285 primarySidebarSuppressedByAuxiliary: false,
286 auxiliaryPaneVisible: false,
287 });
288 });
289
290 it("keeps file navigation on the native stack below the inspector breakpoint", () => {
291 const layout = deriveLayout({ width: 744, height: 1_133 });
292
293 expect(deriveFileInspectorPaneLayout({ layout, viewportWidth: 744 })).toEqual({
294 supported: false,
295 width: null,
296 });
297 expect(
298 deriveWorkspacePaneLayout({
299 layout,
300 viewportWidth: 744,
301 primarySidebarPreferredVisible: true,
302 auxiliaryPanePreferredVisible: true,
303 auxiliaryPaneRole: "inspector",
304 }),
305 ).toMatchObject({
306 primarySidebarVisible: true,
307 supportsAuxiliaryPane: false,
308 auxiliaryPaneVisible: false,
309 });
310 });
311
312 it("supports three visible columns in a sufficiently large window", () => {
313 const layout = deriveLayout({ width: 1_366, height: 1_024 });
314
315 expect(
316 deriveWorkspacePaneLayout({
317 layout,
318 viewportWidth: 1_366,
319 primarySidebarPreferredVisible: true,
320 auxiliaryPanePreferredVisible: true,
321 }),
322 ).toMatchObject({
323 primarySidebarVisible: true,
324 contentPaneWidth: 986,
325 supportsAuxiliaryPane: true,
326 auxiliaryPaneVisible: true,
327 auxiliaryPaneWidth: 276,
328 });
329 });
330
331 it("uses a preferred inspector width when all three panes still fit", () => {
332 const layout = deriveLayout({ width: 1_366, height: 1_024 });
333
334 expect(
335 deriveWorkspacePaneLayout({
336 layout,
337 viewportWidth: 1_366,
338 primarySidebarPreferredVisible: true,
339 auxiliaryPanePreferredVisible: true,
340 auxiliaryPaneRole: "inspector",
341 auxiliaryPanePreferredWidth: 420,
342 }),
343 ).toMatchObject({
344 primarySidebarVisible: true,
345 auxiliaryPaneVisible: true,
346 auxiliaryPaneWidth: 420,
347 });
348 });
349
350 it("clamps a preferred supplementary width before squeezing the main pane", () => {
351 const layout = deriveLayout({ width: 1_366, height: 1_024 });
352
353 expect(
354 deriveWorkspacePaneLayout({
355 layout,
356 viewportWidth: 1_366,
357 primarySidebarPreferredVisible: true,
358 auxiliaryPanePreferredVisible: true,
359 auxiliaryPanePreferredWidth: 460,
360 }).auxiliaryPaneWidth,
361 ).toBe(426);
362 });
363
364 it("respects a hidden auxiliary-pane preference", () => {
365 const layout = deriveLayout({ width: 1_366, height: 1_024 });
366
367 expect(
368 deriveWorkspacePaneLayout({
369 layout,
370 viewportWidth: 1_366,
371 primarySidebarPreferredVisible: true,
372 auxiliaryPanePreferredVisible: false,
373 }).auxiliaryPaneVisible,
374 ).toBe(false);
375 });
376
377 it("never exposes workspace panes in compact layouts", () => {
378 const layout = deriveLayout({ width: 430, height: 932 });
379
380 expect(
381 deriveWorkspacePaneLayout({
382 layout,
383 viewportWidth: 430,
384 primarySidebarPreferredVisible: true,
385 auxiliaryPanePreferredVisible: true,
386 }),
387 ).toMatchObject({
388 primarySidebarVisible: false,
389 supportsAuxiliaryPane: false,
390 auxiliaryPaneVisible: false,
391 auxiliaryPaneWidth: null,
392 });
393 });
394});
395
396describe("deriveStableFormSheetDetent", () => {
397 it.each([
398 { height: 1_194, expected: 0.62 },
399 { height: 834, expected: 0.863 },
400 { height: 600, expected: 0.893 },
401 { height: 0, expected: 0.92 },
402 ])("derives a stable sheet detent for height $height", ({ height, expected }) => {
403 expect(deriveStableFormSheetDetent(height)).toBe(expected);
404 });
405});