@@ -4,17 +4,17 @@ import type MockAdapter from 'axios-mock-adapter';
44import {
55 initializeMocks , render as baseRender , screen , waitFor ,
66 fireEvent ,
7- } from '../../testUtils' ;
7+ within ,
8+ } from '@src/testUtils' ;
9+ import { ContainerType } from '@src/generic/key-utils' ;
10+ import { mockContentSearchConfig , mockSearchResult } from '@src/search-manager/data/api.mock' ;
11+ import type { ToastActionData } from '@src/generic/toast-context' ;
812import { mockContentLibrary , mockGetContainerChildren , mockGetContainerMetadata } from '../data/api.mocks' ;
913import { LibraryProvider } from '../common/context/LibraryContext' ;
1014import ContainerInfo from './ContainerInfo' ;
1115import { getLibraryContainerApiUrl , getLibraryContainerPublishApiUrl } from '../data/api' ;
1216import { SidebarBodyItemId , SidebarProvider } from '../common/context/SidebarContext' ;
13- import { ContainerType } from '../../generic/key-utils' ;
14- import { mockContentSearchConfig , mockSearchResult } from '../../search-manager/data/api.mock' ;
15- import type { ToastActionData } from '../../generic/toast-context' ;
1617
17- mockGetContainerMetadata . applyMock ( ) ;
1818mockContentLibrary . applyMock ( ) ;
1919mockContentSearchConfig . applyMock ( ) ;
2020mockGetContainerMetadata . applyMock ( ) ;
@@ -23,6 +23,12 @@ mockGetContainerChildren.applyMock();
2323const { libraryId } = mockContentLibrary ;
2424const { unitId, subsectionId, sectionId } = mockGetContainerMetadata ;
2525
26+ const mockNavigate = jest . fn ( ) ;
27+ jest . mock ( 'react-router-dom' , ( ) => ( {
28+ ...jest . requireActual ( 'react-router-dom' ) ,
29+ useNavigate : ( ) => mockNavigate ,
30+ } ) ) ;
31+
2632const render = ( containerId : string , showOnlyPublished : boolean = false ) => {
2733 const params : { libraryId : string , selectedItemId ?: string } = { libraryId, selectedItemId : containerId } ;
2834 return baseRender ( < ContainerInfo /> , {
@@ -141,6 +147,7 @@ let mockShowToast: { (message: string, action?: ToastActionData | undefined): vo
141147 } ) ;
142148
143149 it ( `shows the ${ containerType } Preview tab by default and the children are readonly` , async ( ) => {
150+ const user = userEvent . setup ( ) ;
144151 render ( containerId ) ;
145152 const previewTab = await screen . findByText ( 'Preview' ) ;
146153 expect ( previewTab ) . toBeInTheDocument ( ) ;
@@ -149,11 +156,36 @@ let mockShowToast: { (message: string, action?: ToastActionData | undefined): vo
149156 // Check that there are no edit buttons for components titles
150157 expect ( screen . queryAllByRole ( 'button' , { name : / e d i t / i } ) . length ) . toBe ( 0 ) ;
151158
152- // Check that there are no drag handle for components
159+ // Check that there are no drag handle for components/containers
153160 expect ( screen . queryAllByRole ( 'button' , { name : 'Drag to reorder' } ) . length ) . toBe ( 0 ) ;
154161
155162 // Check that there are no menu buttons for components
156163 expect ( screen . queryAllByRole ( 'button' , { name : / c o m p o n e n t a c t i o n s m e n u / i } ) . length ) . toBe ( 0 ) ;
164+
165+ let childType : string ;
166+ switch ( containerType ) {
167+ case ContainerType . Section :
168+ childType = ContainerType . Subsection ;
169+ break ;
170+ case ContainerType . Subsection :
171+ childType = ContainerType . Unit ;
172+ break ;
173+ case ContainerType . Unit :
174+ childType = 'text' ;
175+ break ;
176+ default :
177+ break ;
178+ }
179+ const child = await screen . findByText ( `${ childType ! } block 0` ) ;
180+ screen . debug ( child . parentElement ! . parentElement ! . parentElement ! ) ;
181+ // Check that there are no menu buttons for containers
182+ expect ( within (
183+ child . parentElement ! . parentElement ! . parentElement ! ,
184+ ) . queryAllByRole ( 'button' , { name : / c o n t a i n e r a c t i o n s m e n u / i } ) . length ) . toBe ( 0 ) ;
185+ // Trigger double click. Find the child card as the parent element
186+ await user . dblClick ( child . parentElement ! . parentElement ! . parentElement ! ) ;
187+ // Click should not do anything in preview
188+ expect ( mockNavigate ) . not . toHaveBeenCalled ( ) ;
157189 } ) ;
158190 } ) ;
159191} ) ;
0 commit comments