| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | import { githubMarkdownLinks } from "./githubMarkdownLinks.ts"; |
| 3 | |
| 4 | const url = "https://github.com/team/repo/pull/8"; |
| 5 | describe("githubMarkdownLinks", () => { |
| 6 | it("links closing references, cross-repository references, commits and mentions", () => { |
| 7 | expect( |
| 8 | githubMarkdownLinks( |
| 9 | "Closes #123, fixes other/project#9; other#4 @julius @team/mobile abc1234 other/project@abcdef1", |
| 10 | url, |
| 11 | ), |
| 12 | ).toBe( |
| 13 | "Closes [#123](https://github.com/team/repo/issues/123), fixes [other/project#9](https://github.com/other/project/issues/9); [other#4](https://github.com/other/repo/issues/4) [@julius](https://github.com/julius) [@team/mobile](https://github.com/orgs/team/teams/mobile) [abc1234](https://github.com/team/repo/commit/abc1234) [other/project@abcdef1](https://github.com/other/project/commit/abcdef1)", |
| 14 | ); |
| 15 | }); |
| 16 | it("leaves code, links, images, URLs, escapes, emails, and plain numbers alone", () => { |
| 17 | const text = |
| 18 | "`#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"; |
| 19 | expect(githubMarkdownLinks(text, url)).toBe(text); |
| 20 | }); |
| 21 | it("keeps formatting and links references in lists and quotes", () => { |
| 22 | expect(githubMarkdownLinks("> **Fixes #42**\n\n- See #9", url)).toBe( |
| 23 | "> **Fixes [#42](https://github.com/team/repo/issues/42)**\n\n- See [#9](https://github.com/team/repo/issues/9)", |
| 24 | ); |
| 25 | }); |
| 26 | it("does nothing without repository context", () => { |
| 27 | expect(githubMarkdownLinks("#123", null)).toBe("#123"); |
| 28 | }); |
| 29 | it("does not nest links inside HTML anchors or code", () => { |
| 30 | const text = 'See <a href="https://example.com">#12</a> and <code>#13</code>, then #14.'; |
| 31 | expect(githubMarkdownLinks(text, url)).toBe( |
| 32 | 'See <a href="https://example.com">#12</a> and <code>#13</code>, then [#14](https://github.com/team/repo/issues/14).', |
| 33 | ); |
| 34 | }); |
| 35 | }); |