Skip to content

Commit 8df4f87

Browse files
authored
Merge pull request #10952 from marmelab/fix-filter-live-form
Fix `<FilterLiveForm>` may override latest users inputs when they type at the same pace than the debounce delay
2 parents 97866fe + 85bba42 commit 8df4f87

File tree

3 files changed

+190
-149
lines changed

3 files changed

+190
-149
lines changed

packages/ra-core/src/form/FilterLiveForm.spec.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
2+
import userEvent from '@testing-library/user-event';
3+
24
import { getFilterFormValues } from './FilterLiveForm';
35
import {
46
Basic,
@@ -20,6 +22,22 @@ describe('<FilterLiveForm />', () => {
2022
const input = await screen.findByLabelText('title');
2123
fireEvent.change(input, { target: { value: 'foo' } });
2224
await screen.findByText('{"category":"deals","title":"foo"}');
25+
await new Promise(resolve => setTimeout(resolve, 500));
26+
});
27+
28+
it('should work when users type at the exact same pace than the debounce delay', async () => {
29+
render(
30+
<Basic
31+
ListBaseProps={{ debounce: 100 }}
32+
FilterLiveFormProps={{ debounce: 100 }}
33+
/>
34+
);
35+
const input = await screen.findByLabelText('title');
36+
await userEvent.type(input, 'foo', {
37+
delay: 100,
38+
});
39+
screen.getByDisplayValue('foo');
40+
await screen.findByText('{"category":"deals","title":"foo"}');
2341
});
2442

2543
it('should allow to clear a filter value', async () => {

0 commit comments

Comments
 (0)