1- import type { ToastActionData } from '../../generic/toast-context' ;
1+ import type { ToastActionData } from '@src/generic/toast-context' ;
2+ import { mockContentSearchConfig , mockSearchResult , hydrateSearchResult } from '@src/search-manager/data/api.mock' ;
23import {
34 fireEvent ,
45 render ,
56 screen ,
67 initializeMocks ,
78 waitFor ,
8- } from '../.. /testUtils' ;
9+ } from '@src /testUtils' ;
910import { LibraryProvider } from '../common/context/LibraryContext' ;
1011import { SidebarProvider } from '../common/context/SidebarContext' ;
1112import {
1213 mockContentLibrary , mockDeleteLibraryBlock , mockLibraryBlockMetadata , mockRestoreLibraryBlock ,
1314} from '../data/api.mocks' ;
1415import ComponentDeleter from './ComponentDeleter' ;
15- import { mockContentSearchConfig , mockSearchResult } from '../../search-manager/data/api.mock' ;
1616
1717mockContentLibrary . applyMock ( ) ; // Not required, but avoids 404 errors in the logs when <LibraryProvider> loads data
1818mockLibraryBlockMetadata . applyMock ( ) ;
@@ -41,28 +41,16 @@ describe('<ComponentDeleter />', () => {
4141 beforeEach ( ( ) => {
4242 const mocks = initializeMocks ( ) ;
4343 mockShowToast = mocks . mockShowToast ;
44- mockSearchResult ( {
45- results : [ // @ts -ignore
46- {
47- hits : [ ] ,
48- } ,
49- ] ,
50- } ) ;
51- } ) ;
52-
53- it ( 'is invisible when isConfirmingDelete is false' , async ( ) => {
54- const mockCancel = jest . fn ( ) ;
55- render ( < ComponentDeleter usageKey = { usageKey } isConfirmingDelete = { false } cancelDelete = { mockCancel } /> , renderArgs ) ;
56-
57- const modal = screen . queryByRole ( 'dialog' , { name : 'Delete Component' } ) ;
58- expect ( modal ) . not . toBeInTheDocument ( ) ;
44+ mockSearchResult ( hydrateSearchResult ( [ {
45+ displayName : 'Introduction to Testing 2' ,
46+ } ] ) ) ;
5947 } ) ;
6048
6149 it ( 'should shows a confirmation prompt the card with title and description' , async ( ) => {
6250 const mockCancel = jest . fn ( ) ;
63- render ( < ComponentDeleter usageKey = { usageKey } isConfirmingDelete cancelDelete = { mockCancel } /> , renderArgs ) ;
51+ render ( < ComponentDeleter usageKey = { usageKey } close = { mockCancel } /> , renderArgs ) ;
6452
65- const modal = screen . getByRole ( 'dialog' , { name : 'Delete Component' } ) ;
53+ const modal = await screen . findByRole ( 'dialog' , { name : 'Delete Component' } ) ;
6654 expect ( modal ) . toBeVisible ( ) ;
6755
6856 // It should mention the component's name in the confirm dialog:
@@ -76,9 +64,9 @@ describe('<ComponentDeleter />', () => {
7664
7765 it ( 'deletes the block when confirmed, shows a toast with undo option and restores block on undo' , async ( ) => {
7866 const mockCancel = jest . fn ( ) ;
79- render ( < ComponentDeleter usageKey = { usageKey } isConfirmingDelete cancelDelete = { mockCancel } /> , renderArgs ) ;
67+ render ( < ComponentDeleter usageKey = { usageKey } close = { mockCancel } /> , renderArgs ) ;
8068
81- const modal = screen . getByRole ( 'dialog' , { name : 'Delete Component' } ) ;
69+ const modal = await screen . findByRole ( 'dialog' , { name : 'Delete Component' } ) ;
8270 expect ( modal ) . toBeVisible ( ) ;
8371
8472 const deleteButton = screen . getByRole ( 'button' , { name : 'Delete' } ) ;
@@ -99,23 +87,17 @@ describe('<ComponentDeleter />', () => {
9987
10088 it ( 'should show units message if `unitsData` is set with one unit' , async ( ) => {
10189 const mockCancel = jest . fn ( ) ;
102- mockSearchResult ( {
103- results : [ // @ts -ignore
104- {
105- hits : [ {
106- units : {
107- displayName : [ 'Unit 1' ] ,
108- key : [ 'unit1' ] ,
109- } ,
110- } ] ,
111- } ,
112- ] ,
113- } ) ;
90+ mockSearchResult ( hydrateSearchResult ( [ {
91+ displayName : 'Introduction to Testing 2' ,
92+ units : {
93+ displayName : [ 'Unit 1' ] ,
94+ key : [ 'unit1' ] ,
95+ } ,
96+ } ] ) ) ;
11497 render (
11598 < ComponentDeleter
11699 usageKey = { usageKey }
117- isConfirmingDelete
118- cancelDelete = { mockCancel }
100+ close = { mockCancel }
119101 /> ,
120102 renderArgs ,
121103 ) ;
@@ -131,23 +113,17 @@ describe('<ComponentDeleter />', () => {
131113
132114 it ( 'should show units message if `unitsData` is set with multiple units' , async ( ) => {
133115 const mockCancel = jest . fn ( ) ;
134- mockSearchResult ( {
135- results : [ // @ts -ignore
136- {
137- hits : [ {
138- units : {
139- displayName : [ 'Unit 1' , 'Unit 2' ] ,
140- key : [ 'unit1' , 'unit2' ] ,
141- } ,
142- } ] ,
143- } ,
144- ] ,
145- } ) ;
116+ mockSearchResult ( hydrateSearchResult ( [ {
117+ displayName : 'Introduction to Testing 2' ,
118+ units : {
119+ displayName : [ 'Unit 1' , 'Unit 2' ] ,
120+ key : [ 'unit1' , 'unit2' ] ,
121+ } ,
122+ } ] ) ) ;
146123 render (
147124 < ComponentDeleter
148125 usageKey = { usageKey }
149- isConfirmingDelete
150- cancelDelete = { mockCancel }
126+ close = { mockCancel }
151127 /> ,
152128 renderArgs ,
153129 ) ;
0 commit comments