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

layout.test.ts

366 lines11.2 KB

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