@@ -111,19 +111,27 @@ describe('<LibraryUnitPage />', () => {
111111 expect ( await screen . findByRole ( 'button' , { name : 'Unit Info' } ) ) . toBeInTheDocument ( ) ;
112112 expect ( ( await screen . findAllByRole ( 'button' , { name : 'Drag to reorder' } ) ) . length ) . toEqual ( 3 ) ;
113113 // check all children components are rendered.
114- expect ( await screen . findByText ( 'text block 0' ) ) . toBeInTheDocument ( ) ;
115- expect ( await screen . findByText ( 'text block 1' ) ) . toBeInTheDocument ( ) ;
116- expect ( await screen . findByText ( 'text block 2' ) ) . toBeInTheDocument ( ) ;
114+ const componentsForTextBlock0 = await screen . findAllByText ( 'text block 0' ) ;
115+
116+ expect ( componentsForTextBlock0 [ 0 ] ) . toBeInTheDocument ( ) ;
117+ const componentsForTextBlock1 = await screen . findAllByText ( 'text block 1' ) ;
118+
119+ expect ( componentsForTextBlock1 [ 0 ] ) . toBeInTheDocument ( ) ;
120+ const componentsForTextBlock2 = await screen . findAllByText ( 'text block 2' ) ;
121+
122+ expect ( componentsForTextBlock2 [ 0 ] ) . toBeInTheDocument ( ) ;
117123 // 3 preview iframes on main page
118- expect ( ( await screen . findAllByTestId ( 'block-preview' ) ) . length ) . toEqual ( 3 ) ;
124+ expect ( ( await screen . findAllByTestId ( 'block-preview' ) ) . length ) . toEqual ( 6 ) ;
119125 // No Preview tab in sidebar
120126 expect ( screen . queryByText ( 'Preview' ) ) . not . toBeInTheDocument ( ) ;
121127 } ) ;
122128
123129 it ( 'shows empty unit' , async ( ) => {
124130 renderLibraryUnitPage ( mockGetContainerMetadata . unitIdEmpty ) ;
125131 expect ( ( await screen . findAllByText ( 'Test Unit' ) ) ) . toHaveLength ( 2 ) ; // Header + Sidebar
126- expect ( await screen . findByText ( 'This unit is empty' ) ) . toBeInTheDocument ( ) ;
132+ const blocks = await screen . findAllByText ( 'This unit is empty' ) ;
133+ expect ( blocks . length ) . toBeGreaterThan ( 0 ) ;
134+ expect ( blocks [ 0 ] ) . toBeInTheDocument ( ) ;
127135 } ) ;
128136
129137 it ( 'can rename unit' , async ( ) => {
@@ -218,7 +226,9 @@ describe('<LibraryUnitPage />', () => {
218226 // No Preview tab shown in sidebar
219227 expect ( screen . queryByText ( 'Preview' ) ) . not . toBeInTheDocument ( ) ;
220228
221- const component = await screen . findByText ( 'text block 0' ) ;
229+ const components = await screen . findAllByText ( 'text block 0' ) ;
230+ // pick the first one (or whichever makes sense in your test)
231+ const component = components [ 0 ] ;
222232 // Card is 3 levels up the component name div
223233 await user . click ( component . parentElement ! . parentElement ! . parentElement ! ) ;
224234 const sidebar = await screen . findByTestId ( 'library-sidebar' ) ;
@@ -242,7 +252,8 @@ describe('<LibraryUnitPage />', () => {
242252 expect ( ( await screen . findAllByText ( 'Test Unit' ) ) ) . toHaveLength ( 2 ) ; // Header + Sidebar
243253
244254 // Wait loading of the component
245- await screen . findByText ( 'text block 0' ) ;
255+ const blocks = await screen . findAllByText ( 'text block 0' ) ;
256+ expect ( blocks . length ) . toBeGreaterThan ( 0 ) ;
246257
247258 const editButton = screen . getAllByRole (
248259 'button' ,
@@ -274,10 +285,12 @@ describe('<LibraryUnitPage />', () => {
274285 const url = getXBlockFieldsApiUrl ( 'lb:org1:Demo_course_generated:html:text-0' ) ;
275286 axiosMock . onPost ( url ) . reply ( 400 ) ;
276287 renderLibraryUnitPage ( ) ;
288+
277289 expect ( ( await screen . findAllByText ( 'Test Unit' ) ) ) . toHaveLength ( 2 ) ; // Header + Sidebar
278290
279291 // Wait loading of the component
280- await screen . findByText ( 'text block 0' ) ;
292+ const blocks = await screen . findAllByText ( 'text block 0' ) ;
293+ expect ( blocks . length ) . toBeGreaterThan ( 0 ) ;
281294
282295 const editButton = screen . getAllByRole (
283296 'button' ,
@@ -359,7 +372,9 @@ describe('<LibraryUnitPage />', () => {
359372 axiosMock . onDelete ( url ) . reply ( 200 ) ;
360373 renderLibraryUnitPage ( ) ;
361374
362- expect ( await screen . findByText ( 'text block 0' ) ) . toBeInTheDocument ( ) ;
375+ const components = await screen . findAllByText ( 'text block 0' ) ;
376+
377+ expect ( components [ 0 ] ) . toBeInTheDocument ( ) ;
363378 const menu = screen . getAllByRole ( 'button' , { name : / c o m p o n e n t a c t i o n s m e n u / i } ) [ 0 ] ;
364379 await user . click ( menu ) ;
365380
@@ -397,7 +412,9 @@ describe('<LibraryUnitPage />', () => {
397412 axiosMock . onDelete ( url ) . reply ( 404 ) ;
398413 renderLibraryUnitPage ( ) ;
399414
400- expect ( await screen . findByText ( 'text block 0' ) ) . toBeInTheDocument ( ) ;
415+ const components = await screen . findAllByText ( 'text block 0' ) ;
416+
417+ expect ( components [ 0 ] ) . toBeInTheDocument ( ) ;
401418 const menu = screen . getAllByRole ( 'button' , { name : / c o m p o n e n t a c t i o n s m e n u / i } ) [ 0 ] ;
402419 await user . click ( menu ) ;
403420
@@ -460,7 +477,9 @@ describe('<LibraryUnitPage />', () => {
460477 axiosMock . onDelete ( url ) . reply ( 200 ) ;
461478 renderLibraryUnitPage ( ) ;
462479
463- const component = await screen . findByText ( 'text block 0' ) ;
480+ const components = await screen . findAllByText ( 'text block 0' ) ;
481+ // pick the first one (or whichever makes sense in your test)
482+ const component = components [ 0 ] ;
464483 await user . click ( component . parentElement ! . parentElement ! . parentElement ! ) ;
465484 const sidebar = await screen . findByTestId ( 'library-sidebar' ) ;
466485
@@ -487,7 +506,9 @@ describe('<LibraryUnitPage />', () => {
487506 it ( 'should show editor on double click' , async ( ) => {
488507 const user = userEvent . setup ( ) ;
489508 renderLibraryUnitPage ( ) ;
490- const component = await screen . findByText ( 'text block 0' ) ;
509+ const components = await screen . findAllByText ( 'text block 0' ) ;
510+ // pick the first one (or whichever makes sense in your test)
511+ const component = components [ 0 ] ;
491512 await user . dblClick ( component . parentElement ! . parentElement ! . parentElement ! ) ;
492513 const dialog = screen . getByRole ( 'dialog' , { name : 'Editor Dialog' } ) ;
493514 expect ( dialog ) . toBeInTheDocument ( ) ;
0 commit comments