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