Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import {
4 alignListPaneToHinge,
5 deriveLayout,
6 deriveThreadFeedInitialContentInset,
7 deriveThreadWorkLogSizing,
8 deriveWorkspacePaneLayout,
9 isPrimarySidebarPinned,
10} from "./layout";
11
12describe("thread work-log text sizing", () => {
13 it.each([
14 { baseFontSize: 16, fontScale: 1.25, estimatedRowHeight: 28 },
15 { baseFontSize: 22, fontScale: 2, estimatedRowHeight: 52 },
16 ])(
17 "measures accessibility text instead of locking it to the estimate: %j",
18 ({ estimatedRowHeight, ...settings }) => {
19 expect(deriveThreadWorkLogSizing(settings)).toMatchObject({
20 estimatedRowHeight,
21 fixedRowHeight: undefined,
22 });
23 },
24 );
25
26 it("invalidates native text measurements even when the minimum row height is unchanged", () => {
27 const original = deriveThreadWorkLogSizing({ baseFontSize: 16, fontScale: 1 });
28 for (const settings of [
29 { baseFontSize: 16, fontScale: 1.1 },
30 { baseFontSize: 17, fontScale: 1 },
31 ]) {
32 const resized = deriveThreadWorkLogSizing(settings);
33 expect(resized.estimatedRowHeight).toBe(original.estimatedRowHeight);
34 expect(resized.textSizeKey).not.toBe(original.textSizeKey);
35 }
36 });
37});
38
39describe("deriveThreadFeedInitialContentInset", () => {
40 // regression: #5585 land the first thread open above the composer on Android
41 it("does not double native iOS insets", () => {
42 expect(
43 deriveThreadFeedInitialContentInset({
44 platform: "ios",
45 usesNativeAutomaticInsets: true,
46 bottomContentInset: 174,
47 }),
48 ).toBeUndefined();
49 });
50});
51
52describe("native workspace sizing", () => {
53 it.each([
54 { width: 669, height: 951, hasHinge: true, nativeWorkspace: true, overlay: true },
55 { width: 951, height: 669, hasHinge: true, nativeWorkspace: true, overlay: false },
56 { width: 669, height: 951, hasHinge: false, nativeWorkspace: true, overlay: false },
57 { width: 669, height: 951, hasHinge: true, nativeWorkspace: false, overlay: false },
58 ])(
59 "overlays only a native unfolded portrait Duo sidebar: %j",
60 ({ overlay, nativeWorkspace, ...size }) => {
61 const nativeMetrics = {
62 ...size,
63 horizontalSizeClass: "regular" as const,
64 verticalBarEdge: "none" as const,
65 safeArea: { top: 24, bottom: 20, left: 0, right: 0 },
66 reservedRegions: [],
67 };
68 const layout = deriveLayout({ ...size, nativeMetrics, nativeWorkspace });
69 expect(layout.primarySidebarOverlaysContent).toBe(overlay);
70 for (const primarySidebarPreferredVisible of [true, false]) {
71 expect(
72 deriveWorkspacePaneLayout({
73 layout,
74 viewportWidth: size.width,
75 primarySidebarPreferredVisible,
76 auxiliaryPanePreferredVisible: false,
77 }).contentPaneWidth,
78 ).toBe(
79 !overlay && primarySidebarPreferredVisible
80 ? size.width - (layout.listPaneWidth ?? 0)
81 : size.width,
82 );
83 }
84 },
85 );
86
87 it("keeps the detail mounted in a narrow iPad window while UIKit still has two columns", () => {
88 const nativeMetrics = {
89 width: 715,
90 height: 1013.5,
91 hasHinge: false,
92 horizontalSizeClass: "regular" as const,
93 verticalBarEdge: "none" as const,
94 safeArea: { top: 32, bottom: 20, left: 0, right: 0 },
95 reservedRegions: [],
96 };
97 expect(deriveLayout({ ...nativeMetrics, nativeMetrics, nativeWorkspace: true })).toMatchObject({
98 usesSplitView: true,
99 listPaneWidth: 280,
100 });
101 });
102
103 it.each([
104 { width: 600, horizontalSizeClass: "regular" as const, split: true },
105 { width: 599, horizontalSizeClass: "regular" as const, split: false },
106 { width: 715, horizontalSizeClass: "compact" as const, split: false },
107 ])("respects UIKit collapse and native column minimums: %j", ({ split, ...size }) => {
108 const nativeMetrics = {
109 ...size,
110 height: 800,
111 verticalBarEdge: "none" as const,
112 safeArea: { top: 32, bottom: 20, left: 0, right: 0 },
113 reservedRegions: [],
114 };
115 expect(
116 deriveLayout({ ...nativeMetrics, nativeMetrics, nativeWorkspace: true }).usesSplitView,
117 ).toBe(split);
118 });
119});
120
121describe("isPrimarySidebarPinned", () => {
122 // regression: #20406 sidebar toggle works on iPad and iPhone Duo
123 it("keeps compact native roots pinned so search cannot hide the sidebar for a later split", () => {
124 expect(
125 isPrimarySidebarPinned({ pathname: "/", nativeWorkspace: true, usesSplitView: false }),
126 ).toBe(true);
127 });
128});
129
130describe("deriveWorkspacePaneLayout", () => {
131 it("lets UIKit keep the sidebar independent of the inspector in landscape", () => {
132 const layout = deriveLayout({ width: 1_194, height: 834 });
133 for (const primarySidebarPreferredVisible of [true, false]) {
134 expect(
135 deriveWorkspacePaneLayout({
136 layout,
137 viewportWidth: 1_194,
138 nativeWorkspace: true,
139 primarySidebarPreferredVisible,
140 auxiliaryPanePreferredVisible: true,
141 auxiliaryPaneRole: "inspector",
142 }),
143 ).toMatchObject({
144 primarySidebarVisible: primarySidebarPreferredVisible,
145 primarySidebarSuppressedByAuxiliary: false,
146 auxiliaryPaneVisible: true,
147 });
148 }
149 });
150
151 it("keeps an explicitly hidden thread sidebar hidden when the file inspector is visible", () => {
152 const layout = deriveLayout({ width: 1_024, height: 1_366 });
153
154 expect(
155 deriveWorkspacePaneLayout({
156 layout,
157 viewportWidth: 1_024,
158 primarySidebarPreferredVisible: false,
159 auxiliaryPanePreferredVisible: true,
160 auxiliaryPaneRole: "inspector",
161 }),
162 ).toMatchObject({
163 primarySidebarVisible: false,
164 primarySidebarSuppressedByAuxiliary: false,
165 auxiliaryPaneVisible: true,
166 });
167 });
168});
169
170describe("alignListPaneToHinge", () => {
171 const layout = deriveLayout({ width: 852, height: 880 });
172
173 it("keeps the default split when either side of the hinge would be too narrow", () => {
174 const narrowList = {
175 layout,
176 hinge: { x: 300, width: 0 },
177 viewportWidth: 852,
178 leadingWidth: 96,
179 };
180 const narrowDetail = {
181 layout,
182 hinge: { x: 600, width: 0 },
183 viewportWidth: 852,
184 leadingWidth: 0,
185 };
186 expect(alignListPaneToHinge(narrowList)).toBe(layout);
187 expect(alignListPaneToHinge(narrowDetail)).toBe(layout);
188 });
189});