11import React from "react" ;
22import { render } from "@testing-library/react" ;
33
4- import { reduceToText } from "../../common/utils/reduceToText " ;
4+ import { truncateMarkdownDisplay } from "../../common/utils/truncateMarkdownDisplay " ;
55
66import { 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} ) ;
0 commit comments