| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | import { EnvironmentId } from "@t3tools/contracts"; |
| 3 | import { filePreviewGallery } from "../../lib/filePreviewGallery"; |
| 4 | import { mediaVideoPreviewUri, mediaVideoThumbnailKey } from "../../lib/videoPreviewSource"; |
| 5 | import { pullRequestImageSource, pullRequestMediaSource } from "./pullRequestMediaSource"; |
| 6 | |
| 7 | const location = { environmentId: EnvironmentId.make("test"), cwd: "/repo" }; |
| 8 | const url = "https://github.com/user-attachments/assets/abc-123"; |
| 9 | |
| 10 | describe("PR media previews", () => { |
| 11 | it("keeps a video resource pending until resolved and accepts refreshed capabilities", () => { |
| 12 | const source = { |
| 13 | type: "media" as const, |
| 14 | name: "Video", |
| 15 | mimeType: "video/mp4", |
| 16 | ...pullRequestMediaSource(url, location), |
| 17 | }; |
| 18 | expect(mediaVideoPreviewUri(source, null)).toBeNull(); |
| 19 | expect(mediaVideoPreviewUri(source, "https://signed/first")).toBe("https://signed/first"); |
| 20 | expect(mediaVideoPreviewUri(source, "https://signed/renewed")).toBe("https://signed/renewed"); |
| 21 | expect(mediaVideoThumbnailKey(source)).toContain("github-media"); |
| 22 | }); |
| 23 | |
| 24 | it("keeps every gallery image resolvable and the tapped image appears only once", () => { |
| 25 | const first = pullRequestImageSource(url, location); |
| 26 | const second = pullRequestImageSource(`${url}-second`, location); |
| 27 | const selected = { ...second, sourceIdentifier: "tapped" }; |
| 28 | const gallery = filePreviewGallery(selected, [first, second]); |
| 29 | expect(gallery).toEqual([first, selected]); |
| 30 | expect(gallery.every((item) => "resource" in item)).toBe(true); |
| 31 | }); |
| 32 | |
| 33 | it("leaves custom-domain media as direct URLs", () => { |
| 34 | const external = "https://drop.example/file.mp4"; |
| 35 | expect(pullRequestMediaSource(external, location)).toEqual({ uri: external }); |
| 36 | }); |
| 37 | }); |