Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/ra-ui-materialui/src/layout/Notification.spec.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -8,6 +9,29 @@ import {
} from './Notification.stories';

describe('<Notification />', () => {
(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(
<ConsecutiveUndoable dataProvider={dataProvider} />
);

(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()
Expand Down
8 changes: 6 additions & 2 deletions packages/ra-ui-materialui/src/layout/Notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? (
Expand Down
Loading