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 | |
| 3 | import { |
| 4 | resizeBrowserViewportFromRail, |
| 5 | resolveBrowserViewportTransform, |
| 6 | resolveFittedBrowserViewport, |
| 7 | } from "./browserViewportLayout"; |
| 8 | |
| 9 | describe("resolveBrowserViewportLayout", () => { |
| 10 | it("preserves the last logical viewport when fitting a fill-mode surface", () => { |
| 11 | expect( |
| 12 | resolveFittedBrowserViewport({ _tag: "fill" }, { width: 320, height: 200, scale: 0.25 }), |
| 13 | ).toEqual({ _tag: "freeform", width: 1280, height: 800 }); |
| 14 | }); |
| 15 | |
| 16 | it("keeps the grabbed rail under the pointer across centered layout boundaries", () => { |
| 17 | const available = { width: 1120, height: 818 }; |
| 18 | expect( |
| 19 | resizeBrowserViewportFromRail( |
| 20 | { width: 1120, height: 818 }, |
| 21 | { x: -100, y: -50 }, |
| 22 | available, |
| 23 | 1, |
| 24 | "southeast", |
| 25 | ), |
| 26 | ).toEqual({ width: 920, height: 718 }); |
| 27 | expect( |
| 28 | resizeBrowserViewportFromRail( |
| 29 | { width: 800, height: 600 }, |
| 30 | { x: 300, y: 0 }, |
| 31 | { width: 1200, height: 800 }, |
| 32 | 1, |
| 33 | "east", |
| 34 | ), |
| 35 | ).toEqual({ width: 1300, height: 600 }); |
| 36 | expect( |
| 37 | resizeBrowserViewportFromRail( |
| 38 | { width: 560, height: 409 }, |
| 39 | { x: -100, y: 0 }, |
| 40 | available, |
| 41 | 2, |
| 42 | "east", |
| 43 | ), |
| 44 | ).toEqual({ width: 460, height: 409 }); |
| 45 | }); |
| 46 | }); |
| 47 | |
| 48 | describe("resolveBrowserViewportTransform", () => { |
| 49 | it("keeps a full-detail guest at raster scale 1 while it draws at the fitted scale", () => { |
| 50 | expect(resolveBrowserViewportTransform(1, true)).toBeUndefined(); |
| 51 | expect(resolveBrowserViewportTransform(0.6, false)).toBe("scale(0.6)"); |
| 52 | const values = resolveBrowserViewportTransform(0.6, true) |
| 53 | ?.match(/^matrix3d\((.*)\)$/)?.[1] |
| 54 | ?.split(",") |
| 55 | .map(Number); |
| 56 | // Column-major: the x and y columns keep their 0.6 screen terms and reach length 1 through z. |
| 57 | expect(values?.slice(0, 2)).toEqual([0.6, 0]); |
| 58 | expect(values?.slice(4, 6)).toEqual([0, 0.6]); |
| 59 | expect(Math.hypot(...(values?.slice(0, 3) ?? []))).toBeCloseTo(1); |
| 60 | expect(Math.hypot(...(values?.slice(4, 7) ?? []))).toBeCloseTo(1); |
| 61 | }); |
| 62 | }); |