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

layout.test.ts

450 lines13.7 KB

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 isPrimarySidebarPinned,
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("preserves a useful main pane while constraining a trailing pane", () => {
79 expect(constrainAuxiliaryPaneWidth({ preferredWidth: 440, availableWidth: 1_100 })).toBe(440);
80 expect(constrainAuxiliaryPaneWidth({ preferredWidth: 440, availableWidth: 900 })).toBe(340);
81 expect(constrainAuxiliaryPaneWidth({ preferredWidth: 100, availableWidth: 1_100 })).toBe(260);
82 });
83});
84​
85describe("deriveCenteredContentHorizontalPadding", () => {
86 it("keeps the minimum padding while the viewport fits the reading width", () => {
87 expect(
88 deriveCenteredContentHorizontalPadding({
89 viewportWidth: 744,
90 maxContentWidth: 960,
91 minimumPadding: 20,
92 }),
93 ).toBe(20);
94 });
95​
96 it("centers only the content inside a wider full-width scroll host", () => {
97 expect(
98 deriveCenteredContentHorizontalPadding({
99 viewportWidth: 1_032,
100 maxContentWidth: 960,
101 minimumPadding: 20,
102 }),
103 ).toBe(56);
104 });
105​
106 it("supports unconstrained compact content", () => {
107 expect(
108 deriveCenteredContentHorizontalPadding({
109 viewportWidth: 430,
110 maxContentWidth: null,
111 minimumPadding: 16,
112 }),
113 ).toBe(16);
114 });
115});
116​
117describe("deriveLayout", () => {
118 it.each([
119 { name: "small iPhone portrait", width: 375, height: 667 },
120 { name: "large iPhone portrait", width: 430, height: 932 },
121 { name: "small iPhone landscape", width: 667, height: 375 },
122 { name: "large iPhone landscape", width: 932, height: 430 },
123 { name: "short wide window", width: 1_024, height: 599 },
124 { name: "narrow tall window", width: 719, height: 1_024 },
125 ])("keeps a $name in the compact shell", ({ width, height }) => {
126 expect(deriveLayout({ width, height })).toEqual({
127 variant: "compact",
128 usesSplitView: false,
129 listPaneWidth: null,
130 shellPadding: 0,
131 });
132 });
133​
134 it.each([
135 { name: "small tablet portrait", width: 744, height: 1_133 },
136 { name: "tablet landscape", width: 1_024, height: 768 },
137 { name: "large resizable window", width: 1_366, height: 1_024 },
138 { name: "foldable-sized window", width: 800, height: 700 },
139 ])("uses the split shell for a $name", ({ width, height }) => {
140 expect(deriveLayout({ width, height })).toMatchObject({
141 variant: "split",
142 usesSplitView: true,
143 });
144 });
145​
146 it("switches only after both space requirements are met", () => {
147 expect(
148 deriveLayout({ width: SPLIT_LAYOUT_MIN_WIDTH, height: SPLIT_LAYOUT_MIN_HEIGHT }).variant,
149 ).toBe("split");
150 expect(
151 deriveLayout({ width: SPLIT_LAYOUT_MIN_WIDTH - 1, height: SPLIT_LAYOUT_MIN_HEIGHT }).variant,
152 ).toBe("compact");
153 expect(
154 deriveLayout({ width: SPLIT_LAYOUT_MIN_WIDTH, height: SPLIT_LAYOUT_MIN_HEIGHT - 1 }).variant,
155 ).toBe("compact");
156 });
157​
158 it("keeps the sidebar within usable native-column bounds", () => {
159 expect(deriveLayout({ width: 720, height: 1_000 }).listPaneWidth).toBe(280);
160 expect(deriveLayout({ width: 1_024, height: 768 }).listPaneWidth).toBe(328);
161 expect(deriveLayout({ width: 1_600, height: 1_000 }).listPaneWidth).toBe(380);
162 });
163});
164​
165describe("isPrimarySidebarPinned", () => {
166 it("lets native split columns collapse the sidebar on the workspace root", () => {
167 expect(
168 isPrimarySidebarPinned({ pathname: "/", nativeWorkspace: true, usesSplitView: true }),
169 ).toBe(false);
170 });
171​
172 it("keeps compact native roots pinned so search cannot hide the sidebar for a later split", () => {
173 expect(
174 isPrimarySidebarPinned({ pathname: "/", nativeWorkspace: true, usesSplitView: false }),
175 ).toBe(true);
176 });
177​
178 it("keeps the JS split layout pinned on the workspace root", () => {
179 expect(
180 isPrimarySidebarPinned({ pathname: "/", nativeWorkspace: false, usesSplitView: true }),
181 ).toBe(true);
182 });
183​
184 it("never pins outside the workspace root", () => {
185 expect(
186 isPrimarySidebarPinned({
187 pathname: "/threads/a/b",
188 nativeWorkspace: false,
189 usesSplitView: true,
190 }),
191 ).toBe(false);
192 });
193});
194​
195describe("deriveWorkspacePaneLayout", () => {
196 it("keeps the auxiliary pane out of a standard iPad detail column", () => {
197 const layout = deriveLayout({ width: 1_194, height: 834 });
198​
199 expect(
200 deriveWorkspacePaneLayout({
201 layout,
202 viewportWidth: 1_194,
203 primarySidebarPreferredVisible: true,
204 auxiliaryPanePreferredVisible: true,
205 }),
206 ).toEqual({
207 primarySidebarVisible: true,
208 primarySidebarSuppressedByAuxiliary: false,
209 contentPaneWidth: 814,
210 supportsAuxiliaryPane: false,
211 auxiliaryPaneVisible: false,
212 auxiliaryPaneWidth: null,
213 });
214 });
215​
216 it("offers an auxiliary pane when maximizing a standard iPad landscape window", () => {
217 const layout = deriveLayout({ width: 1_194, height: 834 });
218​
219 expect(
220 deriveWorkspacePaneLayout({
221 layout,
222 viewportWidth: 1_194,
223 primarySidebarPreferredVisible: false,
224 auxiliaryPanePreferredVisible: true,
225 }),
226 ).toEqual({
227 primarySidebarVisible: false,
228 primarySidebarSuppressedByAuxiliary: false,
229 contentPaneWidth: 1_194,
230 supportsAuxiliaryPane: true,
231 auxiliaryPaneVisible: true,
232 auxiliaryPaneWidth: 320,
233 });
234 });
235​
236 it("prioritizes a trailing file inspector over the thread sidebar at medium widths", () => {
237 const layout = deriveLayout({ width: 1_024, height: 1_366 });
238​
239 expect(
240 deriveWorkspacePaneLayout({
241 layout,
242 viewportWidth: 1_024,
243 primarySidebarPreferredVisible: true,
244 auxiliaryPanePreferredVisible: true,
245 auxiliaryPaneRole: "inspector",
246 }),
247 ).toEqual({
248 primarySidebarVisible: false,
249 primarySidebarSuppressedByAuxiliary: true,
250 contentPaneWidth: 1_024,
251 supportsAuxiliaryPane: true,
252 auxiliaryPaneVisible: true,
253 auxiliaryPaneWidth: 260,
254 });
255 });
256​
257 it("keeps threads, content, and the file inspector visible in a large landscape window", () => {
258 const layout = deriveLayout({ width: 1_366, height: 1_024 });
259​
260 expect(
261 deriveWorkspacePaneLayout({
262 layout,
263 viewportWidth: 1_366,
264 primarySidebarPreferredVisible: true,
265 auxiliaryPanePreferredVisible: true,
266 auxiliaryPaneRole: "inspector",
267 }),
268 ).toEqual({
269 primarySidebarVisible: true,
270 primarySidebarSuppressedByAuxiliary: false,
271 contentPaneWidth: 986,
272 supportsAuxiliaryPane: true,
273 auxiliaryPaneVisible: true,
274 auxiliaryPaneWidth: 276,
275 });
276 });
277​
278 it("keeps an explicitly hidden thread sidebar hidden when the file inspector is visible", () => {
279 const layout = deriveLayout({ width: 1_024, height: 1_366 });
280​
281 expect(
282 deriveWorkspacePaneLayout({
283 layout,
284 viewportWidth: 1_024,
285 primarySidebarPreferredVisible: false,
286 auxiliaryPanePreferredVisible: true,
287 auxiliaryPaneRole: "inspector",
288 }),
289 ).toMatchObject({
290 primarySidebarVisible: false,
291 primarySidebarSuppressedByAuxiliary: false,
292 auxiliaryPaneVisible: true,
293 });
294 });
295​
296 it("restores the thread sidebar when the file inspector is hidden", () => {
297 const layout = deriveLayout({ width: 1_024, height: 1_366 });
298​
299 expect(
300 deriveWorkspacePaneLayout({
301 layout,
302 viewportWidth: 1_024,
303 primarySidebarPreferredVisible: true,
304 auxiliaryPanePreferredVisible: false,
305 auxiliaryPaneRole: "inspector",
306 }),
307 ).toMatchObject({
308 primarySidebarVisible: true,
309 primarySidebarSuppressedByAuxiliary: false,
310 auxiliaryPaneVisible: false,
311 });
312 });
313​
314 it("keeps file navigation on the native stack below the inspector breakpoint", () => {
315 const layout = deriveLayout({ width: 744, height: 1_133 });
316​
317 expect(deriveFileInspectorPaneLayout({ layout, viewportWidth: 744 })).toEqual({
318 supported: false,
319 width: null,
320 });
321 expect(
322 deriveWorkspacePaneLayout({
323 layout,
324 viewportWidth: 744,
325 primarySidebarPreferredVisible: true,
326 auxiliaryPanePreferredVisible: true,
327 auxiliaryPaneRole: "inspector",
328 }),
329 ).toMatchObject({
330 primarySidebarVisible: true,
331 supportsAuxiliaryPane: false,
332 auxiliaryPaneVisible: false,
333 });
334 });
335​
336 it("supports three visible columns in a sufficiently large window", () => {
337 const layout = deriveLayout({ width: 1_366, height: 1_024 });
338​
339 expect(
340 deriveWorkspacePaneLayout({
341 layout,
342 viewportWidth: 1_366,
343 primarySidebarPreferredVisible: true,
344 auxiliaryPanePreferredVisible: true,
345 }),
346 ).toMatchObject({
347 primarySidebarVisible: true,
348 contentPaneWidth: 986,
349 supportsAuxiliaryPane: true,
350 auxiliaryPaneVisible: true,
351 auxiliaryPaneWidth: 276,
352 });
353 });
354​
355 it("uses a preferred inspector width when all three panes still fit", () => {
356 const layout = deriveLayout({ width: 1_366, height: 1_024 });
357​
358 expect(
359 deriveWorkspacePaneLayout({
360 layout,
361 viewportWidth: 1_366,
362 primarySidebarPreferredVisible: true,
363 auxiliaryPanePreferredVisible: true,
364 auxiliaryPaneRole: "inspector",
365 auxiliaryPanePreferredWidth: 420,
366 }),
367 ).toMatchObject({
368 primarySidebarVisible: true,
369 auxiliaryPaneVisible: true,
370 auxiliaryPaneWidth: 420,
371 });
372 });
373​
374 it("clamps a preferred supplementary width before squeezing the main pane", () => {
375 const layout = deriveLayout({ width: 1_366, height: 1_024 });
376​
377 expect(
378 deriveWorkspacePaneLayout({
379 layout,
380 viewportWidth: 1_366,
381 primarySidebarPreferredVisible: true,
382 auxiliaryPanePreferredVisible: true,
383 auxiliaryPanePreferredWidth: 460,
384 }).auxiliaryPaneWidth,
385 ).toBe(426);
386 });
387​
388 it("respects a hidden auxiliary-pane preference", () => {
389 const layout = deriveLayout({ width: 1_366, height: 1_024 });
390​
391 expect(
392 deriveWorkspacePaneLayout({
393 layout,
394 viewportWidth: 1_366,
395 primarySidebarPreferredVisible: true,
396 auxiliaryPanePreferredVisible: false,
397 }).auxiliaryPaneVisible,
398 ).toBe(false);
399 });
400​
401 it("never exposes workspace panes in compact layouts", () => {
402 const layout = deriveLayout({ width: 430, height: 932 });
403​
404 expect(
405 deriveWorkspacePaneLayout({
406 layout,
407 viewportWidth: 430,
408 primarySidebarPreferredVisible: true,
409 auxiliaryPanePreferredVisible: true,
410 }),
411 ).toMatchObject({
412 primarySidebarVisible: false,
413 supportsAuxiliaryPane: false,
414 auxiliaryPaneVisible: false,
415 auxiliaryPaneWidth: null,
416 });
417 });
418});
419​
420describe("alignListPaneToHinge", () => {
421 const layout = deriveLayout({ width: 852, height: 880 });
422​
423 it("ends the list pane at a book-posture hinge after the rail", () => {
424 expect(
425 alignListPaneToHinge({
426 layout,
427 hinge: { x: 426, width: 0 },
428 viewportWidth: 852,
429 leadingWidth: 96,
430 }),
431 ).toMatchObject({ listPaneWidth: 330, listPaneGap: 0 });
432 });
433​
434 it("keeps the default split when either side of the hinge would be too narrow", () => {
435 const narrowList = {
436 layout,
437 hinge: { x: 300, width: 0 },
438 viewportWidth: 852,
439 leadingWidth: 96,
440 };
441 const narrowDetail = {
442 layout,
443 hinge: { x: 600, width: 0 },
444 viewportWidth: 852,
445 leadingWidth: 0,
446 };
447 expect(alignListPaneToHinge(narrowList)).toBe(layout);
448 expect(alignListPaneToHinge(narrowDetail)).toBe(layout);
449 });
450});