Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import {
4 alignListPaneToHinge,
5 deriveLayout,
6 deriveThreadFeedInitialContentInset,
7 deriveThreadArrangementSizing,
8 deriveThreadWorkLogSizing,
9 deriveWorkspacePaneLayout,
10 nativeInspectorColumnWidth,
11 isPrimarySidebarPinned,
12} from "./layout";
13
14describe("thread arrangement text sizing", () => {
15 it("fits two title lines and section labels with combined app and system text scaling", () => {
16 const sizing = deriveThreadArrangementSizing({ baseFontSize: 22, fontScale: 1.3 });
17 expect(sizing.rowHeight).toBeGreaterThanOrEqual(2 * 32 * 1.3 + 10);
18 expect(sizing.headerHeight).toBeGreaterThanOrEqual(26 * 1.3 + 24);
19 expect(deriveThreadArrangementSizing({ baseFontSize: 16, fontScale: 1 })).toEqual({
20 rowHeight: 56,
21 headerHeight: 48,
22 });
23 });
24});
25
26describe("thread work-log text sizing", () => {
27 it.each([
28 { baseFontSize: 16, fontScale: 1.25, estimatedRowHeight: 28 },
29 { baseFontSize: 22, fontScale: 2, estimatedRowHeight: 52 },
30 ])(
31 "measures accessibility text instead of locking it to the estimate: %j",
32 ({ estimatedRowHeight, ...settings }) => {
33 expect(deriveThreadWorkLogSizing(settings)).toMatchObject({
34 estimatedRowHeight,
35 fixedRowHeight: undefined,
36 });
37 },
38 );
39
40 it("invalidates native text measurements even when the minimum row height is unchanged", () => {
41 const original = deriveThreadWorkLogSizing({ baseFontSize: 16, fontScale: 1 });
42 for (const settings of [
43 { baseFontSize: 16, fontScale: 1.1 },
44 { baseFontSize: 17, fontScale: 1 },
45 ]) {
46 const resized = deriveThreadWorkLogSizing(settings);
47 expect(resized.estimatedRowHeight).toBe(original.estimatedRowHeight);
48 expect(resized.textSizeKey).not.toBe(original.textSizeKey);
49 }
50 });
51});
52
53describe("deriveThreadFeedInitialContentInset", () => {
54 // regression: #5585 land the first thread open above the composer on Android
55 it("does not double native iOS insets", () => {
56 expect(
57 deriveThreadFeedInitialContentInset({
58 platform: "ios",
59 usesNativeAutomaticInsets: true,
60 bottomContentInset: 174,
61 }),
62 ).toBeUndefined();
63 });
64});
65
66describe("native workspace sizing", () => {
67 it.each([
68 { width: 669, height: 951, hasHinge: true, nativeWorkspace: true, overlay: true },
69 { width: 951, height: 669, hasHinge: true, nativeWorkspace: true, overlay: false },
70 { width: 669, height: 951, hasHinge: false, nativeWorkspace: true, overlay: false },
71 { width: 669, height: 951, hasHinge: true, nativeWorkspace: false, overlay: false },
72 ])(
73 "overlays only a native unfolded portrait Duo sidebar: %j",
74 ({ overlay, nativeWorkspace, ...size }) => {
75 const nativeMetrics = {
76 ...size,
77 horizontalSizeClass: "regular" as const,
78 verticalBarEdge: "none" as const,
79 safeArea: { top: 24, bottom: 20, left: 0, right: 0 },
80 reservedRegions: [],
81 };
82 const layout = deriveLayout({ ...size, nativeMetrics, nativeWorkspace });
83 expect(layout.variant === "medium").toBe(overlay);
84 for (const primarySidebarPreferredVisible of [true, false]) {
85 expect(
86 deriveWorkspacePaneLayout({
87 layout,
88 viewportWidth: size.width,
89 primarySidebarPreferredVisible,
90 auxiliaryPanePreferredVisible: false,
91 }).contentPaneWidth,
92 ).toBe(
93 !overlay && primarySidebarPreferredVisible
94 ? size.width - (layout.listPaneWidth ?? 0)
95 : size.width,
96 );
97 }
98 },
99 );
100
101 it("keeps the detail mounted in a narrow iPad window while UIKit still has two columns", () => {
102 const nativeMetrics = {
103 width: 715,
104 height: 1013.5,
105 hasHinge: false,
106 horizontalSizeClass: "regular" as const,
107 verticalBarEdge: "none" as const,
108 safeArea: { top: 32, bottom: 20, left: 0, right: 0 },
109 reservedRegions: [],
110 };
111 expect(deriveLayout({ ...nativeMetrics, nativeMetrics, nativeWorkspace: true })).toMatchObject({
112 usesSplitView: true,
113 listPaneWidth: 280,
114 });
115 });
116
117 it.each([
118 { width: 600, horizontalSizeClass: "regular" as const, split: true },
119 { width: 599, horizontalSizeClass: "regular" as const, split: false },
120 { width: 715, horizontalSizeClass: "compact" as const, split: false },
121 ])("respects UIKit collapse and native column minimums: %j", ({ split, ...size }) => {
122 const nativeMetrics = {
123 ...size,
124 height: 800,
125 verticalBarEdge: "none" as const,
126 safeArea: { top: 32, bottom: 20, left: 0, right: 0 },
127 reservedRegions: [],
128 };
129 expect(
130 deriveLayout({ ...nativeMetrics, nativeMetrics, nativeWorkspace: true }).usesSplitView,
131 ).toBe(split);
132 });
133});
134
135describe("width classes", () => {
136 it.each([
137 { width: 599, height: 900, variant: "compact" },
138 { width: 600, height: 900, variant: "medium" },
139 { width: 719, height: 900, variant: "medium" },
140 { width: 720, height: 900, variant: "expanded" },
141 { width: 900, height: 599, variant: "compact" },
142 ] as const)("classes a window without native columns by size: %j", ({ variant, ...size }) => {
143 expect(deriveLayout(size).variant).toBe(variant);
144 });
145});
146
147describe("isPrimarySidebarPinned", () => {
148 // regression: #20406 sidebar toggle works on iPad and iPhone Duo
149 it("keeps compact native roots pinned so search cannot hide the sidebar for a later split", () => {
150 expect(
151 isPrimarySidebarPinned({ pathname: "/", nativeWorkspace: true, usesSplitView: false }),
152 ).toBe(true);
153 });
154});
155
156describe("deriveWorkspacePaneLayout", () => {
157 it.each([
158 { width: 1_194, height: 834, suppressed: false },
159 { width: 1_032, height: 1_376, suppressed: true },
160 ])(
161 "steps the sidebar aside for the native inspector only when the page gets too narrow ($width wide)",
162 ({ width, height, suppressed }) => {
163 const layout = deriveLayout({ width, height });
164 for (const primarySidebarPreferredVisible of [true, false]) {
165 expect(
166 deriveWorkspacePaneLayout({
167 layout,
168 viewportWidth: width,
169 nativeWorkspace: true,
170 primarySidebarPreferredVisible,
171 auxiliaryPanePreferredVisible: true,
172 nativeInspectorWidth: nativeInspectorColumnWidth({
173 viewportWidth: width,
174 horizontalSafeArea: 0,
175 fraction: 0.4,
176 }),
177 }),
178 ).toMatchObject({
179 primarySidebarVisible: primarySidebarPreferredVisible && !suppressed,
180 primarySidebarSuppressedByAuxiliary: primarySidebarPreferredVisible && suppressed,
181 auxiliaryPaneVisible: true,
182 });
183 }
184 },
185 );
186
187 it.each([
188 { viewportWidth: 1_376, horizontalSafeArea: 0 },
189 { viewportWidth: 951, horizontalSafeArea: 76 },
190 ])(
191 "never widens the native inspector past the page's minimum ($viewportWidth wide)",
192 ({ viewportWidth, horizontalSafeArea }) => {
193 const width = nativeInspectorColumnWidth({ viewportWidth, horizontalSafeArea, fraction: 1 });
194 expect(viewportWidth - horizontalSafeArea - width).toBeGreaterThanOrEqual(320);
195 },
196 );
197
198 it("keeps an explicitly hidden thread sidebar hidden when the file inspector is visible", () => {
199 const layout = deriveLayout({ width: 1_024, height: 1_366 });
200
201 expect(
202 deriveWorkspacePaneLayout({
203 layout,
204 viewportWidth: 1_024,
205 primarySidebarPreferredVisible: false,
206 auxiliaryPanePreferredVisible: true,
207 }),
208 ).toMatchObject({
209 primarySidebarVisible: false,
210 primarySidebarSuppressedByAuxiliary: false,
211 auxiliaryPaneVisible: true,
212 });
213 });
214});
215
216describe("alignListPaneToHinge", () => {
217 const layout = deriveLayout({ width: 852, height: 880 });
218
219 it("keeps the default split when either side of the hinge would be too narrow", () => {
220 const narrowList = {
221 layout,
222 hinge: { x: 300, width: 0 },
223 viewportWidth: 852,
224 leadingWidth: 96,
225 };
226 const narrowDetail = {
227 layout,
228 hinge: { x: 600, width: 0 },
229 viewportWidth: 852,
230 leadingWidth: 0,
231 };
232 expect(alignListPaneToHinge(narrowList)).toBe(layout);
233 expect(alignListPaneToHinge(narrowDetail)).toBe(layout);
234 });
235});