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

layout.test.ts

169 lines5.6 KB

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("keeps an explicitly hidden thread sidebar hidden when the file inspector is visible", () => {
132 const layout = deriveLayout({ width: 1_024, height: 1_366 });
133​
134 expect(
135 deriveWorkspacePaneLayout({
136 layout,
137 viewportWidth: 1_024,
138 primarySidebarPreferredVisible: false,
139 auxiliaryPanePreferredVisible: true,
140 auxiliaryPaneRole: "inspector",
141 }),
142 ).toMatchObject({
143 primarySidebarVisible: false,
144 primarySidebarSuppressedByAuxiliary: false,
145 auxiliaryPaneVisible: true,
146 });
147 });
148});
149​
150describe("alignListPaneToHinge", () => {
151 const layout = deriveLayout({ width: 852, height: 880 });
152​
153 it("keeps the default split when either side of the hinge would be too narrow", () => {
154 const narrowList = {
155 layout,
156 hinge: { x: 300, width: 0 },
157 viewportWidth: 852,
158 leadingWidth: 96,
159 };
160 const narrowDetail = {
161 layout,
162 hinge: { x: 600, width: 0 },
163 viewportWidth: 852,
164 leadingWidth: 0,
165 };
166 expect(alignListPaneToHinge(narrowList)).toBe(layout);
167 expect(alignListPaneToHinge(narrowDetail)).toBe(layout);
168 });
169});