| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | import type { MarkdownNode } from "../../lib/markdownDocument"; |
| 3 | import { splitPullRequestBody } from "@t3tools/client-runtime/pull-request-markdown"; |
| 4 | import { pullRequestDescriptionContent } from "./pullRequestDescriptionContent"; |
| 5 | |
| 6 | describe("PR attachments", () => { |
| 7 | it("combines embedded images and detected media without duplicate URLs", () => { |
| 8 | const uri = "https://drop.example.com/shot.png"; |
| 9 | const document = { |
| 10 | type: "root", |
| 11 | children: [ |
| 12 | { type: "image", url: uri, alt: "Screenshot" }, |
| 13 | { type: "image", url: uri, alt: "Duplicate" }, |
| 14 | ], |
| 15 | } as MarkdownNode; |
| 16 | const media = splitPullRequestBody( |
| 17 | `${uri}\n\nhttps://drop.example.com/demo.mp4\n\nhttps://github.com/user-attachments/assets/123-abc`, |
| 18 | ); |
| 19 | expect(pullRequestDescriptionContent(document, media).attachments).toEqual([ |
| 20 | { uri, caption: "Screenshot", kind: "image" }, |
| 21 | { uri: "https://drop.example.com/demo.mp4", caption: "Video", kind: "video" }, |
| 22 | { |
| 23 | uri: "https://github.com/user-attachments/assets/123-abc", |
| 24 | caption: "Video", |
| 25 | kind: "video", |
| 26 | }, |
| 27 | ]); |
| 28 | }); |
| 29 | |
| 30 | it("does not collect ordinary links or media examples in code", () => { |
| 31 | const media = splitPullRequestBody( |
| 32 | "https://example.com/docs\n\n```\nhttps://drop.example.com/demo.mp4\n```", |
| 33 | ); |
| 34 | expect( |
| 35 | pullRequestDescriptionContent({ type: "root" } as MarkdownNode, media).attachments, |
| 36 | ).toEqual([]); |
| 37 | }); |
| 38 | }); |