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, 03:37 UTC
| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { |
| 4 | IMAGE_ATTACHMENT_MAX_EDGE, |
| 5 | downscalableImageMimeType, |
| 6 | fitImageAttachmentSize, |
| 7 | } from "./imageAttachmentSize.ts"; |
| 8 | |
| 9 | describe("downscalableImageMimeType", () => { |
| 10 | it.each([ |
| 11 | ["image/png", "image/png"], |
| 12 | ["image/jpeg", "image/jpeg"], |
| 13 | ["image/jpg", "image/jpeg"], |
| 14 | ["IMAGE/PNG", "image/png"], |
| 15 | ])("normalizes %s to %s", (input, expected) => { |
| 16 | expect(downscalableImageMimeType(input)).toBe(expected); |
| 17 | }); |
| 18 | |
| 19 | it.each(["image/gif", "image/webp", "text/plain"])("rejects %s", (input) => { |
| 20 | expect(downscalableImageMimeType(input)).toBeNull(); |
| 21 | }); |
| 22 | }); |
| 23 | |
| 24 | describe("fitImageAttachmentSize", () => { |
| 25 | it("returns null when the image already fits", () => { |
| 26 | expect(fitImageAttachmentSize({ width: 800, height: 600 })).toBeNull(); |
| 27 | expect( |
| 28 | fitImageAttachmentSize({ |
| 29 | width: IMAGE_ATTACHMENT_MAX_EDGE, |
| 30 | height: IMAGE_ATTACHMENT_MAX_EDGE, |
| 31 | }), |
| 32 | ).toBeNull(); |
| 33 | }); |
| 34 | |
| 35 | it("scales the longest edge down to the limit", () => { |
| 36 | expect(fitImageAttachmentSize({ width: 4000, height: 2000 })).toEqual({ |
| 37 | width: 2000, |
| 38 | height: 1000, |
| 39 | }); |
| 40 | }); |
| 41 | |
| 42 | it("clamps the short edge of extreme aspect ratios to at least 1px", () => { |
| 43 | expect(fitImageAttachmentSize({ width: 1, height: 10000 })).toEqual({ |
| 44 | width: 1, |
| 45 | height: IMAGE_ATTACHMENT_MAX_EDGE, |
| 46 | }); |
| 47 | }); |
| 48 | }); |