import { describe, expect, it } from "vite-plus/test"; import { splitPullRequestBody } from "./pullRequestMarkdown.logic"; describe("pull request body segmentation", () => { it("keeps a plain body as a single markdown run", () => { expect(splitPullRequestBody("## What changed\n\nSome prose.")).toEqual([ { id: "markdown:0", kind: "markdown", text: "## What changed\n\nSome prose." }, ]); }); // GitHub writes a dropped image into the body as an `` tag, so a bare attachment link on // its own line is the shape it uses for a video — every one sampled in the wild was one. it("lifts a dropped video out and keeps the prose around it", () => { expect( splitPullRequestBody( "Before\n\nhttps://github.com/user-attachments/assets/2f8c1a90-1b2c-4d5e-8f90-abcdef123456\n\nAfter", ), ).toEqual([ { id: "markdown:0", kind: "markdown", text: "Before" }, { id: "attachment:1", kind: "attachment", url: "https://github.com/user-attachments/assets/2f8c1a90-1b2c-4d5e-8f90-abcdef123456", media: "video", }, { id: "markdown:2", kind: "markdown", text: "After" }, ]); }); it("names a bare link to a video file a video", () => { expect(splitPullRequestBody("https://example.com/demo.mp4?raw=1")).toEqual([ { id: "attachment:0", kind: "attachment", url: "https://example.com/demo.mp4?raw=1", media: "video", }, ]); }); it("reads the source out of a video tag, including a multi-line one", () => { expect( splitPullRequestBody( '', ), ).toEqual([ { id: "attachment:0", kind: "attachment", url: "https://example.com/a.webm", media: "video", }, ]); }); it("leaves a dropped image as markdown so it still renders as an image", () => { const body = "![shot](https://github.com/user-attachments/assets/2f8c1a90-1b2c-4d5e-8f90-ab)"; expect(splitPullRequestBody(body)).toEqual([ { id: "markdown:0", kind: "markdown", text: body }, ]); }); it("leaves the img tag GitHub writes for a dropped image as markdown", () => { const body = 'image'; expect(splitPullRequestBody(body)).toEqual([ { id: "markdown:0", kind: "markdown", text: body }, ]); }); it("leaves an ordinary link alone, whether it is bare or written as markdown", () => { const body = "https://example.com/page\n\n[the docs](https://example.com/docs)"; expect(splitPullRequestBody(body)).toEqual([ { id: "markdown:0", kind: "markdown", text: body }, ]); }); it("never lifts a link inside fenced code out of it", () => { const body = "```\nhttps://example.com/demo.mp4\n```"; expect(splitPullRequestBody(body)).toEqual([ { id: "markdown:0", kind: "markdown", text: body }, ]); }); it("does not let a different fence marker close an open fence", () => { const body = "```\n~~~\nhttps://example.com/demo.mp4\n```"; expect(splitPullRequestBody(body)).toEqual([ { id: "markdown:0", kind: "markdown", text: body }, ]); }); it("keeps a video tag that shares its line with prose as markdown", () => { const body = 'Before after'; expect(splitPullRequestBody(body)).toEqual([ { id: "markdown:0", kind: "markdown", text: body }, ]); }); it("keeps the indentation that opens a code block", () => { const body = " const answer = 42;"; expect(splitPullRequestBody(body)).toEqual([ { id: "markdown:0", kind: "markdown", text: body }, ]); }); it("treats an info-string fence as a nested opener, not a close", () => { const body = "```\n```javascript\nhttps://example.com/demo.mp4\n```"; expect(splitPullRequestBody(body)).toEqual([ { id: "markdown:0", kind: "markdown", text: body }, ]); }); it("leaves an indented code line alone even when it is only a video link", () => { const body = " https://example.com/demo.mp4"; expect(splitPullRequestBody(body)).toEqual([ { id: "markdown:0", kind: "markdown", text: body }, ]); }); it("leaves an unclosed video tag as prose without eating the rest of the body", () => { const body = ['