From 356512d8f6cdcba917ca8b0e5bc11a0d48d43aa5 Mon Sep 17 00:00:00 2001 From: fzaninotto Date: Tue, 12 Mar 2024 19:11:39 +0100 Subject: [PATCH 1/2] Fix Autocomplete loses focus on select Closes #9715 --- .../src/input/AutocompleteArrayInput.spec.tsx | 4 +++- packages/ra-ui-materialui/src/input/AutocompleteInput.tsx | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/ra-ui-materialui/src/input/AutocompleteArrayInput.spec.tsx b/packages/ra-ui-materialui/src/input/AutocompleteArrayInput.spec.tsx index 521c5d54af4..27c6af76458 100644 --- a/packages/ra-ui-materialui/src/input/AutocompleteArrayInput.spec.tsx +++ b/packages/ra-ui-materialui/src/input/AutocompleteArrayInput.spec.tsx @@ -1081,7 +1081,9 @@ describe('', () => { ); }); expect(screen.getByDisplayValue('Russian')).not.toBeNull(); - screen.getAllByRole('textbox')[0].focus(); + fireEvent.keyDown(screen.getAllByRole('textbox')[0], { + key: 'ArrowDown', + }); fireEvent.click(await screen.findByText('Victor Hugo')); await waitFor(() => { expect(onChange).toHaveBeenCalledWith( diff --git a/packages/ra-ui-materialui/src/input/AutocompleteInput.tsx b/packages/ra-ui-materialui/src/input/AutocompleteInput.tsx index 43c05af43e1..b267870823d 100644 --- a/packages/ra-ui-materialui/src/input/AutocompleteInput.tsx +++ b/packages/ra-ui-materialui/src/input/AutocompleteInput.tsx @@ -555,7 +555,6 @@ If you provided a React element for the optionText prop, you must also provide t return ( <> Date: Tue, 12 Mar 2024 20:47:54 +0100 Subject: [PATCH 2/2] Fix unit test --- .../src/list/filter/FilterButton.spec.tsx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/ra-ui-materialui/src/list/filter/FilterButton.spec.tsx b/packages/ra-ui-materialui/src/list/filter/FilterButton.spec.tsx index b8a99441622..4d5c27e345f 100644 --- a/packages/ra-ui-materialui/src/list/filter/FilterButton.spec.tsx +++ b/packages/ra-ui-materialui/src/list/filter/FilterButton.spec.tsx @@ -1,6 +1,7 @@ import * as React from 'react'; import expect from 'expect'; import { render, fireEvent, screen, waitFor } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; import { createTheme } from '@mui/material/styles'; import { AdminContext } from '../../AdminContext'; @@ -25,6 +26,10 @@ describe('', () => { filterValues: {}, }; + beforeAll(() => { + window.scrollTo = jest.fn(); + }); + describe('filter selection menu', () => { it('should display only hidden filters', () => { const hiddenFilter = ( @@ -189,14 +194,14 @@ describe('', () => { render(); // Open Posts List - fireEvent.click(await screen.findByText('Posts')); + userEvent.click(await screen.findByText('Posts')); await waitFor(() => { expect(screen.queryAllByRole('checkbox')).toHaveLength(11); }); - fireEvent.click(await screen.findByLabelText('Open')); - fireEvent.click(await screen.findByText('Sint...')); + userEvent.click(await screen.findByLabelText('Open')); + userEvent.click(await screen.findByText('Sint...')); await waitFor( () => { @@ -205,15 +210,15 @@ describe('', () => { { timeout: 10000 } ); - fireEvent.click(screen.getByLabelText('Add filter')); - fireEvent.click(screen.getByText('Remove all filters')); + userEvent.click(screen.getByLabelText('Add filter')); + userEvent.click(screen.getByText('Remove all filters')); await waitFor(() => { expect(screen.getAllByRole('checkbox')).toHaveLength(11); }); - fireEvent.click(screen.getByLabelText('Open')); - fireEvent.click(screen.getByText('Sint...')); + userEvent.click(screen.getByLabelText('Open')); + userEvent.click(screen.getByText('Sint...')); await waitFor(() => { expect(