The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | import { |
| 3 | deriveBottomControlInsets, |
| 4 | deriveContentSideInsets, |
| 5 | deriveSharedTopBand, |
| 6 | type NativeLayoutMetrics, |
| 7 | } from "./reserved-regions"; |
| 8 | import { deriveLayout, deriveWorkspacePaneLayout } from "./layout"; |
| 9 | |
| 10 | const innerDisplay: NativeLayoutMetrics = { |
| 11 | width: 960, |
| 12 | height: 560, |
| 13 | horizontalSizeClass: "regular", |
| 14 | verticalBarEdge: "right", |
| 15 | safeArea: { top: 0, bottom: 20, left: 8, right: 72 }, |
| 16 | reservedRegions: [], |
| 17 | }; |
| 18 | |
| 19 | describe("bottom controls around reserved regions", () => { |
| 20 | it("keeps the editor entirely on one side of a book fold", () => { |
| 21 | const insets = deriveBottomControlInsets({ |
| 22 | ...innerDisplay, |
| 23 | reservedRegions: [{ kind: "division", x: 456, y: 0, width: 48, height: 560 }], |
| 24 | }); |
| 25 | expect(insets).toEqual({ left: 8, right: 504, bottom: 0 }); |
| 26 | expect(innerDisplay.width - insets.left - insets.right).toBeGreaterThan(320); |
| 27 | }); |
| 28 | |
| 29 | it("starts the editor after a fold that covers a native column's leading edge", () => { |
| 30 | expect( |
| 31 | deriveBottomControlInsets({ |
| 32 | ...innerDisplay, |
| 33 | width: 411.33, |
| 34 | height: 669, |
| 35 | safeArea: { top: 82, bottom: 34, left: 0, right: 0 }, |
| 36 | reservedRegions: [{ kind: "division", x: 0, y: 0, width: 39.83, height: 669 }], |
| 37 | }), |
| 38 | ).toEqual({ left: 39.83, right: 0, bottom: 0 }); |
| 39 | }); |
| 40 | |
| 41 | it("does not reserve a hinge twice when the safe area already covers it", () => { |
| 42 | expect( |
| 43 | deriveBottomControlInsets({ |
| 44 | ...innerDisplay, |
| 45 | width: 412, |
| 46 | safeArea: { top: 82, bottom: 34, left: 40, right: 0 }, |
| 47 | reservedRegions: [{ kind: "division", x: 0, y: 0, width: 40, height: 560 }], |
| 48 | }), |
| 49 | ).toEqual({ left: 40, right: 0, bottom: 0 }); |
| 50 | }); |
| 51 | |
| 52 | it("keeps controls below a horizontal fold in a hands-free pose", () => { |
| 53 | expect( |
| 54 | deriveBottomControlInsets({ |
| 55 | ...innerDisplay, |
| 56 | reservedRegions: [{ kind: "division", x: 0, y: 240, width: 960, height: 40 }], |
| 57 | }), |
| 58 | ).toEqual({ left: 8, right: 72, bottom: 0 }); |
| 59 | }); |
| 60 | |
| 61 | it("moves a control away from a bottom camera while leaving a top camera alone", () => { |
| 62 | expect( |
| 63 | deriveBottomControlInsets({ |
| 64 | ...innerDisplay, |
| 65 | reservedRegions: [ |
| 66 | { kind: "occlusion", x: 8, y: 0, width: 60, height: 60 }, |
| 67 | { kind: "occlusion", x: 8, y: 510, width: 60, height: 50 }, |
| 68 | ], |
| 69 | }), |
| 70 | ).toEqual({ left: 68, right: 72, bottom: 0 }); |
| 71 | }); |
| 72 | }); |
| 73 | |
| 74 | describe("content side insets around reserved regions", () => { |
| 75 | it("keeps transcript text on the wider side of a book fold", () => { |
| 76 | expect( |
| 77 | deriveContentSideInsets({ |
| 78 | ...innerDisplay, |
| 79 | reservedRegions: [{ kind: "division", x: 456, y: 0, width: 48, height: 560 }], |
| 80 | }), |
| 81 | ).toEqual({ left: 8, right: 504 }); |
| 82 | expect( |
| 83 | deriveContentSideInsets({ |
| 84 | ...innerDisplay, |
| 85 | width: 800, |
| 86 | reservedRegions: [{ kind: "division", x: 240, y: 0, width: 40, height: 560 }], |
| 87 | }), |
| 88 | ).toEqual({ left: 280, right: 72 }); |
| 89 | }); |
| 90 | |
| 91 | it("starts transcript text after a fold that covers a native column's leading edge", () => { |
| 92 | expect( |
| 93 | deriveContentSideInsets({ |
| 94 | ...innerDisplay, |
| 95 | width: 411.33, |
| 96 | height: 669, |
| 97 | safeArea: { top: 82, bottom: 34, left: 0, right: 0 }, |
| 98 | reservedRegions: [{ kind: "division", x: 0, y: 0, width: 39.83, height: 669 }], |
| 99 | }), |
| 100 | ).toEqual({ left: 39.83, right: 0 }); |
| 101 | }); |
| 102 | |
| 103 | it("ends transcript text before a fold at a native column's trailing edge", () => { |
| 104 | expect( |
| 105 | deriveContentSideInsets({ |
| 106 | ...innerDisplay, |
| 107 | width: 456, |
| 108 | safeArea: { top: 82, bottom: 34, left: 0, right: 0 }, |
| 109 | reservedRegions: [{ kind: "division", x: 416, y: 0, width: 40, height: 560 }], |
| 110 | }), |
| 111 | ).toEqual({ left: 0, right: 40 }); |
| 112 | }); |
| 113 | |
| 114 | it("ignores a horizontal fold and bottom cameras", () => { |
| 115 | expect( |
| 116 | deriveContentSideInsets({ |
| 117 | ...innerDisplay, |
| 118 | reservedRegions: [ |
| 119 | { kind: "division", x: 0, y: 240, width: 960, height: 40 }, |
| 120 | { kind: "occlusion", x: 8, y: 510, width: 60, height: 50 }, |
| 121 | ], |
| 122 | }), |
| 123 | ).toEqual({ left: 8, right: 72 }); |
| 124 | }); |
| 125 | }); |
| 126 | |
| 127 | describe("a bar sharing the top band with the system status", () => { |
| 128 | // The folded Duo with horizontal bars: its status block sits at the right of a tall top band. |
| 129 | const foldedDuo: NativeLayoutMetrics = { |
| 130 | width: 466, |
| 131 | height: 678, |
| 132 | horizontalSizeClass: "compact", |
| 133 | verticalBarEdge: "none", |
| 134 | safeArea: { top: 82, bottom: 34, left: 0, right: 0 }, |
| 135 | reservedRegions: [ |
| 136 | { kind: "occlusion", x: 399.67, y: 29.33, width: 37, height: 37 }, |
| 137 | { kind: "occlusion", x: 266, y: 0, width: 200, height: 82 }, |
| 138 | ], |
| 139 | }; |
| 140 | |
| 141 | it.each([ |
| 142 | ["status block on the right", foldedDuo, { height: 82, left: 0, right: 200 }], |
| 143 | [ |
| 144 | "status block on the left", |
| 145 | { |
| 146 | ...foldedDuo, |
| 147 | reservedRegions: [{ kind: "occlusion" as const, x: 0, y: 0, width: 200, height: 82 }], |
| 148 | }, |
| 149 | { height: 82, left: 200, right: 0 }, |
| 150 | ], |
| 151 | ["no status block (a notch or island)", { ...foldedDuo, reservedRegions: [] }, null], |
| 152 | [ |
| 153 | "a block across the middle", |
| 154 | { |
| 155 | ...foldedDuo, |
| 156 | reservedRegions: [{ kind: "occlusion" as const, x: 133, y: 0, width: 200, height: 82 }], |
| 157 | }, |
| 158 | null, |
| 159 | ], |
| 160 | ["no top safe area", { ...foldedDuo, safeArea: { ...foldedDuo.safeArea, top: 0 } }, null], |
| 161 | ])("%s", (_, metrics, expected) => { |
| 162 | expect(deriveSharedTopBand(metrics)).toEqual(expected); |
| 163 | }); |
| 164 | }); |
| 165 | |
| 166 | describe("Duo workspace sizing", () => { |
| 167 | it("shows both columns on the unfolded inner display in portrait", () => { |
| 168 | // Reported by the iOS 27.1 Duo simulator: no side bar or fold, only the hinge. |
| 169 | const portrait: NativeLayoutMetrics = { |
| 170 | width: 669, |
| 171 | height: 951, |
| 172 | hasHinge: true, |
| 173 | horizontalSizeClass: "regular", |
| 174 | verticalBarEdge: "none", |
| 175 | safeArea: { top: 82, bottom: 34, left: 0, right: 0 }, |
| 176 | reservedRegions: [{ kind: "occlusion", x: 535, y: 0, width: 134, height: 82 }], |
| 177 | }; |
| 178 | expect(deriveLayout({ ...portrait, nativeMetrics: portrait }).usesSplitView).toBe(true); |
| 179 | const withoutHinge = { ...portrait, hasHinge: false }; |
| 180 | expect(deriveLayout({ ...withoutHinge, nativeMetrics: withoutHinge }).usesSplitView).toBe( |
| 181 | false, |
| 182 | ); |
| 183 | }); |
| 184 | |
| 185 | it("aligns the panes to the book fold and accounts for the reserved gap", () => { |
| 186 | const metrics = { |
| 187 | ...innerDisplay, |
| 188 | reservedRegions: [{ kind: "division" as const, x: 456, y: 0, width: 48, height: 560 }], |
| 189 | }; |
| 190 | const layout = deriveLayout({ ...metrics, nativeMetrics: metrics }); |
| 191 | expect(layout.listPaneWidth).toBe(456); |
| 192 | expect(layout.listPaneGap).toBe(48); |
| 193 | const panes = deriveWorkspacePaneLayout({ |
| 194 | layout, |
| 195 | viewportWidth: 960, |
| 196 | primarySidebarPreferredVisible: true, |
| 197 | auxiliaryPanePreferredVisible: false, |
| 198 | }); |
| 199 | expect(panes.contentPaneWidth).toBe(456); |
| 200 | expect( |
| 201 | deriveWorkspacePaneLayout({ |
| 202 | layout, |
| 203 | viewportWidth: 960, |
| 204 | primarySidebarPreferredVisible: false, |
| 205 | auxiliaryPanePreferredVisible: false, |
| 206 | }).contentPaneWidth, |
| 207 | ).toBe(960); |
| 208 | }); |
| 209 | }); |