The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { resolveChatCanvasLayout } from "../chat/chatCanvasLayout"; |
| 4 | import { |
| 5 | type PreviewMiniPlayerGesture, |
| 6 | settlePreviewMiniPlayerResize, |
| 7 | stepPreviewMiniPlayerGesture, |
| 8 | } from "./previewMiniPlayerGesture"; |
| 9 | |
| 10 | const container = { width: 1_440, height: 900 }; |
| 11 | const frame = { x: 996, y: 433, width: 268, height: 179 }; |
| 12 | const gesture: PreviewMiniPlayerGesture = { |
| 13 | pointerId: 1, |
| 14 | pointerType: "mouse", |
| 15 | pointerX: 996, |
| 16 | pointerY: 433, |
| 17 | frame, |
| 18 | direction: "northwest", |
| 19 | source: { width: 1_200, height: 800 }, |
| 20 | moved: true, |
| 21 | }; |
| 22 | const pointer = { pointerId: 1, buttons: 1, clientX: 936, clientY: 393 }; |
| 23 | |
| 24 | describe("stepPreviewMiniPlayerGesture", () => { |
| 25 | it("ends on a move without the primary button instead of following the hover", () => { |
| 26 | expect(stepPreviewMiniPlayerGesture(gesture, pointer, container).kind).toBe("resize"); |
| 27 | expect(stepPreviewMiniPlayerGesture(gesture, { ...pointer, buttons: 0 }, container)).toEqual({ |
| 28 | kind: "end", |
| 29 | }); |
| 30 | expect(stepPreviewMiniPlayerGesture(gesture, { ...pointer, buttons: 2 }, container)).toEqual({ |
| 31 | kind: "end", |
| 32 | }); |
| 33 | expect(stepPreviewMiniPlayerGesture(gesture, { ...pointer, pointerId: 2 }, container)).toEqual({ |
| 34 | kind: "ignore", |
| 35 | }); |
| 36 | }); |
| 37 | |
| 38 | it("resizes at the shape the gesture started with", () => { |
| 39 | const step = stepPreviewMiniPlayerGesture(gesture, pointer, container); |
| 40 | expect(step).toEqual({ kind: "resize", frame: { x: 936, y: 393, width: 328, height: 219 } }); |
| 41 | }); |
| 42 | }); |
| 43 | |
| 44 | describe("settlePreviewMiniPlayerResize", () => { |
| 45 | it("keeps the corner opposite the handle when the source changed shape mid-resize", () => { |
| 46 | const source = { width: 1_200, height: 1_000 }; |
| 47 | const settled = settlePreviewMiniPlayerResize({ |
| 48 | frame, |
| 49 | direction: "northwest", |
| 50 | held: gesture.source, |
| 51 | source, |
| 52 | container, |
| 53 | }); |
| 54 | expect(settled).toEqual({ x: 1_018, y: 407, width: 246, height: 205 }); |
| 55 | expect( |
| 56 | resolveChatCanvasLayout({ |
| 57 | container, |
| 58 | preview: { |
| 59 | key: "browser:tab", |
| 60 | width: settled!.width, |
| 61 | position: settled, |
| 62 | source, |
| 63 | lastInteraction: "resize", |
| 64 | }, |
| 65 | }).frame, |
| 66 | ).toEqual(settled); |
| 67 | expect( |
| 68 | settlePreviewMiniPlayerResize({ |
| 69 | frame, |
| 70 | direction: "northwest", |
| 71 | held: gesture.source, |
| 72 | source: { width: 600, height: 400 }, |
| 73 | container, |
| 74 | }), |
| 75 | ).toBeNull(); |
| 76 | }); |
| 77 | }); |