@@ -3,7 +3,11 @@ import expect from 'expect';
33import { Route , Routes } from 'react-router' ;
44import { fireEvent , screen , render , waitFor } from '@testing-library/react' ;
55
6- import { testDataProvider } from '../../dataProvider' ;
6+ import {
7+ testDataProvider ,
8+ UndoableMutation ,
9+ useTakeUndoableMutation ,
10+ } from '../../dataProvider' ;
711import { CoreAdminContext } from '../../core' ;
812import useDeleteWithUndoController , {
913 UseDeleteWithUndoControllerParams ,
@@ -22,6 +26,12 @@ describe('useDeleteWithUndoController', () => {
2226 } ) ,
2327 } ) ;
2428
29+ let takeMutation : ( ) => UndoableMutation | void ;
30+ const MutationTrigger = ( ) => {
31+ takeMutation = useTakeUndoableMutation ( ) ;
32+ return null ;
33+ } ;
34+
2535 const MockComponent = ( ) => {
2636 const { handleDelete } = useDeleteWithUndoController ( {
2737 record : { id : 1 } ,
@@ -38,13 +48,20 @@ describe('useDeleteWithUndoController', () => {
3848 < Routes >
3949 < Route path = "/" element = { < MockComponent /> } />
4050 </ Routes >
51+ < MutationTrigger />
4152 </ CoreAdminContext >
4253 </ TestMemoryRouter >
4354 ) ;
4455
4556 const button = await screen . findByText ( 'Delete' ) ;
4657 fireEvent . click ( button ) ;
47- waitFor ( ( ) => expect ( receivedMeta ) . toEqual ( 'metadata' ) , {
58+
59+ // Trigger the mutation.
60+ await waitFor ( ( ) => new Promise ( resolve => setTimeout ( resolve , 0 ) ) ) ;
61+ const mutation = takeMutation ( ) ;
62+ if ( mutation ) mutation ( { isUndo : false } ) ;
63+
64+ await waitFor ( ( ) => expect ( receivedMeta ) . toEqual ( 'metadata' ) , {
4865 timeout : 1000 ,
4966 } ) ;
5067 } ) ;
0 commit comments