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

reserved-regions.test.ts

169 lines5.7 KB

1import { describe, expect, it } from "vite-plus/test";
2import {
3 deriveBottomControlInsets,
4 deriveContentSideInsets,
5 type NativeLayoutMetrics,
6} from "./reserved-regions";
7import { deriveLayout, deriveWorkspacePaneLayout } from "./layout";
8​
9const innerDisplay: NativeLayoutMetrics = {
10 width: 960,
11 height: 560,
12 horizontalSizeClass: "regular",
13 verticalBarEdge: "right",
14 safeArea: { top: 0, bottom: 20, left: 8, right: 72 },
15 reservedRegions: [],
16};
17​
18describe("bottom controls around reserved regions", () => {
19 it("keeps the editor entirely on one side of a book fold", () => {
20 const insets = deriveBottomControlInsets({
21 ...innerDisplay,
22 reservedRegions: [{ kind: "division", x: 456, y: 0, width: 48, height: 560 }],
23 });
24 expect(insets).toEqual({ left: 8, right: 504, bottom: 0 });
25 expect(innerDisplay.width - insets.left - insets.right).toBeGreaterThan(320);
26 });
27​
28 it("starts the editor after a fold that covers a native column's leading edge", () => {
29 expect(
30 deriveBottomControlInsets({
31 ...innerDisplay,
32 width: 411.33,
33 height: 669,
34 safeArea: { top: 82, bottom: 34, left: 0, right: 0 },
35 reservedRegions: [{ kind: "division", x: 0, y: 0, width: 39.83, height: 669 }],
36 }),
37 ).toEqual({ left: 39.83, right: 0, bottom: 0 });
38 });
39​
40 it("does not reserve a hinge twice when the safe area already covers it", () => {
41 expect(
42 deriveBottomControlInsets({
43 ...innerDisplay,
44 width: 412,
45 safeArea: { top: 82, bottom: 34, left: 40, right: 0 },
46 reservedRegions: [{ kind: "division", x: 0, y: 0, width: 40, height: 560 }],
47 }),
48 ).toEqual({ left: 40, right: 0, bottom: 0 });
49 });
50​
51 it("keeps controls below a horizontal fold in a hands-free pose", () => {
52 expect(
53 deriveBottomControlInsets({
54 ...innerDisplay,
55 reservedRegions: [{ kind: "division", x: 0, y: 240, width: 960, height: 40 }],
56 }),
57 ).toEqual({ left: 8, right: 72, bottom: 0 });
58 });
59​
60 it("moves a control away from a bottom camera while leaving a top camera alone", () => {
61 expect(
62 deriveBottomControlInsets({
63 ...innerDisplay,
64 reservedRegions: [
65 { kind: "occlusion", x: 8, y: 0, width: 60, height: 60 },
66 { kind: "occlusion", x: 8, y: 510, width: 60, height: 50 },
67 ],
68 }),
69 ).toEqual({ left: 68, right: 72, bottom: 0 });
70 });
71});
72​
73describe("content side insets around reserved regions", () => {
74 it("keeps transcript text on the wider side of a book fold", () => {
75 expect(
76 deriveContentSideInsets({
77 ...innerDisplay,
78 reservedRegions: [{ kind: "division", x: 456, y: 0, width: 48, height: 560 }],
79 }),
80 ).toEqual({ left: 8, right: 504 });
81 expect(
82 deriveContentSideInsets({
83 ...innerDisplay,
84 width: 800,
85 reservedRegions: [{ kind: "division", x: 240, y: 0, width: 40, height: 560 }],
86 }),
87 ).toEqual({ left: 280, right: 72 });
88 });
89​
90 it("starts transcript text after a fold that covers a native column's leading edge", () => {
91 expect(
92 deriveContentSideInsets({
93 ...innerDisplay,
94 width: 411.33,
95 height: 669,
96 safeArea: { top: 82, bottom: 34, left: 0, right: 0 },
97 reservedRegions: [{ kind: "division", x: 0, y: 0, width: 39.83, height: 669 }],
98 }),
99 ).toEqual({ left: 39.83, right: 0 });
100 });
101​
102 it("ends transcript text before a fold at a native column's trailing edge", () => {
103 expect(
104 deriveContentSideInsets({
105 ...innerDisplay,
106 width: 456,
107 safeArea: { top: 82, bottom: 34, left: 0, right: 0 },
108 reservedRegions: [{ kind: "division", x: 416, y: 0, width: 40, height: 560 }],
109 }),
110 ).toEqual({ left: 0, right: 40 });
111 });
112​
113 it("ignores a horizontal fold and bottom cameras", () => {
114 expect(
115 deriveContentSideInsets({
116 ...innerDisplay,
117 reservedRegions: [
118 { kind: "division", x: 0, y: 240, width: 960, height: 40 },
119 { kind: "occlusion", x: 8, y: 510, width: 60, height: 50 },
120 ],
121 }),
122 ).toEqual({ left: 8, right: 72 });
123 });
124});
125​
126describe("Duo workspace sizing", () => {
127 it("shows both columns on the unfolded inner display in portrait", () => {
128 // Reported by the iOS 27.1 Duo simulator: no side bar or fold, only the hinge.
129 const portrait: NativeLayoutMetrics = {
130 width: 669,
131 height: 951,
132 hasHinge: true,
133 horizontalSizeClass: "regular",
134 verticalBarEdge: "none",
135 safeArea: { top: 82, bottom: 34, left: 0, right: 0 },
136 reservedRegions: [{ kind: "occlusion", x: 535, y: 0, width: 134, height: 82 }],
137 };
138 expect(deriveLayout({ ...portrait, nativeMetrics: portrait }).usesSplitView).toBe(true);
139 const withoutHinge = { ...portrait, hasHinge: false };
140 expect(deriveLayout({ ...withoutHinge, nativeMetrics: withoutHinge }).usesSplitView).toBe(
141 false,
142 );
143 });
144​
145 it("aligns the panes to the book fold and accounts for the reserved gap", () => {
146 const metrics = {
147 ...innerDisplay,
148 reservedRegions: [{ kind: "division" as const, x: 456, y: 0, width: 48, height: 560 }],
149 };
150 const layout = deriveLayout({ ...metrics, nativeMetrics: metrics });
151 expect(layout.listPaneWidth).toBe(456);
152 expect(layout.listPaneGap).toBe(48);
153 const panes = deriveWorkspacePaneLayout({
154 layout,
155 viewportWidth: 960,
156 primarySidebarPreferredVisible: true,
157 auxiliaryPanePreferredVisible: false,
158 });
159 expect(panes.contentPaneWidth).toBe(456);
160 expect(
161 deriveWorkspacePaneLayout({
162 layout,
163 viewportWidth: 960,
164 primarySidebarPreferredVisible: false,
165 auxiliaryPanePreferredVisible: false,
166 }).contentPaneWidth,
167 ).toBe(960);
168 });
169});