diff --git a/extensions/matrix/src/matrix/format.test.ts b/extensions/matrix/src/matrix/format.test.ts index ab1990a67fb..e4e5a625405 100644 --- a/extensions/matrix/src/matrix/format.test.ts +++ b/extensions/matrix/src/matrix/format.test.ts @@ -10,83 +10,71 @@ function createMentionClient(selfUserId = "@bot:example.org") { describe("markdownToMatrixHtml", () => { it("renders basic inline formatting", () => { const html = markdownToMatrixHtml("hi _there_ **boss** `code`"); - expect(html).toContain("there"); - expect(html).toContain("boss"); - expect(html).toContain("code"); + expect(html).toBe("

hi there boss code

"); }); it("renders links as HTML", () => { const html = markdownToMatrixHtml("see [docs](https://example.com)"); - expect(html).toContain('docs'); + expect(html).toBe('

see docs

'); }); it("does not auto-link bare file references into external urls", () => { const html = markdownToMatrixHtml("Check README.md and backup.sh"); - expect(html).toContain("README.md"); - expect(html).toContain("backup.sh"); - expect(html).not.toContain('href="http://README.md"'); - expect(html).not.toContain('href="http://backup.sh"'); + expect(html).toBe("

Check README.md and backup.sh

"); }); it("keeps real domains linked even when path segments look like filenames", () => { const html = markdownToMatrixHtml("See https://docs.example.com/backup.sh"); - expect(html).toContain('href="https://docs.example.com/backup.sh"'); + expect(html).toBe( + '

See https://docs.example.com/backup.sh

', + ); }); it("escapes raw HTML", () => { const html = markdownToMatrixHtml("nope"); - expect(html).toContain("<b>nope</b>"); - expect(html).not.toContain("nope"); + expect(html).toBe("

<b>nope</b>

"); }); it("flattens images into alt text", () => { const html = markdownToMatrixHtml("![alt](https://example.com/img.png)"); - expect(html).toContain("alt"); - expect(html).not.toContain("alt

"); }); it("preserves line breaks", () => { const html = markdownToMatrixHtml("line1\nline2"); - expect(html).toContain("line1
\nline2

"); }); it("compacts loose ordered lists without paragraph tags", () => { const html = markdownToMatrixHtml("1. first\n\n2. second\n\n3. third"); - expect(html).toContain("
    "); - expect(html).toContain("
  1. "); - expect(html).not.toContain("

    "); + expect(html).toBe("

      \n
    1. first
    2. \n
    3. second
    4. \n
    5. third
    6. \n
    "); }); it("compacts loose unordered lists without paragraph tags", () => { const html = markdownToMatrixHtml("- one\n\n- two\n\n- three"); - expect(html).toContain("
      "); - expect(html).not.toContain("

      "); + expect(html).toBe("

        \n
      • one
      • \n
      • two
      • \n
      • three
      • \n
      "); }); it("keeps tight lists unchanged", () => { const html = markdownToMatrixHtml("- one\n- two"); - expect(html).toContain("
        "); - expect(html).not.toContain("

        "); + expect(html).toBe("

          \n
        • one
        • \n
        • two
        • \n
        "); }); it("preserves inline formatting in loose lists", () => { const html = markdownToMatrixHtml("1. **bold**\n\n2. _italic_"); - expect(html).toContain("bold"); - expect(html).toContain("italic"); - expect(html).not.toContain("

        "); + expect(html).toBe("

          \n
        1. bold
        2. \n
        3. italic
        4. \n
        "); }); it("does not strip paragraph tags outside lists", () => { const html = markdownToMatrixHtml("Hello\n\nWorld"); - expect(html).toContain("

        Hello

        "); - expect(html).toContain("

        World

        "); + expect(html).toBe("

        Hello

        \n

        World

        "); }); it("compacts nested sublists without paragraph tags", () => { const html = markdownToMatrixHtml("1. parent\n\n - child\n\n2. other"); - expect(html).toContain("
          "); - expect(html).toContain("
            "); - expect(html).not.toContain("

            "); + expect(html).toBe( + "

              \n
            1. parent\n
                \n
              • child
              • \n
              \n
            2. \n
            3. other
            4. \n
            ", + ); }); it("compacts loose lists with mentions via renderMarkdownToMatrixHtmlWithMentions", async () => { @@ -101,9 +89,9 @@ describe("markdownToMatrixHtml", () => { it("preserves paragraph wrappers for multi-paragraph list items", () => { const html = markdownToMatrixHtml("1. First sentence.\n\n Second sentence in the same item."); - expect(html).toContain("
          • "); - expect(html).toContain("

            First sentence.

            "); - expect(html).toContain("

            Second sentence in the same item.

            "); + expect(html).toBe( + "
              \n
            1. \n

              First sentence.

              \n

              Second sentence in the same item.

              \n
            2. \n
            ", + ); }); it("renders qualified Matrix user mentions as matrix.to links and m.mentions metadata", async () => {