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

layout.test.ts

202 lines6.9 KB

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