11import userEvent from '@testing-library/user-event' ;
22import type MockAdapter from 'axios-mock-adapter' ;
33
4+ import { mockContentLibrary } from '@src/library-authoring/data/api.mocks' ;
45import {
56 initializeMocks , render as baseRender , screen , waitFor , within , fireEvent ,
67} from '../../testUtils' ;
@@ -43,14 +44,18 @@ const collectionHitSample: CollectionHit = {
4344let axiosMock : MockAdapter ;
4445let mockShowToast ;
4546
46- const libraryId = 'lib:org1:Demo_Course' ;
47+ const { libraryId } = mockContentLibrary ;
4748
48- const render = ( ui : React . ReactElement , showOnlyPublished : boolean = false ) => baseRender ( ui , {
49+ const render = (
50+ ui : React . ReactElement ,
51+ showOnlyPublished : boolean = false ,
52+ libId : string = libraryId ,
53+ ) => baseRender ( ui , {
4954 path : '/library/:libraryId' ,
50- params : { libraryId } ,
55+ params : { libraryId : libId } ,
5156 extraWrapper : ( { children } ) => (
5257 < LibraryProvider
53- libraryId = "lib:Axim:TEST"
58+ libraryId = { libId }
5459 showOnlyPublished = { showOnlyPublished }
5560 >
5661 { children }
@@ -63,6 +68,7 @@ describe('<CollectionCard />', () => {
6368 const mocks = initializeMocks ( ) ;
6469 axiosMock = mocks . axiosMock ;
6570 mockShowToast = mocks . mockShowToast ;
71+ mockContentLibrary . applyMock ( ) ;
6672 } ) ;
6773
6874 it ( 'should render the card with title and description' , ( ) => {
@@ -193,4 +199,24 @@ describe('<CollectionCard />', () => {
193199 expect ( mockShowToast ) . toHaveBeenCalledWith ( 'Failed to delete collection' ) ;
194200 } ) ;
195201 } ) ;
202+
203+ it ( 'should not show delete button when library is read-only' , async ( ) => {
204+ const user = userEvent . setup ( ) ;
205+
206+ // Render with read-only library
207+ render ( < CollectionCard hit = { collectionHitSample } /> , false , mockContentLibrary . libraryIdReadOnly ) ;
208+
209+ // Open menu
210+ const menu = await screen . findByTestId ( 'collection-card-menu-toggle' ) ;
211+ expect ( menu ) . toBeInTheDocument ( ) ;
212+ await user . click ( menu ) ;
213+
214+ // Delete button should not be visible in readonly mode
215+ const deleteOption = screen . queryByRole ( 'button' , { name : 'Delete' } ) ;
216+ expect ( deleteOption ) . not . toBeInTheDocument ( ) ;
217+
218+ // Open button should still be visible
219+ const openOption = screen . queryByRole ( 'button' , { name : 'Open' } ) ;
220+ expect ( openOption ) . toBeInTheDocument ( ) ;
221+ } ) ;
196222} ) ;
0 commit comments