Open History to see the last commit
1import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
2import { EnvironmentId } from "@t3tools/contracts";
3import { expect, it } from "vite-plus/test";
4
5import { render } from "../../../test/render";
6import { PullRequestMarkdown, PullRequestMarkdownContext } from "./PullRequestMarkdown";
7
8async function renderBody(host: string, options: { lineBreaks?: boolean } = {}) {
9 const context = {
10 remarkPlugins: [],
11 lineBreaks: sourceControlClients.get(host).hardLineBreaks ?? false,
12 threadRef: null,
13 };
14 return render(
15 <PullRequestMarkdownContext value={context}>
16 <PullRequestMarkdown
17 text={"first line\nsecond line"}
18 cwd="/repo"
19 environmentId={EnvironmentId.make("local")}
20 {...options}
21 />
22 </PullRequestMarkdownContext>,
23 );
24}
25
26it.each(["github", "forgejo", "azure-devops"])("%s breaks a single newline", async (host) => {
27 await using screen = await renderBody(host);
28 await expect.element(screen.getByText(/first line/)).toBeInTheDocument();
29 expect(screen.container.querySelectorAll("p br")).toHaveLength(1);
30});
31
32it.each(["gitlab", "bitbucket", "gitcafe", "unknown"])(
33 "%s joins a single newline",
34 async (host) => {
35 await using screen = await renderBody(host);
36 await expect.element(screen.getByText(/first line/)).toBeInTheDocument();
37 expect(screen.container.querySelectorAll("p br")).toHaveLength(0);
38 },
39);
40
41it("lets text the host did not write opt out of the host's breaks", async () => {
42 await using screen = await renderBody("github", { lineBreaks: false });
43 await expect.element(screen.getByText(/first line/)).toBeInTheDocument();
44 expect(screen.container.querySelectorAll("p br")).toHaveLength(0);
45});