Skip to content

Commit d4ac0a2

Browse files
committed
Adjust Markdown tests
1 parent 59f4596 commit d4ac0a2

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

src/cmem/markdown/Markdown.test.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react";
22
import { render } from "@testing-library/react";
33

4-
import { reduceToText } from "../../common/utils/reduceToText";
4+
import { truncateMarkdownDisplay } from "../../common/utils/truncateMarkdownDisplay";
55

66
import { Markdown } from "./Markdown";
77

@@ -46,7 +46,7 @@ describe("Markdown", () => {
4646
"After table.",
4747
].join("\n");
4848

49-
const { container } = render(<Markdown cutOff={35}>{content}</Markdown>);
49+
const { container } = render(<Markdown cutOff={55}>{content}</Markdown>);
5050

5151
expect(container.querySelector("table")).toBeTruthy();
5252
expect(container.textContent).toContain("Name");
@@ -70,7 +70,7 @@ describe("Markdown", () => {
7070
].join("\n");
7171

7272
for (const cutOff of [152, 153]) {
73-
const { container } = render(<Markdown cutOff={cutOff}>{content}</Markdown>);
73+
const { container } = render(truncateMarkdownDisplay(<Markdown cutOff={cutOff}>{content}</Markdown>));
7474

7575
expect(container.querySelectorAll("pre")).toHaveLength(2);
7676
expect(container.textContent).toContain('const status = "ready";');
@@ -80,9 +80,15 @@ describe("Markdown", () => {
8080
}
8181
});
8282

83-
it("does not call display truncation when cutOff is absent", () => {
84-
const content = "Plain **markdown** with [a link](https://example.com).";
83+
it("renders a link at the end of long content when cutOff is absent", () => {
84+
const content = `${Array.from({ length: 40 }, (_, index) => `Long visible paragraph part ${index + 1}.`).join(
85+
" ",
86+
)} [final reference](https://example.com/final-reference)`;
87+
88+
const { container } = render(<Markdown>{content}</Markdown>);
8589

86-
expect(reduceToText(<Markdown>{content}</Markdown>)).toContain("Plain markdown with a link");
90+
expect(container.textContent).toContain("Long visible paragraph part 1.");
91+
expect(container.textContent).toContain("final reference");
92+
expect(container.querySelector('a[href="https://example.com/final-reference"]')).toBeTruthy();
8793
});
8894
});

src/cmem/markdown/Markdown.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { remarkDefinitionList } from "remark-definition-list";
88
import remarkGfm from "remark-gfm";
99
import { PluggableList } from "unified";
1010

11-
import { truncateMarkdownDisplay } from "../../common/utils/truncateMarkdownDisplay";
1211
import { TestableComponent } from "../../components";
1312
import { HtmlContentBlock, HtmlContentBlockProps } from "../../components/Typography";
1413
import { CLASSPREFIX as eccgui } from "../../configuration/constants";
@@ -125,7 +124,8 @@ const configDefault = {
125124
skipHtml: false,
126125
};
127126

128-
const MarkdownInner = ({
127+
/** Renders a markdown string. */
128+
export const Markdown = ({
129129
children,
130130
allowHtml = false,
131131
removeMarkup = false,
@@ -212,6 +212,3 @@ const MarkdownInner = ({
212212
</HtmlContentBlock>
213213
);
214214
};
215-
216-
/** Renders a markdown string. */
217-
export const Markdown = (props: MarkdownProps) => truncateMarkdownDisplay(<MarkdownInner {...props} />);

0 commit comments

Comments
 (0)