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

reserved-regions.test.ts

90 lines3.2 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("keeps controls below a horizontal fold in a hands-free pose", () => {
25 expect(
26 deriveBottomControlInsets({
27 ...innerDisplay,
28 reservedRegions: [{ kind: "division", x: 0, y: 240, width: 960, height: 40 }],
29 }),
30 ).toEqual({ left: 8, right: 72, bottom: 0 });
31 });
32​
33 it("moves a control away from a bottom camera while leaving a top camera alone", () => {
34 expect(
35 deriveBottomControlInsets({
36 ...innerDisplay,
37 reservedRegions: [
38 { kind: "occlusion", x: 8, y: 0, width: 60, height: 60 },
39 { kind: "occlusion", x: 8, y: 510, width: 60, height: 50 },
40 ],
41 }),
42 ).toEqual({ left: 68, right: 72, bottom: 0 });
43 });
44});
45​
46describe("Duo workspace sizing", () => {
47 it("shows both columns on the unfolded inner display in portrait", () => {
48 // Reported by the iOS 27.1 Duo simulator: no side bar or fold, only the hinge.
49 const portrait: NativeLayoutMetrics = {
50 width: 669,
51 height: 951,
52 hasHinge: true,
53 horizontalSizeClass: "regular",
54 verticalBarEdge: "none",
55 safeArea: { top: 82, bottom: 34, left: 0, right: 0 },
56 reservedRegions: [{ kind: "occlusion", x: 535, y: 0, width: 134, height: 82 }],
57 };
58 expect(deriveLayout({ ...portrait, nativeMetrics: portrait }).usesSplitView).toBe(true);
59 // Without the hinge, the same window is an ordinary narrow iPad-style window.
60 const withoutHinge = { ...portrait, hasHinge: false };
61 expect(deriveLayout({ ...withoutHinge, nativeMetrics: withoutHinge }).usesSplitView).toBe(
62 false,
63 );
64 });
65​
66 it("aligns the panes to the book fold and accounts for the reserved gap", () => {
67 const metrics = {
68 ...innerDisplay,
69 reservedRegions: [{ kind: "division" as const, x: 456, y: 0, width: 48, height: 560 }],
70 };
71 const layout = deriveLayout({ ...metrics, nativeMetrics: metrics });
72 expect(layout.listPaneWidth).toBe(456);
73 expect(layout.listPaneGap).toBe(48);
74 const panes = deriveWorkspacePaneLayout({
75 layout,
76 viewportWidth: 960,
77 primarySidebarPreferredVisible: true,
78 auxiliaryPanePreferredVisible: false,
79 });
80 expect(panes.contentPaneWidth).toBe(456);
81 expect(
82 deriveWorkspacePaneLayout({
83 layout,
84 viewportWidth: 960,
85 primarySidebarPreferredVisible: false,
86 auxiliaryPanePreferredVisible: false,
87 }).contentPaneWidth,
88 ).toBe(960);
89 });
90});