@@ -15,7 +15,8 @@ describe('ContentRenderer', () => {
1515 } ) ;
1616
1717 it ( 'renders a plain string as MarkdownContent in inline mode' , ( ) => {
18- render ( < ContentRenderer content = 'Just a string block' /> ) ;
18+ const container = render ( < ContentRenderer content = 'Just a string block' /> ) ;
19+ expect ( container . asFragment ( ) ) . toMatchSnapshot ( ) ;
1920 expect ( screen . getByText ( 'Just a string block' ) ) . toBeInTheDocument ( ) ;
2021 } ) ;
2122
@@ -46,7 +47,9 @@ describe('ContentRenderer', () => {
4647 { type : 'text' , text : 'Another paragraph.' } ,
4748 ] ;
4849
49- render ( < ContentRenderer content = { content } /> ) ;
50+ const container = render ( < ContentRenderer content = { content } /> ) ;
51+
52+ expect ( container . asFragment ( ) ) . toMatchSnapshot ( ) ;
5053
5154 const listItems = screen . getAllByRole ( 'paragraph' ) ;
5255 expect ( listItems ) . toHaveLength ( 2 ) ;
@@ -59,14 +62,16 @@ describe('ContentRenderer', () => {
5962 { type : 'inline-text' , text : 'Inline content' } ,
6063 ] ;
6164
62- render (
65+ const container = render (
6366 < ul >
6467 < li data-testid = 'list-item' >
6568 < ContentRenderer content = { content } />
6669 </ li >
6770 </ ul >
6871 ) ;
6972
73+ expect ( container . asFragment ( ) ) . toMatchSnapshot ( ) ;
74+
7075 const listItem = screen . getByTestId ( 'list-item' ) ;
7176 expect ( listItem ) . toHaveTextContent ( 'Inline content' ) ;
7277 expect ( listItem . querySelector ( 'p' ) ) . toBeNull ( ) ;
@@ -75,14 +80,16 @@ describe('ContentRenderer', () => {
7580 it ( 'treats a string as inline text (no paragraph wrapper)' , ( ) => {
7681 const content : string = 'Inline via string' ;
7782
78- render (
83+ const container = render (
7984 < ul >
8085 < li data-testid = 'list-item' >
8186 < ContentRenderer content = { content } />
8287 </ li >
8388 </ ul >
8489 ) ;
8590
91+ expect ( container . asFragment ( ) ) . toMatchSnapshot ( ) ;
92+
8693 const listItem = screen . getByTestId ( 'list-item' ) ;
8794 expect ( listItem ) . toHaveTextContent ( 'Inline via string' ) ;
8895 expect ( listItem . querySelector ( 'p' ) ) . toBeNull ( ) ;
@@ -91,14 +98,16 @@ describe('ContentRenderer', () => {
9198 it ( 'treats a string array as inline text (no paragraph wrapper)' , ( ) => {
9299 const content : ContentItem [ ] = [ 'Inline via string' ] ;
93100
94- render (
101+ const container = render (
95102 < ul >
96103 < li data-testid = 'list-item' >
97104 < ContentRenderer content = { content } />
98105 </ li >
99106 </ ul >
100107 ) ;
101108
109+ expect ( container . asFragment ( ) ) . toMatchSnapshot ( ) ;
110+
102111 const listItem = screen . getByTestId ( 'list-item' ) ;
103112 expect ( listItem ) . toHaveTextContent ( 'Inline via string' ) ;
104113 expect ( listItem . querySelector ( 'p' ) ) . toBeNull ( ) ;
@@ -116,7 +125,9 @@ describe('ContentRenderer', () => {
116125 } ,
117126 ] ;
118127
119- render ( < ContentRenderer content = { content } /> ) ;
128+ const container = render ( < ContentRenderer content = { content } /> ) ;
129+
130+ expect ( container . asFragment ( ) ) . toMatchSnapshot ( ) ;
120131
121132 const hiddenText = screen . getByText ( 'An example of heading markdown' ) ;
122133 expect ( hiddenText ) . toHaveAttribute ( 'id' , 'heading-markdown-description' ) ;
@@ -128,17 +139,41 @@ describe('ContentRenderer', () => {
128139 ) ;
129140 } ) ;
130141
131- it ( 'renders list blocks' , ( ) => {
142+ it ( 'renders unordered list blocks' , ( ) => {
132143 const content : ContentBlock [ ] = [
133144 {
134145 type : 'text' ,
135146 text : markdownList ( 'ul' , [ 'Item 1' , 'Item 2' , 'Item 3' ] ) ,
136147 } ,
137148 ] ;
138149
139- render ( < ContentRenderer content = { content } /> ) ;
150+ const container = render ( < ContentRenderer content = { content } /> ) ;
151+
152+ expect ( container . asFragment ( ) ) . toMatchSnapshot ( ) ;
153+
154+ const listItems = screen . getAllByRole ( 'listitem' ) ;
155+ expect ( listItems ) . toHaveLength ( 3 ) ;
156+ expect ( listItems [ 0 ] ?. parentElement ?. tagName ) . toBe ( 'UL' ) ;
157+ expect ( listItems [ 0 ] ) . toHaveTextContent ( 'Item 1' ) ;
158+ expect ( listItems [ 1 ] ) . toHaveTextContent ( 'Item 2' ) ;
159+ expect ( listItems [ 2 ] ) . toHaveTextContent ( 'Item 3' ) ;
160+ } ) ;
161+
162+ it ( 'renders ordered list blocks' , ( ) => {
163+ const content : ContentBlock [ ] = [
164+ {
165+ type : 'text' ,
166+ text : markdownList ( 'ol' , [ 'Item 1' , 'Item 2' , 'Item 3' ] ) ,
167+ } ,
168+ ] ;
169+
170+ const container = render ( < ContentRenderer content = { content } /> ) ;
171+
172+ expect ( container . asFragment ( ) ) . toMatchSnapshot ( ) ;
173+
140174 const listItems = screen . getAllByRole ( 'listitem' ) ;
141175 expect ( listItems ) . toHaveLength ( 3 ) ;
176+ expect ( listItems [ 0 ] ?. parentElement ?. tagName ) . toBe ( 'OL' ) ;
142177 expect ( listItems [ 0 ] ) . toHaveTextContent ( 'Item 1' ) ;
143178 expect ( listItems [ 1 ] ) . toHaveTextContent ( 'Item 2' ) ;
144179 expect ( listItems [ 2 ] ) . toHaveTextContent ( 'Item 3' ) ;
@@ -158,12 +193,14 @@ describe('ContentRenderer', () => {
158193 } ,
159194 ] ;
160195
161- render ( < ContentRenderer content = { content } /> ) ;
196+ const container = render ( < ContentRenderer content = { content } /> ) ;
162197
163- const listItems = screen . getAllByRole ( 'paragraph' ) ;
164- expect ( listItems ) . toHaveLength ( 2 ) ;
165- expect ( listItems [ 0 ] ) . toHaveClass ( 'foo' ) ;
166- expect ( listItems [ 1 ] ) . toHaveClass ( 'bar' ) ;
198+ expect ( container . asFragment ( ) ) . toMatchSnapshot ( ) ;
199+
200+ const paragraphs = screen . getAllByRole ( 'paragraph' ) ;
201+ expect ( paragraphs ) . toHaveLength ( 2 ) ;
202+ expect ( paragraphs [ 0 ] ) . toHaveClass ( 'foo' ) ;
203+ expect ( paragraphs [ 1 ] ) . toHaveClass ( 'bar' ) ;
167204 } ) ;
168205
169206 it ( 'renders with overrides on inline-text blocks' , ( ) => {
@@ -175,7 +212,9 @@ describe('ContentRenderer', () => {
175212 } ,
176213 ] ;
177214
178- render ( < ContentRenderer content = { content } /> ) ;
215+ const container = render ( < ContentRenderer content = { content } /> ) ;
216+
217+ expect ( container . asFragment ( ) ) . toMatchSnapshot ( ) ;
179218
180219 const link = screen . getByRole ( 'link' ) ;
181220 expect ( link ) . toHaveClass ( 'foo' ) ;
0 commit comments