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 { expect, it } from "vite-plus/test"; |
| 2 | import { bufferedViewport, cachedViewport, retainCachedViewport } from "./sheet-viewport"; |
| 3 | |
| 4 | it.each([ |
| 5 | { x: 150, y: 400, expected: { x: 150, y: 400 } }, |
| 6 | { x: 50, y: 100, expected: { x: 100, y: 300 } }, |
| 7 | { x: 500, y: 1000, expected: { x: 300, y: 700 } }, |
| 8 | ])("keeps a viewport at ($x, $y) inside the cached bitmap", ({ x, y, expected }) => { |
| 9 | expect( |
| 10 | cachedViewport({ x: 100, y: 300, width: 800, height: 1000 }, { x, y, width: 600, height: 600 }), |
| 11 | ).toEqual(expected); |
| 12 | }); |
| 13 | |
| 14 | it("keeps the cache origin when a resized viewport is larger than the bitmap", () => { |
| 15 | expect( |
| 16 | cachedViewport( |
| 17 | { x: 100, y: 300, width: 400, height: 400 }, |
| 18 | { x: 50, y: 100, width: 600, height: 600 }, |
| 19 | ), |
| 20 | ).toEqual({ x: 100, y: 300 }); |
| 21 | }); |
| 22 | |
| 23 | it.each([ |
| 24 | { x: 0, y: 0 }, |
| 25 | { x: 50, y: 100 }, |
| 26 | { x: 1000, y: 2000 }, |
| 27 | ])("buffers both scroll directions without going past the sheet origin ($x, $y)", (point) => { |
| 28 | const viewport = { ...point, width: 600, height: 600 }; |
| 29 | const frame = bufferedViewport(viewport); |
| 30 | expect(frame.x).toBe(Math.max(0, point.x - 128)); |
| 31 | expect(frame.y).toBe(Math.max(0, point.y - 200)); |
| 32 | expect(frame.x + frame.width).toBe(point.x + viewport.width + 128); |
| 33 | expect(frame.y + frame.height).toBe(point.y + viewport.height + 200); |
| 34 | expect(cachedViewport(frame, viewport)).toEqual(point); |
| 35 | }); |
| 36 | |
| 37 | it.each([ |
| 38 | { cachedX: 0, incomingX: 1000, currentX: 0, expected: true }, |
| 39 | { cachedX: 0, incomingX: 1000, currentX: 1000, expected: false }, |
| 40 | { cachedX: 0, incomingX: 1000, currentX: 2000, expected: false }, |
| 41 | { cachedX: 0, incomingX: 100, currentX: 200, expected: false }, |
| 42 | ])( |
| 43 | "retains useful cached cells when a distant frame arrives at $currentX", |
| 44 | ({ cachedX, incomingX, currentX, expected }) => { |
| 45 | const size = { y: 0, width: 800, height: 800 }; |
| 46 | expect( |
| 47 | retainCachedViewport( |
| 48 | { ...size, x: cachedX }, |
| 49 | { ...size, x: incomingX }, |
| 50 | { ...size, x: currentX, width: 400, height: 400 }, |
| 51 | ), |
| 52 | ).toBe(expected); |
| 53 | }, |
| 54 | ); |