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