The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { afterEach, describe, expect, it, vi } from "vite-plus/test"; |
| 2 | |
| 3 | import { buildExpandedImagePreview, resolveMarkdownMediaPreview } from "./ExpandedImagePreview"; |
| 4 | |
| 5 | describe("resolveMarkdownMediaPreview", () => { |
| 6 | afterEach(() => { |
| 7 | vi.unstubAllGlobals(); |
| 8 | }); |
| 9 | |
| 10 | it.each([ |
| 11 | ["t3code:", "https:"], |
| 12 | ["t3code-dev:", "https:"], |
| 13 | ["http:", "http:"], |
| 14 | ["https:", "https:"], |
| 15 | ])( |
| 16 | "resolves protocol-relative media on %s without changing its source", |
| 17 | async (pageProtocol, mediaProtocol) => { |
| 18 | vi.stubGlobal("window", { location: { protocol: pageProtocol } }); |
| 19 | const source = "//cdn.example.com/recording.mp4?token=a%2FB&v=1#t=2"; |
| 20 | const preview = await resolveMarkdownMediaPreview({ |
| 21 | source, |
| 22 | createAssetUrl: async () => { |
| 23 | throw new Error("Remote media must not request a local asset URL."); |
| 24 | }, |
| 25 | }); |
| 26 | |
| 27 | expect(preview?.images[0]).toMatchObject({ |
| 28 | src: `${mediaProtocol}${source}`, |
| 29 | originalUrl: source, |
| 30 | actionsSource: { |
| 31 | src: `${mediaProtocol}${source}`, |
| 32 | reference: { kind: "url", url: source }, |
| 33 | }, |
| 34 | }); |
| 35 | }, |
| 36 | ); |
| 37 | }); |
| 38 | |
| 39 | describe("buildExpandedImagePreview", () => { |
| 40 | it("keeps MIME type for stored images without a filename extension", () => { |
| 41 | const preview = buildExpandedImagePreview( |
| 42 | [ |
| 43 | { |
| 44 | type: "image", |
| 45 | id: "heic-1", |
| 46 | name: "photo", |
| 47 | mimeType: "image/heic", |
| 48 | sizeBytes: 3, |
| 49 | previewUrl: "blob:heic", |
| 50 | }, |
| 51 | ], |
| 52 | "heic-1", |
| 53 | ); |
| 54 | expect(preview?.images[0]).toMatchObject({ |
| 55 | name: "photo", |
| 56 | mimeType: "image/heic", |
| 57 | src: "blob:heic", |
| 58 | }); |
| 59 | }); |
| 60 | }); |