@@ -4,17 +4,17 @@ import type MockAdapter from 'axios-mock-adapter';
4
4
import {
5
5
initializeMocks , render as baseRender , screen , waitFor ,
6
6
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' ;
8
12
import { mockContentLibrary , mockGetContainerChildren , mockGetContainerMetadata } from '../data/api.mocks' ;
9
13
import { LibraryProvider } from '../common/context/LibraryContext' ;
10
14
import ContainerInfo from './ContainerInfo' ;
11
15
import { getLibraryContainerApiUrl , getLibraryContainerPublishApiUrl } from '../data/api' ;
12
16
import { 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' ;
16
17
17
- mockGetContainerMetadata . applyMock ( ) ;
18
18
mockContentLibrary . applyMock ( ) ;
19
19
mockContentSearchConfig . applyMock ( ) ;
20
20
mockGetContainerMetadata . applyMock ( ) ;
@@ -23,6 +23,12 @@ mockGetContainerChildren.applyMock();
23
23
const { libraryId } = mockContentLibrary ;
24
24
const { unitId, subsectionId, sectionId } = mockGetContainerMetadata ;
25
25
26
+ const mockNavigate = jest . fn ( ) ;
27
+ jest . mock ( 'react-router-dom' , ( ) => ( {
28
+ ...jest . requireActual ( 'react-router-dom' ) ,
29
+ useNavigate : ( ) => mockNavigate ,
30
+ } ) ) ;
31
+
26
32
const render = ( containerId : string , showOnlyPublished : boolean = false ) => {
27
33
const params : { libraryId : string , selectedItemId ?: string } = { libraryId, selectedItemId : containerId } ;
28
34
return baseRender ( < ContainerInfo /> , {
@@ -141,6 +147,7 @@ let mockShowToast: { (message: string, action?: ToastActionData | undefined): vo
141
147
} ) ;
142
148
143
149
it ( `shows the ${ containerType } Preview tab by default and the children are readonly` , async ( ) => {
150
+ const user = userEvent . setup ( ) ;
144
151
render ( containerId ) ;
145
152
const previewTab = await screen . findByText ( 'Preview' ) ;
146
153
expect ( previewTab ) . toBeInTheDocument ( ) ;
@@ -149,11 +156,36 @@ let mockShowToast: { (message: string, action?: ToastActionData | undefined): vo
149
156
// Check that there are no edit buttons for components titles
150
157
expect ( screen . queryAllByRole ( 'button' , { name : / e d i t / i } ) . length ) . toBe ( 0 ) ;
151
158
152
- // Check that there are no drag handle for components
159
+ // Check that there are no drag handle for components/containers
153
160
expect ( screen . queryAllByRole ( 'button' , { name : 'Drag to reorder' } ) . length ) . toBe ( 0 ) ;
154
161
155
162
// Check that there are no menu buttons for components
156
163
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 ( ) ;
157
189
} ) ;
158
190
} ) ;
159
191
} ) ;
0 commit comments