The best way to control Claude Code, Codex and more from any computer or phone

main
ts 225 lines 8.13 KB
Raw
1 import { describe, expect, it } from "vite-plus/test";
2
3 import {
4 alignListPaneToHinge,
5 deriveLayout,
6 deriveThreadArrangementSizing,
7 deriveThreadWorkLogSizing,
8 deriveWorkspacePaneLayout,
9 nativeInspectorColumnWidth,
10 isPrimarySidebarPinned,
11 } from "./layout";
12
13 describe("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
25 describe("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
52 describe("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.variant === "medium").toBe(overlay);
70 expect(layout.listPaneWidth).toBe(overlay ? 350 : size.width === 951 ? 304 : 280);
71 for (const primarySidebarPreferredVisible of [true, false]) {
72 expect(
73 deriveWorkspacePaneLayout({
74 layout,
75 viewportWidth: size.width,
76 primarySidebarPreferredVisible,
77 auxiliaryPanePreferredVisible: false,
78 }).contentPaneWidth,
79 ).toBe(
80 !overlay && primarySidebarPreferredVisible
81 ? size.width - (layout.listPaneWidth ?? 0)
82 : size.width,
83 );
84 }
85 },
86 );
87
88 it("keeps the detail mounted in a narrow iPad window while UIKit still has two columns", () => {
89 const nativeMetrics = {
90 width: 715,
91 height: 1013.5,
92 hasHinge: false,
93 horizontalSizeClass: "regular" as const,
94 verticalBarEdge: "none" as const,
95 safeArea: { top: 32, bottom: 20, left: 0, right: 0 },
96 reservedRegions: [],
97 };
98 expect(deriveLayout({ ...nativeMetrics, nativeMetrics, nativeWorkspace: true })).toMatchObject({
99 usesSplitView: true,
100 listPaneWidth: 280,
101 });
102 });
103
104 it.each([
105 { width: 600, horizontalSizeClass: "regular" as const, split: true },
106 { width: 599, horizontalSizeClass: "regular" as const, split: false },
107 { width: 715, horizontalSizeClass: "compact" as const, split: false },
108 ])("respects UIKit collapse and native column minimums: %j", ({ split, ...size }) => {
109 const nativeMetrics = {
110 ...size,
111 height: 800,
112 verticalBarEdge: "none" as const,
113 safeArea: { top: 32, bottom: 20, left: 0, right: 0 },
114 reservedRegions: [],
115 };
116 expect(
117 deriveLayout({ ...nativeMetrics, nativeMetrics, nativeWorkspace: true }).usesSplitView,
118 ).toBe(split);
119 });
120 });
121
122 describe("width classes", () => {
123 it.each([
124 { width: 599, height: 900, variant: "compact" },
125 { width: 600, height: 900, variant: "medium" },
126 { width: 719, height: 900, variant: "medium" },
127 { width: 720, height: 900, variant: "expanded" },
128 { width: 900, height: 599, variant: "compact" },
129 ] as const)("classes a window without native columns by size: %j", ({ variant, ...size }) => {
130 expect(deriveLayout(size).variant).toBe(variant);
131 });
132 });
133
134 describe("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
143 describe("deriveWorkspacePaneLayout", () => {
144 it.each([
145 { width: 1_194, height: 834, horizontalSafeArea: 0, fraction: 0.4, suppressed: false },
146 { width: 1_032, height: 1_376, horizontalSafeArea: 0, fraction: 0.4, suppressed: true },
147 // The unfolded Duo's system bar leaves no room for the sidebar beside even the narrowest inspector.
148 { width: 951, height: 669, horizontalSafeArea: 76, fraction: 0, suppressed: true },
149 ])(
150 "steps the sidebar aside for the native inspector only when the page gets too narrow ($width wide)",
151 ({ width, height, horizontalSafeArea, fraction, suppressed }) => {
152 const layout = deriveLayout({ width, height });
153 for (const primarySidebarPreferredVisible of [true, false]) {
154 expect(
155 deriveWorkspacePaneLayout({
156 layout,
157 viewportWidth: width,
158 horizontalSafeArea,
159 nativeWorkspace: true,
160 primarySidebarPreferredVisible,
161 auxiliaryPanePreferredVisible: true,
162 nativeInspectorWidth: nativeInspectorColumnWidth({
163 viewportWidth: width,
164 horizontalSafeArea,
165 fraction,
166 }),
167 }),
168 ).toMatchObject({
169 primarySidebarVisible: primarySidebarPreferredVisible && !suppressed,
170 primarySidebarSuppressedByAuxiliary: primarySidebarPreferredVisible && suppressed,
171 auxiliaryPaneVisible: true,
172 });
173 }
174 },
175 );
176
177 it.each([
178 { viewportWidth: 1_376, horizontalSafeArea: 0 },
179 { viewportWidth: 951, horizontalSafeArea: 76 },
180 ])(
181 "never widens the native inspector past the page's minimum ($viewportWidth wide)",
182 ({ viewportWidth, horizontalSafeArea }) => {
183 const width = nativeInspectorColumnWidth({ viewportWidth, horizontalSafeArea, fraction: 1 });
184 expect(viewportWidth - horizontalSafeArea - width).toBeGreaterThanOrEqual(320);
185 },
186 );
187
188 it("keeps an explicitly hidden thread sidebar hidden when the file inspector is visible", () => {
189 const layout = deriveLayout({ width: 1_024, height: 1_366 });
190
191 expect(
192 deriveWorkspacePaneLayout({
193 layout,
194 viewportWidth: 1_024,
195 primarySidebarPreferredVisible: false,
196 auxiliaryPanePreferredVisible: true,
197 }),
198 ).toMatchObject({
199 primarySidebarVisible: false,
200 primarySidebarSuppressedByAuxiliary: false,
201 auxiliaryPaneVisible: true,
202 });
203 });
204 });
205
206 describe("alignListPaneToHinge", () => {
207 const layout = deriveLayout({ width: 852, height: 880 });
208
209 it("keeps the default split when either side of the hinge would be too narrow", () => {
210 const narrowList = {
211 layout,
212 hinge: { x: 300, width: 0 },
213 viewportWidth: 852,
214 leadingWidth: 96,
215 };
216 const narrowDetail = {
217 layout,
218 hinge: { x: 600, width: 0 },
219 viewportWidth: 852,
220 leadingWidth: 0,
221 };
222 expect(alignListPaneToHinge(narrowList)).toBe(layout);
223 expect(alignListPaneToHinge(narrowDetail)).toBe(layout);
224 });
225 });