@@ -8,11 +8,14 @@ import {
88 initializeMocks ,
99} from '@src/testUtils' ;
1010
11+ import MockAdapter from 'axios-mock-adapter/types' ;
12+ import { useGetContentHits } from '@src/search-manager' ;
1113import { mockContentLibrary } from './data/api.mocks' ;
1214import mockEmptyResult from '../search-modal/__mocks__/empty-search-result.json' ;
1315import { LibraryProvider } from './common/context/LibraryContext' ;
1416import LibraryContent from './LibraryContent' ;
1517import { libraryComponentsMock } from './__mocks__' ;
18+ import { getModulestoreMigratedBlocksInfoUrl } from './data/api' ;
1619
1720const searchEndpoint = 'http://mock.meilisearch.local/multi-search' ;
1821
@@ -43,9 +46,10 @@ const returnEmptyResult = (_url: string, req) => {
4346 return mockEmptyResult ;
4447} ;
4548
46- jest . mock ( '.. /search-manager' , ( ) => ( {
49+ jest . mock ( '@src /search-manager' , ( ) => ( {
4750 ...jest . requireActual ( '../search-manager' ) ,
4851 useSearchContext : ( ) => mockUseSearchContext ( ) ,
52+ useGetContentHits : jest . fn ( ) . mockReturnValue ( { isPending : true , data : null } ) ,
4953} ) ) ;
5054
5155const withLibraryId = ( libraryId : string ) => ( {
@@ -55,10 +59,12 @@ const withLibraryId = (libraryId: string) => ({
5559 </ LibraryProvider >
5660 ) ,
5761} ) ;
62+ let axiosMock : MockAdapter ;
5863
5964describe ( '<LibraryHome />' , ( ) => {
6065 beforeEach ( ( ) => {
61- const { axiosMock } = initializeMocks ( ) ;
66+ const mocks = initializeMocks ( ) ;
67+ axiosMock = mocks . axiosMock ;
6268
6369 fetchMock . post ( searchEndpoint , returnEmptyResult , { overwriteRoutes : true } ) ;
6470
@@ -108,4 +114,48 @@ describe('<LibraryHome />', () => {
108114 fireEvent . scroll ( window , { target : { scrollY : 1000 } } ) ;
109115 expect ( mockFetchNextPage ) . toHaveBeenCalled ( ) ;
110116 } ) ;
117+
118+ it ( 'should show placeholderBlocks' , async ( ) => {
119+ axiosMock . onGet ( getModulestoreMigratedBlocksInfoUrl ( ) ) . reply ( 200 , [
120+ {
121+ sourceKey : 'block-v1:UNIX+UX2+2025_T2+type@library_content+block@test_lib_content' ,
122+ targetKey : null ,
123+ unsupportedReason : 'The "library_content" XBlock (ID: "test_lib_content") has children, so it not supported in content libraries. It has 2 children blocks.' ,
124+ } ,
125+ {
126+ sourceKey : 'block-v1:UNIX+UX2+2025_T2+type@conditional+block@test_conditional' ,
127+ targetKey : null ,
128+ unsupportedReason : 'The "conditional" XBlock (ID: "test_conditional") has children, so it not supported in content libraries. It has 2 children blocks.' ,
129+ } ,
130+ ] ) ;
131+ ( useGetContentHits as jest . Mock ) . mockReturnValue ( {
132+ isPending : false ,
133+ data : {
134+ hits : [
135+ {
136+ display_name : 'Randomized Content Block' ,
137+ usage_key : 'block-v1:UNIX+UX2+2025_T2+type@library_content+block@test_lib_content' ,
138+ block_type : 'library_content' ,
139+ } ,
140+ {
141+ display_name : 'Conditional' ,
142+ usage_key : 'block-v1:UNIX+UX2+2025_T2+type@conditional+block@test_conditional' ,
143+ block_type : 'conditional' ,
144+ } ,
145+ ] ,
146+ query : '' ,
147+ processingTimeMs : 0 ,
148+ limit : 2 ,
149+ offset : 0 ,
150+ estimatedTotalHits : 2 ,
151+ } ,
152+ } ) ;
153+ mockUseSearchContext . mockReturnValue ( {
154+ ...data ,
155+ hits : libraryComponentsMock ,
156+ } ) ;
157+ render ( < LibraryContent /> , withLibraryId ( mockContentLibrary . libraryId ) ) ;
158+ expect ( await screen . findByText ( 'Randomized Content Block' ) ) . toBeInTheDocument ( ) ;
159+ expect ( await screen . findByText ( 'Conditional' ) ) . toBeInTheDocument ( ) ;
160+ } ) ;
111161} ) ;
0 commit comments