Skip to content
Source
Sign inSign up

pullRequestDescription.test.ts

46 lines1.9 KB

1import { describe, expect, it } from "vite-plus/test";
2import { parseMarkdownDocument } from "../../lib/markdownDocument";
3import { pullRequestDescriptionContent } from "./pullRequestDescriptionContent";
4​
5describe("pull request description content", () => {
6 it("ignores malformed image URLs while keeping the description and valid attachments", () => {
7 const result = pullRequestDescriptionContent(
8 parseMarkdownDocument(
9 [
10 "The pull request remains readable.",
11 "![Missing host](https://)",
12 "![Invalid host](<https://a b>)",
13 '<img src="https://:80" alt="Invalid port">',
14 "![Unsupported](file:///screenshots/local.png)",
15 "![Screenshot](http://example.com/screenshot.png)",
16 ].join("\n\n"),
17 ),
18 );
19​
20 expect(result.attachments).toEqual([
21 { uri: "http://example.com/screenshot.png", caption: "Screenshot", kind: "image" },
22 ]);
23 expect(result.preview).toContain("The pull request remains readable.");
24 });
25​
26 it("keeps screenshot attachments and does not turn code examples or local paths into media", () => {
27 const result = pullRequestDescriptionContent(
28 parseMarkdownDocument(
29 [
30 "Fixes reconnects.",
31 "```markdown\n![Example](https://example.com/code.png)\n```",
32 "![Before](https://example.com/before.png)",
33 "![After](https://example.com/after.png)",
34 "![Duplicate](https://example.com/before.png)",
35 "![Local](screenshots/local.png)",
36 ].join("\n\n"),
37 ),
38 );
39 expect(result.attachments).toEqual([
40 { uri: "https://example.com/before.png", caption: "Before", kind: "image" },
41 { uri: "https://example.com/after.png", caption: "After", kind: "image" },
42 ]);
43 expect(result.preview).toContain("Fixes reconnects.");
44 expect(result.preview).not.toContain("Duplicate");
45 });
46});