Skip to content

Commit 4ccc73b

Browse files
test(code): parameterise htmlToMarkdown conversion cases
Generated-By: PostHog Code Task-Id: 5b5bfd18-72ac-40ff-9694-afc2494d96b9
1 parent 7a45544 commit 4ccc73b

1 file changed

Lines changed: 21 additions & 22 deletions

File tree

apps/code/src/renderer/features/message-editor/utils/htmlToMarkdown.test.ts

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,29 @@ import { describe, expect, it } from "vitest";
22
import { htmlToMarkdown } from "./htmlToMarkdown";
33

44
describe("htmlToMarkdown", () => {
5-
it("converts headings, emphasis and links", () => {
6-
const html =
7-
"<h1>Title</h1><p>Some <strong>bold</strong> and <em>italic</em> with a <a href='https://posthog.com'>link</a>.</p>";
8-
expect(htmlToMarkdown(html)).toBe(
5+
it.each([
6+
[
7+
"headings, emphasis and links",
8+
"<h1>Title</h1><p>Some <strong>bold</strong> and <em>italic</em> with a <a href='https://posthog.com'>link</a>.</p>",
99
"# Title\n\nSome **bold** and *italic* with a [link](https://posthog.com).",
10-
);
11-
});
12-
13-
it("converts unordered lists", () => {
14-
const html = "<ul><li>one</li><li>two</li></ul>";
15-
expect(htmlToMarkdown(html)).toBe("- one\n- two");
16-
});
17-
18-
it("converts tables via the gfm plugin", () => {
19-
const html =
20-
"<table><thead><tr><th>a</th><th>b</th></tr></thead><tbody><tr><td>1</td><td>2</td></tr></tbody></table>";
21-
expect(htmlToMarkdown(html)).toBe(
10+
],
11+
[
12+
"unordered lists",
13+
"<ul><li>one</li><li>two</li></ul>",
14+
"- one\n- two",
15+
],
16+
[
17+
"tables via the gfm plugin",
18+
"<table><thead><tr><th>a</th><th>b</th></tr></thead><tbody><tr><td>1</td><td>2</td></tr></tbody></table>",
2219
"| a | b |\n| --- | --- |\n| 1 | 2 |",
23-
);
24-
});
25-
26-
it("converts fenced code blocks", () => {
27-
const html = "<pre><code>const x = 1;</code></pre>";
28-
expect(htmlToMarkdown(html)).toBe("```\nconst x = 1;\n```");
20+
],
21+
[
22+
"fenced code blocks",
23+
"<pre><code>const x = 1;</code></pre>",
24+
"```\nconst x = 1;\n```",
25+
],
26+
])("converts %s", (_, html, expected) => {
27+
expect(htmlToMarkdown(html)).toBe(expected);
2928
});
3029

3130
it("returns null when there is no formatting beyond the plain-text fallback", () => {

0 commit comments

Comments
 (0)