diff --git a/packages/ra-ui-materialui/src/layout/Notification.spec.tsx b/packages/ra-ui-materialui/src/layout/Notification.spec.tsx index e92d3686e26..ecc219ea12a 100644 --- a/packages/ra-ui-materialui/src/layout/Notification.spec.tsx +++ b/packages/ra-ui-materialui/src/layout/Notification.spec.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; import { fireEvent, render, screen, waitFor } from '@testing-library/react'; +import { major as muiMajor } from '@mui/material'; import { ConsecutiveNotifications, @@ -8,6 +9,29 @@ import { } from './Notification.stories'; describe('', () => { + (muiMajor >= 6 ? it : it.skip)( + 'should confirm an undoable mutation only once when its notification exits with MUI 6+', + async () => { + const deleteOne = jest + .fn() + .mockImplementation((_resource, { id }) => + Promise.resolve({ data: { id } }) + ); + const dataProvider = { delete: deleteOne } as any; + const { container } = render( + + ); + + (await screen.findByText('Delete post 1')).click(); + await screen.findByText('Post 1 deleted'); + fireEvent.click(container); + + await waitFor(() => expect(deleteOne).toHaveBeenCalled()); + expect(deleteOne).toHaveBeenCalledTimes(1); + expect(deleteOne).toHaveBeenCalledWith('posts', { id: 1 }); + } + ); + it('should confirm the first undoable notification when a second one starts', async () => { const deleteOne = jest .fn() diff --git a/packages/ra-ui-materialui/src/layout/Notification.tsx b/packages/ra-ui-materialui/src/layout/Notification.tsx index 327bd1a1434..a7ab8d9409d 100644 --- a/packages/ra-ui-materialui/src/layout/Notification.tsx +++ b/packages/ra-ui-materialui/src/layout/Notification.tsx @@ -168,8 +168,12 @@ export const Notification = (inProps: NotificationProps) => { : autoHideDurationFromMessage ?? undefined } disableWindowBlurListener={undoable} - TransitionProps={transitionProps} - ContentProps={contentProps} + {...(muiMajor < 6 + ? { + TransitionProps: transitionProps, + ContentProps: contentProps, + } + : {})} onClose={handleRequestClose} action={ undoable ? (