Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import { EnvironmentId } from "@t3tools/contracts";
3import { filePreviewGallery } from "../../lib/filePreviewGallery";
4import { pullRequestImageSource, pullRequestMediaUri } from "./pullRequestMediaSource";
5
6const location = {
7 environmentId: EnvironmentId.make("test"),
8 cwd: "/repo",
9 repository: "enterprise/private",
10};
11const url = "https://github.com/user-attachments/assets/abc-123";
12
13describe("PR media previews", () => {
14 it("keeps every gallery image resolvable and the tapped image appears only once", () => {
15 const first = pullRequestImageSource(url, location);
16 const second = pullRequestImageSource(`${url}-second`, location);
17 const selected = { ...second, sourceIdentifier: "tapped" };
18 const gallery = filePreviewGallery(selected, [first, second]);
19 expect(gallery).toEqual([first, selected]);
20 expect(gallery).toMatchObject([
21 { resource: { url, repository: location.repository } },
22 { resource: { url: `${url}-second`, repository: location.repository } },
23 ]);
24 });
25
26 it("loads media directly when the connected server will not proxy its host", () => {
27 const source = "https://source.tanstack.com/acme/app/assets/shot.png";
28 expect(pullRequestMediaUri(source, true, { _tag: "Failure", reason: "failed" })).toEqual({
29 uri: source,
30 proxied: false,
31 unavailable: false,
32 });
33 expect(pullRequestMediaUri(source, true, { _tag: "Failure", reason: "disconnected" })).toEqual({
34 uri: null,
35 proxied: true,
36 unavailable: true,
37 });
38 expect(pullRequestMediaUri(source, true, { _tag: "Loading" })).toEqual({
39 uri: null,
40 proxied: true,
41 unavailable: false,
42 });
43 });
44});