Skip to content

Commit 190513d

Browse files
committed
Fix useUpdate mutationMode cannot be controlled
1 parent 71009e2 commit 190513d

File tree

3 files changed

+399
-2
lines changed

3 files changed

+399
-2
lines changed

packages/ra-core/src/dataProvider/useUpdate.spec.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import * as React from 'react';
2-
import { act, render, screen, waitFor } from '@testing-library/react';
2+
import {
3+
act,
4+
fireEvent,
5+
render,
6+
screen,
7+
waitFor,
8+
} from '@testing-library/react';
39
import expect from 'expect';
410

511
import { CoreAdminContext } from '../core';
@@ -25,6 +31,7 @@ import {
2531
WithMiddlewaresError as WithMiddlewaresErrorUndoable,
2632
} from './useUpdate.undoable.stories';
2733
import { QueryClient } from '@tanstack/react-query';
34+
import { Basic } from './useUpdate.stories';
2835

2936
describe('useUpdate', () => {
3037
describe('mutate', () => {
@@ -368,6 +375,23 @@ describe('useUpdate', () => {
368375
expect(screen.queryByText('mutating')).toBeNull();
369376
});
370377
});
378+
it('allows to control the mutation mode', async () => {
379+
jest.spyOn(console, 'error').mockImplementation(() => {});
380+
render(<Basic timeout={10} />);
381+
await screen.findByText('Hello');
382+
// Update the post in pessimistic mode
383+
fireEvent.click(await screen.findByText('Update title'));
384+
await screen.findByText('Hello World 0');
385+
fireEvent.click(await screen.findByText('undoable'));
386+
fireEvent.click(await screen.findByText('Increment counter'));
387+
// Update a post in undoable mode
388+
fireEvent.click(await screen.findByText('Update title'));
389+
// Check the optimistic result
390+
await screen.findByText('Hello World 1');
391+
// As we haven't confirmed the undoable mutation, refetching the post should return nothing
392+
fireEvent.click(await screen.findByText('Refetch'));
393+
await screen.findByText('Hello World 0');
394+
});
371395
});
372396
describe('query cache', () => {
373397
it('updates getList query cache when dataProvider promise resolves', async () => {

0 commit comments

Comments
 (0)