diff --git a/packages/mui-base/src/MenuButton/MenuButton.test.tsx b/packages/mui-base/src/MenuButton/MenuButton.test.tsx index 4a4624f034..a95219f24b 100644 --- a/packages/mui-base/src/MenuButton/MenuButton.test.tsx +++ b/packages/mui-base/src/MenuButton/MenuButton.test.tsx @@ -11,10 +11,6 @@ import { } from '@base_ui/react/useDropdown'; import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled'; -// TODO v6: initialize @testing-library/user-event using userEvent.setup() instead of directly calling methods e.g. userEvent.click() for all related tests in this file -// currently the setup() method uses the ClipboardEvent constructor which is incompatible with our lowest supported version of iOS Safari (12.2) https://github.com/mui/material-ui/blob/master/.browserslistrc#L44 -// userEvent.setup() requires Safari 14 or up to work - const testContext: DropdownContextValue = { dispatch: () => {}, popupId: 'menu-popup', @@ -146,6 +142,8 @@ describe('', () => { dispatch: dispatchSpy, }; + const user = userEvent.setup(); + const { getByRole } = render( {buttonComponent}, ); @@ -155,7 +153,7 @@ describe('', () => { button.focus(); }); - await userEvent.keyboard(`{${key}}`); + await user.keyboard(`{${key}}`); expect(dispatchSpy.calledOnce).to.equal(true); expect(dispatchSpy.args[0][0]).to.contain({ type: DropdownActionTypes.open }); @@ -171,6 +169,8 @@ describe('', () => { dispatch: dispatchSpy, }; + const user = userEvent.setup(); + const { getByRole } = render( {buttonComponent}, ); @@ -180,7 +180,7 @@ describe('', () => { button.focus(); }); - await userEvent.keyboard(`{${key}}`); + await user.keyboard(`{${key}}`); expect(dispatchSpy.calledOnce).to.equal(true); expect(dispatchSpy.args[0][0]).to.contain({ type: DropdownActionTypes.toggle }); diff --git a/packages/mui-base/src/Select/Select.test.tsx b/packages/mui-base/src/Select/Select.test.tsx index 57895a72eb..cf7a79fe5a 100644 --- a/packages/mui-base/src/Select/Select.test.tsx +++ b/packages/mui-base/src/Select/Select.test.tsx @@ -18,10 +18,6 @@ import { Option, OptionProps, OptionRootSlotProps, optionClasses } from '@base_u import { OptionGroup } from '@base_ui/react/OptionGroup'; import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled'; -// TODO v6: initialize @testing-library/user-event using userEvent.setup() instead of directly calling methods e.g. userEvent.click() for all related tests in this file -// currently the setup() method uses the ClipboardEvent constructor which is incompatible with our lowest supported version of iOS Safari (12.2) https://github.com/mui/material-ui/blob/master/.browserslistrc#L44 -// userEvent.setup() requires Safari 14 or up to work - describe('', () => { const triggerType = selectComponent.props.slots?.root ? 'non-native' : 'native'; ['Enter', 'ArrowDown', 'ArrowUp', ' '].forEach((key) => { it(`opens the dropdown when the "${key}" key is pressed on a ${triggerType} button trigger`, async () => { + const user = userEvent.setup(); + const { getByRole } = await render(selectComponent); + const select = getByRole('combobox'); act(() => { select.focus(); }); - await userEvent.keyboard(`{${key}}`); + await user.keyboard(`{${key}}`); expect(select).to.have.attribute('aria-expanded', 'true'); expect(getByRole('listbox')).not.to.equal(null); @@ -131,6 +130,8 @@ describe(' @@ -142,7 +143,8 @@ describe('', () => { ['Enter', ' '].forEach((key) => { it(`does not close the multiselect dropdown when the "${key}" key is pressed`, async () => { + const user = userEvent.setup(); + const { getByRole, queryByRole } = await render( ', () => { select.click(); }); - await userEvent.keyboard(`{${key}}`); + await user.keyboard(`{${key}}`); expect(select).to.have.attribute('aria-expanded', 'true'); expect(queryByRole('listbox')).not.to.equal(null); @@ -171,6 +175,8 @@ describe(' @@ -180,9 +186,9 @@ describe('', () => { ['Enter', ' '].forEach((key) => it(`selects a highlighted item using the "${key}" key in multiple mode`, async () => { + const user = userEvent.setup(); + const { getByRole } = await render( ', () => { const select = getByRole('combobox'); - await userEvent.pointer({ target: select, keys: '[MouseLeft]' }); - await userEvent.keyboard(`{${key}}`); - await userEvent.keyboard('{ArrowDown}'); - await userEvent.keyboard(`{${key}}`); + await user.pointer({ target: select, keys: '[MouseLeft]' }); + await user.keyboard(`{${key}}`); + await user.keyboard('{ArrowDown}'); + await user.keyboard(`{${key}}`); expect(select).to.have.text('1, 2'); }), @@ -211,6 +219,8 @@ describe(' @@ -227,15 +237,17 @@ describe(' @@ -252,11 +264,11 @@ describe('', () => { ); } + const user = userEvent.setup(); + const { getByRole, getByTestId } = await render( ', () => { select.click(); }); - await userEvent.keyboard('d'); + await user.keyboard('d'); expect(getByTestId('5')).to.have.class(optionClasses.highlighted); - await userEvent.keyboard('r'); + await user.keyboard('r'); expect(getByTestId('5')).to.have.class(optionClasses.highlighted); - await userEvent.keyboard('z'); + await user.keyboard('z'); expect(getByTestId('5')).to.have.class(optionClasses.highlighted); }); it('skips the non-stringifiable options', async () => { + const user = userEvent.setup(); + const { getByRole, getByText } = await render( ', () => { select.click(); }); - await userEvent.keyboard('c'); + await user.keyboard('c'); expect(getByText('Cherry')).to.have.class(optionClasses.highlighted); - await userEvent.keyboard('c'); + await user.keyboard('c'); expect(getByText('Calamondin')).to.have.class(optionClasses.highlighted); - await userEvent.keyboard('c'); + await user.keyboard('c'); expect(getByText('Cherry')).to.have.class(optionClasses.highlighted); }); it('navigate to options with diacritic characters', async () => { + const user = userEvent.setup(); + const { getByRole, getByText } = await render( ', () => { select.click(); }); - await userEvent.keyboard('b'); + await user.keyboard('b'); expect(getByText('Ba')).to.have.class(optionClasses.highlighted); - await userEvent.keyboard('{Control>}{Alt>}ą{/Alt}{/Control}'); + await user.keyboard('{Control>}{Alt>}ą{/Alt}{/Control}'); expect(getByText('Bą')).to.have.class(optionClasses.highlighted); }); it('navigate to next options with beginning diacritic characters', async () => { + const user = userEvent.setup(); + const { getByRole, getByText } = await render( ', () => { select.click(); }); - await userEvent.keyboard('{Control>}{Alt>}ą{/Alt}{/Control}'); + await user.keyboard('{Control>}{Alt>}ą{/Alt}{/Control}'); expect(getByText('ąa')).to.have.class(optionClasses.highlighted); - await userEvent.keyboard('{Alt>}{Control>}ą{/Control}{/Alt}'); + await user.keyboard('{Alt>}{Control>}ą{/Control}{/Alt}'); expect(getByText('ąb')).to.have.class(optionClasses.highlighted); - await userEvent.keyboard('{Control>}{AltGraph>}ą{/AltGraph}{/Control}'); + await user.keyboard('{Control>}{AltGraph>}ą{/AltGraph}{/Control}'); expect(getByText('ąc')).to.have.class(optionClasses.highlighted); }); }); it('closes the listbox without selecting an option when "Escape" is pressed', async () => { + const user = userEvent.setup(); + const { getByRole, queryByRole } = await render( ', () => { select.click(); }); - await userEvent.keyboard('{ArrowDown}'); // highlights '2' - await userEvent.keyboard('{Escape}'); + await user.keyboard('{ArrowDown}'); // highlights '2' + await user.keyboard('{Escape}'); expect(select).to.have.attribute('aria-expanded', 'false'); expect(select).to.have.text('1'); @@ -399,6 +421,8 @@ describe(' @@ -408,9 +432,9 @@ describe('', () => { return @@ -1082,16 +1110,18 @@ describe(' @@ -1111,7 +1141,8 @@ describe('', () => { return
  • ; }); + const user = userEvent.setup(); + const { getByRole } = await render(