Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tdnl committed Sep 5, 2023
1 parent ee76753 commit 4de3980
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
Expand Up @@ -992,7 +992,7 @@ describe('<AutocompleteInput />', () => {
</AdminContext>
);
const input = screen.getByLabelText('resources.users.fields.role');
fireEvent.change(input, { target: { value: 'a' } });
userEvent.type(input, 'a');
await waitFor(() => {
expect(screen.queryAllByRole('option').length).toEqual(2);
});
Expand All @@ -1019,7 +1019,7 @@ describe('<AutocompleteInput />', () => {
</AdminContext>
);
const input = screen.getByLabelText('resources.users.fields.role');
fireEvent.change(input, { target: { value: 'ab' } });
userEvent.type(input, 'ab');
await waitFor(() =>
expect(screen.queryAllByRole('option').length).toEqual(2)
);
Expand Down Expand Up @@ -1355,8 +1355,7 @@ describe('<AutocompleteInput />', () => {
'Author'
)) as HTMLInputElement;
expect(input.value).toBe('Leo Tolstoy');
fireEvent.mouseDown(input);
fireEvent.change(input, { target: { value: 'Leo Tolstoy test' } });
userEvent.type(input, 'Leo Tolstoy test');
// Make sure that 'Leo Tolstoy' did not reappear
let testFailed = false;
try {
Expand Down
Expand Up @@ -1121,10 +1121,11 @@ export const WithInputOnChange = () => {
source="role"
resource="users"
choices={[
{ id: 1, name: 'bar' },
{ id: 2, name: 'foo' },
{ id: 1, name: 'ab' },
{ id: 2, name: 'abc' },
{ id: 3, name: '123' },
]}
onInputChange={(_, value: string) => {
onInputChange={(_, value) => {
setSearchText(value);
}}
/>
Expand Down
7 changes: 2 additions & 5 deletions packages/ra-ui-materialui/src/input/AutocompleteInput.tsx
Expand Up @@ -528,13 +528,10 @@ If you provided a React element for the optionText prop, you must also provide t
>['onInputChange']
>(
(event, newInputValue, reason) => {
if (
typeof event?.type === 'string' ||
!doesQueryMatchSelection(newInputValue)
) {
setFilterValue(newInputValue);
if (!doesQueryMatchSelection(newInputValue)) {
debouncedSetFilter(newInputValue);
}
setFilterValue(newInputValue);
onInputChange?.(event, newInputValue, reason);
},
[debouncedSetFilter, doesQueryMatchSelection, onInputChange]
Expand Down

0 comments on commit 4de3980

Please sign in to comment.