1import { changeRequestReferenceAutolinker } from "@t3tools/client-runtime/pull-request-markdown";
2import { describe, expect, it } from "vite-plus/test";
3
4import { linkReferenceAutolinks } from "./pullRequestAutolinks";
5
6const github = changeRequestReferenceAutolinker({
7 provider: "github",
8 url: "https://github.com/team/repo/pull/8",
9});
10
11describe("linkReferenceAutolinks", () => {
12 it("links the host's references in prose", () => {
13 expect(linkReferenceAutolinks("Closes #123, see @julius", github)).toBe(
14 "Closes [#123](https://github.com/team/repo/issues/123), see [@julius](https://github.com/julius)",
15 );
16 });
17
18 it("leaves code, links, images, escapes and definitions alone", () => {
19 const text =
20 "`#123 @person abc1234`\n\n```\n#123\n```\n\n[#123](https://example.com)  https://example.com/#123 user@example.com \\#123 1234567\n\n[ref]: https://example.com/#123";
21 expect(linkReferenceAutolinks(text, github)).toBe(text);
22 });
23
24 it("does not nest links inside HTML anchors or code", () => {
25 const text = 'See <a href="https://example.com">#12</a> and <code>#13</code>, then #14.';
26 expect(linkReferenceAutolinks(text, github)).toBe(
27 'See <a href="https://example.com">#12</a> and <code>#13</code>, then [#14](https://github.com/team/repo/issues/14).',
28 );
29 });
30
31 it("leaves markdown unchanged for a host that links nothing", () => {
32 const forgejo = changeRequestReferenceAutolinker({
33 provider: "forgejo",
34 url: "https://codeberg.org/acme/web/pulls/7",
35 });
36 expect(linkReferenceAutolinks("Closes #123", forgejo)).toBe("Closes #123");
37 });
38});