Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

pullRequestDescriptionContent.test.ts

55 lines2.3 KB

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: "123-abc",
26 kind: "unknown",
27 },
28 ]);
29 });
30​
31 it("captions image links with their decoded file name", () => {
32 const media = splitPullRequestBody(
33 "https://drop.example.com/My%20Screenshot.png\n\nhttps://drop.example.com/caf%C3%A9.png\n\nhttps://drop.example.com/100%.png",
34 markdownReferenceDefinitions,
35 );
36 expect(
37 pullRequestDescriptionContent({ type: "root" } as MarkdownNode, media).attachments.map(
38 (attachment) => attachment.caption,
39 ),
40 ).toEqual(["My Screenshot.png", "café.png", "100%.png"]);
41 });
42​
43 it("collects videos from a before/after table", () => {
44 const media = splitPullRequestBody(
45 "<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>",
46 markdownReferenceDefinitions,
47 );
48 expect(
49 pullRequestDescriptionContent({ type: "root" } as MarkdownNode, media).attachments,
50 ).toEqual([
51 { uri: "https://drop.example.com/before.mp4", caption: "Video", kind: "video" },
52 { uri: "https://drop.example.com/after.mp4", caption: "Video", kind: "video" },
53 ]);
54 });
55});