Skip to content

Commit 95537ad

Browse files
committed
Fix <SaveButton> test
1 parent 1178838 commit 95537ad

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

packages/ra-ui-materialui/src/button/SaveButton.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ describe('<SaveButton />', () => {
7272

7373
it('should render an enabled button when the form is dirty', async () => {
7474
render(<Dirty />);
75+
fireEvent.click(await screen.findByText('Make change'));
7576
await waitFor(() =>
7677
expect(screen.getByLabelText('ra.action.save')['disabled']).toEqual(
7778
false

packages/ra-ui-materialui/src/button/SaveButton.stories.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { TextInput } from '../input/TextInput';
1010
import { SimpleFormIterator } from '../input/ArrayInput/SimpleFormIterator';
1111
import { AdminContext } from '../AdminContext';
1212
import { Edit } from '../detail';
13+
import { Button } from './Button';
1314

1415
export default {
1516
title: 'ra-ui-materialui/button/SaveButton',
@@ -26,15 +27,11 @@ export const Basic = () => (
2627
);
2728

2829
const MakeFormChange = () => {
29-
const {
30-
setValue,
31-
formState: { isReady },
32-
} = useFormContext();
33-
React.useEffect(() => {
34-
if (!isReady) return;
30+
const { setValue } = useFormContext();
31+
const handleClick = () => {
3532
setValue('name', 'test', { shouldDirty: true });
36-
}, [isReady, setValue]);
37-
return null;
33+
};
34+
return <Button label="Make change" onClick={handleClick} />;
3835
};
3936

4037
export const Dirty = () => (

0 commit comments

Comments
 (0)