@@ -15,12 +15,13 @@ import {
1515 mockContentLibrary ,
1616 mockXBlockFields ,
1717 mockGetCollectionMetadata ,
18+ mockGetContainerMetadata ,
1819} from '../data/api.mocks' ;
1920import { mockContentSearchConfig , mockGetBlockTypes } from '../../search-manager/data/api.mock' ;
2021import { mockClipboardEmpty } from '../../generic/data/api.mock' ;
2122import { LibraryLayout } from '..' ;
2223import { ContentTagsDrawer } from '../../content-tags-drawer' ;
23- import { getLibraryCollectionComponentApiUrl } from '../data/api' ;
24+ import { getLibraryCollectionItemsApiUrl } from '../data/api' ;
2425
2526let axiosMock : MockAdapter ;
2627let mockShowToast ;
@@ -31,6 +32,7 @@ mockContentSearchConfig.applyMock();
3132mockGetBlockTypes . applyMock ( ) ;
3233mockContentLibrary . applyMock ( ) ;
3334mockXBlockFields . applyMock ( ) ;
35+ mockGetContainerMetadata . applyMock ( ) ;
3436
3537const searchEndpoint = 'http://mock.meilisearch.local/multi-search' ;
3638const path = '/library/:libraryId/*' ;
@@ -350,7 +352,7 @@ describe('<LibraryCollectionPage />', () => {
350352 } ) ;
351353
352354 it ( 'should remove component from collection and hides sidebar' , async ( ) => {
353- const url = getLibraryCollectionComponentApiUrl (
355+ const url = getLibraryCollectionItemsApiUrl (
354356 mockContentLibrary . libraryId ,
355357 mockCollection . collectionId ,
356358 ) ;
@@ -369,8 +371,38 @@ describe('<LibraryCollectionPage />', () => {
369371 fireEvent . click ( await screen . findByText ( 'Remove from collection' ) ) ;
370372 await waitFor ( ( ) => {
371373 expect ( axiosMock . history . delete . length ) . toEqual ( 1 ) ;
372- expect ( mockShowToast ) . toHaveBeenCalledWith ( 'Component successfully removed' ) ;
373374 } ) ;
375+ expect ( mockShowToast ) . toHaveBeenCalledWith ( 'Item successfully removed' ) ;
376+ // Should close sidebar as component was removed
377+ await waitFor ( ( ) => expect ( screen . queryByTestId ( 'library-sidebar' ) ) . not . toBeInTheDocument ( ) ) ;
378+ } ) ;
379+
380+ it ( 'should remove unit from collection and hides sidebar' , async ( ) => {
381+ const url = getLibraryCollectionItemsApiUrl (
382+ mockContentLibrary . libraryId ,
383+ mockCollection . collectionId ,
384+ ) ;
385+ axiosMock . onDelete ( url ) . reply ( 204 ) ;
386+ const displayName = 'Test Unit' ;
387+ await renderLibraryCollectionPage ( ) ;
388+
389+ // Wait for the unit cards to load
390+ waitFor ( ( ) => expect ( screen . getAllByTestId ( 'container-card-menu-toggle' ) . length ) . toBeGreaterThan ( 0 ) ) ;
391+
392+ // open sidebar
393+ fireEvent . click ( await screen . findByText ( displayName ) ) ;
394+ await waitFor ( ( ) => expect ( screen . queryByTestId ( 'library-sidebar' ) ) . toBeInTheDocument ( ) ) ;
395+
396+ // Open menu
397+ fireEvent . click ( ( await screen . findAllByTestId ( 'container-card-menu-toggle' ) ) [ 0 ] ) ;
398+
399+ // Click remove to collection
400+ fireEvent . click ( screen . getByRole ( 'button' , { name : 'Remove from collection' } ) ) ;
401+
402+ await waitFor ( ( ) => {
403+ expect ( axiosMock . history . delete . length ) . toEqual ( 1 ) ;
404+ } ) ;
405+ expect ( mockShowToast ) . toHaveBeenCalledWith ( 'Item successfully removed' ) ;
374406 // Should close sidebar as component was removed
375407 await waitFor ( ( ) => expect ( screen . queryByTestId ( 'library-sidebar' ) ) . not . toBeInTheDocument ( ) ) ;
376408 } ) ;
0 commit comments