Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import { markdownReferenceDefinitions, type MarkdownNode } from "../../lib/markdownDocument";
3import { splitPullRequestBody } from "@t3tools/client-runtime/pull-request-markdown";
4import { pullRequestDescriptionContent } from "./pullRequestDescriptionContent";
5
6describe("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 markdownReferenceDefinitions,
19 );
20 expect(pullRequestDescriptionContent(document, media).attachments).toEqual([
21 { uri, caption: "Screenshot", kind: "image" },
22 { uri: "https://drop.example.com/demo.mp4", caption: "Video", kind: "video" },
23 {
24 uri: "https://github.com/user-attachments/assets/123-abc",
25 caption: "Video",
26 kind: "video",
27 },
28 ]);
29 });
30
31 it("collects videos from a before/after table", () => {
32 const media = splitPullRequestBody(
33 "<table>\n<tr><th>Before</th><th>After</th></tr>\n<tr><td>\n\nhttps://drop.example.com/before.mp4\n\n</td><td>\n\nhttps://drop.example.com/after.mp4\n\n</td></tr>\n</table>",
34 markdownReferenceDefinitions,
35 );
36 expect(
37 pullRequestDescriptionContent({ type: "root" } as MarkdownNode, media).attachments,
38 ).toEqual([
39 { uri: "https://drop.example.com/before.mp4", caption: "Video", kind: "video" },
40 { uri: "https://drop.example.com/after.mp4", caption: "Video", kind: "video" },
41 ]);
42 });
43});