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

reserved-regions.test.ts

111 lines3.9 KB

1import { describe, expect, it } from "vite-plus/test";
2import { deriveBottomControlInsets, type NativeLayoutMetrics } from "./reserved-regions";
3import { deriveLayout, deriveWorkspacePaneLayout } from "./layout";
4​
5const innerDisplay: NativeLayoutMetrics = {
6 width: 960,
7 height: 560,
8 horizontalSizeClass: "regular",
9 verticalBarEdge: "right",
10 safeArea: { top: 0, bottom: 20, left: 8, right: 72 },
11 reservedRegions: [],
12};
13​
14describe("bottom controls around reserved regions", () => {
15 it("keeps the editor entirely on one side of a book fold", () => {
16 const insets = deriveBottomControlInsets({
17 ...innerDisplay,
18 reservedRegions: [{ kind: "division", x: 456, y: 0, width: 48, height: 560 }],
19 });
20 expect(insets).toEqual({ left: 8, right: 504, bottom: 0 });
21 expect(innerDisplay.width - insets.left - insets.right).toBeGreaterThan(320);
22 });
23​
24 it("does not reserve a hinge twice when a native column starts at the division", () => {
25 expect(
26 deriveBottomControlInsets({
27 ...innerDisplay,
28 width: 412,
29 safeArea: { top: 82, bottom: 34, left: 0, right: 0 },
30 reservedRegions: [{ kind: "division", x: 0, y: 0, width: 40, height: 560 }],
31 }),
32 ).toEqual({ left: 0, right: 0, bottom: 0 });
33 });
34​
35 it("keeps a native column's trailing division at its existing edge", () => {
36 expect(
37 deriveBottomControlInsets({
38 ...innerDisplay,
39 width: 456,
40 safeArea: { top: 82, bottom: 34, left: 0, right: 0 },
41 reservedRegions: [{ kind: "division", x: 455.75, y: 0, width: 0.25, height: 560 }],
42 }),
43 ).toEqual({ left: 0, right: 0, bottom: 0 });
44 });
45​
46 it("keeps controls below a horizontal fold in a hands-free pose", () => {
47 expect(
48 deriveBottomControlInsets({
49 ...innerDisplay,
50 reservedRegions: [{ kind: "division", x: 0, y: 240, width: 960, height: 40 }],
51 }),
52 ).toEqual({ left: 8, right: 72, bottom: 0 });
53 });
54​
55 it("moves a control away from a bottom camera while leaving a top camera alone", () => {
56 expect(
57 deriveBottomControlInsets({
58 ...innerDisplay,
59 reservedRegions: [
60 { kind: "occlusion", x: 8, y: 0, width: 60, height: 60 },
61 { kind: "occlusion", x: 8, y: 510, width: 60, height: 50 },
62 ],
63 }),
64 ).toEqual({ left: 68, right: 72, bottom: 0 });
65 });
66});
67​
68describe("Duo workspace sizing", () => {
69 it("shows both columns on the unfolded inner display in portrait", () => {
70 // Reported by the iOS 27.1 Duo simulator: no side bar or fold, only the hinge.
71 const portrait: NativeLayoutMetrics = {
72 width: 669,
73 height: 951,
74 hasHinge: true,
75 horizontalSizeClass: "regular",
76 verticalBarEdge: "none",
77 safeArea: { top: 82, bottom: 34, left: 0, right: 0 },
78 reservedRegions: [{ kind: "occlusion", x: 535, y: 0, width: 134, height: 82 }],
79 };
80 expect(deriveLayout({ ...portrait, nativeMetrics: portrait }).usesSplitView).toBe(true);
81 const withoutHinge = { ...portrait, hasHinge: false };
82 expect(deriveLayout({ ...withoutHinge, nativeMetrics: withoutHinge }).usesSplitView).toBe(
83 false,
84 );
85 });
86​
87 it("aligns the panes to the book fold and accounts for the reserved gap", () => {
88 const metrics = {
89 ...innerDisplay,
90 reservedRegions: [{ kind: "division" as const, x: 456, y: 0, width: 48, height: 560 }],
91 };
92 const layout = deriveLayout({ ...metrics, nativeMetrics: metrics });
93 expect(layout.listPaneWidth).toBe(456);
94 expect(layout.listPaneGap).toBe(48);
95 const panes = deriveWorkspacePaneLayout({
96 layout,
97 viewportWidth: 960,
98 primarySidebarPreferredVisible: true,
99 auxiliaryPanePreferredVisible: false,
100 });
101 expect(panes.contentPaneWidth).toBe(456);
102 expect(
103 deriveWorkspacePaneLayout({
104 layout,
105 viewportWidth: 960,
106 primarySidebarPreferredVisible: false,
107 auxiliaryPanePreferredVisible: false,
108 }).contentPaneWidth,
109 ).toBe(960);
110 });
111});