{}} />);
- userEvent.click(screen.getByText('onTitleClick'));
+ await user.click(screen.getByText('onTitleClick'));
// when
- userEvent.click(screen.getByText('Today'));
+ await user.click(screen.getByText('Today'));
// then
expect(screen.getByTestId('DateView')).toBeInTheDocument();
diff --git a/packages/components/src/DateTimePickers/pickers/DatePicker/DatePicker.test.js b/packages/components/src/DateTimePickers/pickers/DatePicker/DatePicker.test.js
index bc702399146..70243a3792f 100644
--- a/packages/components/src/DateTimePickers/pickers/DatePicker/DatePicker.test.js
+++ b/packages/components/src/DateTimePickers/pickers/DatePicker/DatePicker.test.js
@@ -171,7 +171,9 @@ describe('DatePicker', () => {
expect(startDateTableCell).toHaveClass('theme-date-range');
});
- it('should select date', () => {
+ it('should select date', async () => {
+ const user = userEvent.setup();
+
// given
const calendar = { year: YEAR, monthIndex: MONTH_INDEX };
const onSelect = jest.fn();
@@ -186,7 +188,7 @@ describe('DatePicker', () => {
expect(onSelect).not.toHaveBeenCalled();
// when
- userEvent.click(screen.getAllByText('1')[0]);
+ await user.click(screen.getAllByText('1')[0]);
// then
expect(onSelect).toHaveBeenCalledWith(expect.anything(), new Date(YEAR, MONTH_INDEX, 1));
@@ -234,7 +236,9 @@ describe('DatePicker', () => {
expect(screen.getAllByRole('button')).toHaveLength(6 * 7);
});
- it('should go to next month if select a date of next month', () => {
+ it('should go to next month if select a date of next month', async () => {
+ const user = userEvent.setup();
+
const year = 2019;
const monthIndex = 11;
const calendar = { year, monthIndex };
@@ -246,7 +250,7 @@ describe('DatePicker', () => {
goToNextMonth: jest.fn(),
};
render();
- userEvent.click(screen.getAllByText('4')[1]);
+ await user.click(screen.getAllByText('4')[1]);
const selectedDate = new Date(year + 1, 0, 4);
expect(props.onSelect).toHaveBeenCalledWith(expect.anything(), selectedDate);
expect(props.goToNextMonth).toHaveBeenCalled();
diff --git a/packages/components/src/DateTimePickers/views/DateView/DateView.test.js b/packages/components/src/DateTimePickers/views/DateView/DateView.test.js
index bc34981c843..fe045c2c271 100644
--- a/packages/components/src/DateTimePickers/views/DateView/DateView.test.js
+++ b/packages/components/src/DateTimePickers/views/DateView/DateView.test.js
@@ -31,7 +31,9 @@ describe('DateView', () => {
expect(container.firstChild).toMatchSnapshot();
});
- it('should trigger props.onTitleClick when title is clicked', () => {
+ it('should trigger props.onTitleClick when title is clicked', async () => {
+ const user = userEvent.setup();
+
// given
const onTitleClick = jest.fn();
render(
@@ -49,7 +51,7 @@ describe('DateView', () => {
expect(onTitleClick).not.toHaveBeenCalled();
// when
- userEvent.click(screen.getByLabelText('Switch to month-and-year view'));
+ await user.click(screen.getByLabelText('Switch to month-and-year view'));
// then
expect(onTitleClick).toHaveBeenCalled();
@@ -118,7 +120,9 @@ describe('DateView', () => {
button: 'next',
expectedMonthYear: { monthIndex: 0, year: 2007 },
},
- ])('$name', ({ calendar, button, expectedMonthYear }) => {
+ ])('$name', async ({ calendar, button, expectedMonthYear }) => {
+ const user = userEvent.setup();
+
// given
const onSelectMonthYear = jest.fn();
render(
@@ -134,9 +138,9 @@ describe('DateView', () => {
// when
if (button === 'previous') {
- userEvent.click(screen.getByLabelText('Go to previous month'));
+ await user.click(screen.getByLabelText('Go to previous month'));
} else if (button === 'next') {
- userEvent.click(screen.getByLabelText('Go to next month'));
+ await user.click(screen.getByLabelText('Go to next month'));
}
// then
diff --git a/packages/components/src/Enumeration/Items/Item/ItemEdit.component.js b/packages/components/src/Enumeration/Items/Item/ItemEdit.component.js
index 0ca8627d00f..0dc1eb2a607 100644
--- a/packages/components/src/Enumeration/Items/Item/ItemEdit.component.js
+++ b/packages/components/src/Enumeration/Items/Item/ItemEdit.component.js
@@ -1,7 +1,6 @@
import PropTypes from 'prop-types';
import { Component } from 'react';
import classNames from 'classnames';
-import keycode from 'keycode';
import { withTranslation } from 'react-i18next';
import Action from '../../../Actions/Action';
@@ -44,11 +43,12 @@ class ItemEdit extends Component {
}
onKeyDown(event) {
- switch (event.keyCode) {
- case keycode('escape'):
+ switch (event.key) {
+ case 'Esc':
+ case 'Escape':
this.cancel(event);
break;
- case keycode('enter'):
+ case 'Enter':
this.submit(event);
break;
default:
@@ -144,6 +144,7 @@ class ItemEdit extends Component {
type="text"
onKeyDown={this.onKeyDown}
onChange={this.itemChange}
+ // eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus
/>
diff --git a/packages/components/src/Enumeration/Items/Item/ItemEdit.test.js b/packages/components/src/Enumeration/Items/Item/ItemEdit.test.js
index 6494ab45db0..4ee10eb63aa 100644
--- a/packages/components/src/Enumeration/Items/Item/ItemEdit.test.js
+++ b/packages/components/src/Enumeration/Items/Item/ItemEdit.test.js
@@ -31,7 +31,9 @@ describe('Item', () => {
beforeEach(() => {
jest.resetAllMocks();
});
- it('should display value with two buttons and trigger callback on button title click', () => {
+ it('should display value with two buttons and trigger callback on button title click', async () => {
+ const user = userEvent.setup();
+
// given
const props = {
item,
@@ -44,13 +46,15 @@ describe('Item', () => {
render();
// when
- userEvent.click(screen.getByLabelText('Cancel'));
+ await user.click(screen.getByLabelText('Cancel'));
// then
expect(props.item.itemProps.actions[1].onClick).toHaveBeenCalled();
});
- it('should trigger callback on input title ENTER', () => {
+ it('should trigger callback on input title ENTER', async () => {
+ const user = userEvent.setup();
+
// given
const props = {
item,
@@ -83,10 +87,10 @@ describe('Item', () => {
// when
const input = screen.getAllByRole('gridcell')[0];
- userEvent.click(input);
+ await user.click(input);
input.value = '';
- userEvent.type(input, 'my new title');
- userEvent.keyboard('{Enter}');
+ await user.type(input, 'my new title');
+ await user.keyboard('{Enter}');
// then
expect(props.item.itemProps.onSubmitItem).toHaveBeenCalled();
@@ -94,7 +98,9 @@ describe('Item', () => {
expect(callArgs[1]).toEqual({ value: 'my new title', model: props.item, index: 0 });
});
- it('should trigger callback on input title ESC', () => {
+ it('should trigger callback on input title ESC', async () => {
+ const user = userEvent.setup();
+
// given
const props = {
item,
@@ -124,8 +130,8 @@ describe('Item', () => {
// when
render();
- userEvent.click(screen.getAllByRole('gridcell')[0]);
- userEvent.keyboard('{Escape}');
+ await user.click(screen.getAllByRole('gridcell')[0]);
+ await user.keyboard('{Escape}');
// then
expect(props.item.itemProps.onAbortItem).toHaveBeenCalled();
diff --git a/packages/components/src/HeaderBar/HeaderBar.test.js b/packages/components/src/HeaderBar/HeaderBar.test.js
index 0ddb1d785ed..2bcb37159d1 100644
--- a/packages/components/src/HeaderBar/HeaderBar.test.js
+++ b/packages/components/src/HeaderBar/HeaderBar.test.js
@@ -9,7 +9,9 @@ describe('HeaderBar', () => {
expect(container.firstChild).toMatchSnapshot();
});
- it('should render logo', () => {
+ it('should render logo', async () => {
+ const user = userEvent.setup();
+
// GIVEN
const logo = {
id: 'logo',
@@ -27,7 +29,7 @@ describe('HeaderBar', () => {
expect(element).toHaveAttribute('aria-label', logo.label);
// THEN trigger onClick
- userEvent.click(element);
+ await user.click(element);
expect(logo.onClick).toHaveBeenCalled();
});
@@ -77,7 +79,9 @@ describe('HeaderBar', () => {
expect(element).toHaveTextContent('Intercom chat');
});
- it('should render search', () => {
+ it('should render search', async () => {
+ const user = userEvent.setup();
+
// GIVEN
const search = {
id: 'search',
@@ -97,11 +101,13 @@ describe('HeaderBar', () => {
expect(element).toBeVisible();
// THEN trigger onClick
- userEvent.click(element);
+ await user.click(element);
expect(search.onToggle).toHaveBeenCalled();
});
- it('should render help', () => {
+ it('should render help', async () => {
+ const user = userEvent.setup();
+
// GIVEN
const help = {
id: 'help',
@@ -114,13 +120,15 @@ describe('HeaderBar', () => {
const element = screen.getAllByRole('button')[1];
expect(element).toHaveAttribute('aria-label', 'Help');
// THEN trigger onClick
- userEvent.click(element);
+ await user.click(element);
expect(help.onClick).toHaveBeenCalled();
});
- it('should render user', () => {
+ it('should render user', async () => {
+ const user = userEvent.setup();
+
// GIVEN
- const user = {
+ const userIdentity = {
id: 'user',
items: [
{
@@ -136,23 +144,25 @@ describe('HeaderBar', () => {
onClick: jest.fn(),
};
// WHEN
- render();
+ render();
// THEN check user button
const userBtn = screen.getAllByRole('button').find(btn => btn.id === 'user');
- expect(userBtn).toHaveTextContent(user.name);
+ expect(userBtn).toHaveTextContent(userIdentity.name);
expect(userBtn).toHaveAttribute('aria-expanded', 'false');
// THEN trigger user onClick
- userEvent.click(userBtn);
+ await user.click(userBtn);
expect(userBtn).toHaveAttribute('aria-expanded', 'true');
// THEN check user button
const settingsLink = screen.getAllByRole('menuitem')[0];
- expect(settingsLink).toHaveTextContent(user.items[0].label);
+ expect(settingsLink).toHaveTextContent(userIdentity.items[0].label);
// THEN check settings onClick
- userEvent.click(settingsLink);
- expect(user.items[0].onClick).toHaveBeenCalled();
+ await user.click(settingsLink);
+ expect(userIdentity.items[0].onClick).toHaveBeenCalled();
});
- it('should render products', () => {
+ it('should render products', async () => {
+ const user = userEvent.setup();
+
const products = {
items: [
{
@@ -186,18 +196,20 @@ describe('HeaderBar', () => {
const brandBtn = screen.getAllByRole('button').find(btn => btn.id === 'brand');
expect(brandBtn).toHaveTextContent(brand.label);
// THEN trigger brand onClick
- userEvent.click(brandBtn);
+ await user.click(brandBtn);
expect(brandBtn).toHaveAttribute('aria-expanded', 'true');
// THEN check user button
const tdpLink = screen.getAllByRole('menuitem')[0];
expect(tdpLink).toHaveTextContent(products.items[0].label);
// THEN check TDP onClick
- userEvent.click(tdpLink);
+ await user.click(tdpLink);
expect(products.items[0].onClick).toHaveBeenCalled();
});
- it('should render genericAction', () => {
+ it('should render genericAction', async () => {
+ const user = userEvent.setup();
+
// GIVEN
const genericAction = {
id: 'generic-action',
@@ -211,7 +223,7 @@ describe('HeaderBar', () => {
const element = screen.getAllByRole('button')[1];
expect(element).toHaveAttribute('aria-label', genericAction.label);
// THEN trigger onClick
- userEvent.click(element);
+ await user.click(element);
expect(genericAction.onClick).toHaveBeenCalled();
});
});
diff --git a/packages/components/src/List/ListComposition/ColumnChooser/ColumnChooser.component.test.js b/packages/components/src/List/ListComposition/ColumnChooser/ColumnChooser.component.test.js
index b3e3692af23..c34c2a9e1bc 100644
--- a/packages/components/src/List/ListComposition/ColumnChooser/ColumnChooser.component.test.js
+++ b/packages/components/src/List/ListComposition/ColumnChooser/ColumnChooser.component.test.js
@@ -1,4 +1,4 @@
-import { screen, render } from '@testing-library/react';
+import { screen, render, act } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import ColumnChooser from './ColumnChooser.component';
import { ListContext } from '../context';
@@ -30,7 +30,7 @@ describe('ColumnChooser', () => {
// then
expect(screen.getByRole('button')).toBeVisible();
- screen.getByRole('button').focus(); // trigger the tooltip
+ act(() => screen.getByRole('button').focus()); // trigger the tooltip
expect(screen.getByText('Open the column chooser')).toBeVisible();
});
diff --git a/packages/components/src/List/ListToVirtualizedList/ListToVirtualizedList.test.js b/packages/components/src/List/ListToVirtualizedList/ListToVirtualizedList.test.js
index e3fbf85308d..0ed086f8e1c 100644
--- a/packages/components/src/List/ListToVirtualizedList/ListToVirtualizedList.test.js
+++ b/packages/components/src/List/ListToVirtualizedList/ListToVirtualizedList.test.js
@@ -157,6 +157,8 @@ describe('ListToVirtualizedList', () => {
});
it('should find renderer based on column type', async () => {
+ const user = userEvent.setup();
+
// given
const renderer = function test() {
return 'ok';
@@ -165,7 +167,7 @@ describe('ListToVirtualizedList', () => {
render();
// when
- await userEvent.click(screen.getByText('getProps'));
+ await user.click(screen.getByText('getProps'));
const renderProps = VirtualizedList.getProps.mock.calls[0][0];
const CellActions = VirtualizedList.cellDictionary.actions;
const CellBadge = VirtualizedList.cellDictionary.badge;
@@ -180,6 +182,8 @@ describe('ListToVirtualizedList', () => {
});
it('should support custom header renderer', async () => {
+ const user = userEvent.setup();
+
// given
const renderer = function test() {
return 'ok';
@@ -188,7 +192,7 @@ describe('ListToVirtualizedList', () => {
render();
// when
- await userEvent.click(screen.getByText('getProps'));
+ await user.click(screen.getByText('getProps'));
const renderProps = VirtualizedList.getProps.mock.calls[0][0];
// then
@@ -198,13 +202,15 @@ describe('ListToVirtualizedList', () => {
});
it('should support column hide feature', async () => {
+ const user = userEvent.setup();
+
// given
const hideProps = cloneDeep(props);
hideProps.columns.find(column => column.label === 'Tag').hidden = true;
render();
// when
- await userEvent.click(screen.getByText('getProps'));
+ await user.click(screen.getByText('getProps'));
const renderProps = VirtualizedList.getProps.mock.calls[0][0];
// then
@@ -232,6 +238,8 @@ describe('ListToVirtualizedList', () => {
});
it('should adapt sort onChange', async () => {
+ const user = userEvent.setup();
+
// given
const onChange = jest.fn();
render(
@@ -239,7 +247,7 @@ describe('ListToVirtualizedList', () => {
);
// when
- userEvent.click(screen.getByText('getProps'));
+ await user.click(screen.getByText('getProps'));
const virtualizedProps = VirtualizedList.getProps.mock.calls[0][0];
virtualizedProps.sort({ sortBy: 'name', sortDirection: VirtualizedList.SORT_BY.DESC });
@@ -247,13 +255,15 @@ describe('ListToVirtualizedList', () => {
expect(onChange).toHaveBeenCalledWith(null, { field: 'name', isDescending: true });
});
- it('should adapt selection isSelected', () => {
+ it('should adapt selection isSelected', async () => {
+ const user = userEvent.setup();
+
// given
const isSelected = jest.fn();
render();
// when
- userEvent.click(screen.getByText('getProps'));
+ await user.click(screen.getByText('getProps'));
const virtualizedProps = VirtualizedList.getProps.mock.calls[0][0];
virtualizedProps.isSelected(props.items[0]);
@@ -261,14 +271,16 @@ describe('ListToVirtualizedList', () => {
expect(isSelected).toHaveBeenCalledWith(props.items[0]);
});
- it('should adapt selection onToggle', () => {
+ it('should adapt selection onToggle', async () => {
+ const user = userEvent.setup();
+
// given
const onToggle = jest.fn();
const event = { target: {} };
render();
// when
- userEvent.click(screen.getByText('getProps'));
+ await user.click(screen.getByText('getProps'));
const virtualizedProps = VirtualizedList.getProps.mock.calls[0][0];
virtualizedProps.selectionToggle(event, props.items[0]);
@@ -276,14 +288,16 @@ describe('ListToVirtualizedList', () => {
expect(onToggle).toHaveBeenCalledWith(event, props.items[0]);
});
- it('should adapt click onRowClick', () => {
+ it('should adapt click onRowClick', async () => {
+ const user = userEvent.setup();
+
// given
const onRowClick = jest.fn();
const event = { target: {} };
render();
// when
- userEvent.click(screen.getByText('getProps'));
+ await user.click(screen.getByText('getProps'));
const virtualizedProps = VirtualizedList.getProps.mock.calls[0][0];
virtualizedProps.onRowClick(event, props.items[0]);
@@ -291,14 +305,16 @@ describe('ListToVirtualizedList', () => {
expect(onRowClick).toHaveBeenCalledWith(event, props.items[0]);
});
- it('should adapt click onRowDoubleClick', () => {
+ it('should adapt click onRowDoubleClick', async () => {
+ const user = userEvent.setup();
+
// given
props.titleProps.onClick = jest.fn();
const event = { target: {} };
render();
// when
- userEvent.click(screen.getByText('getProps'));
+ await user.click(screen.getByText('getProps'));
const virtualizedProps = VirtualizedList.getProps.mock.calls[0][0];
virtualizedProps.onRowDoubleClick(event, props.items[0]);
@@ -306,13 +322,15 @@ describe('ListToVirtualizedList', () => {
expect(props.titleProps.onClick).toHaveBeenCalledWith(event, props.items[0]);
});
- it('should adapt selection isActive', () => {
+ it('should adapt selection isActive', async () => {
+ const user = userEvent.setup();
+
// given
const isActive = jest.fn();
render();
// when
- userEvent.click(screen.getByText('getProps'));
+ await user.click(screen.getByText('getProps'));
const virtualizedProps = VirtualizedList.getProps.mock.calls[0][0];
virtualizedProps.isActive(props.items[0]);
diff --git a/packages/components/src/ObjectViewer/JSONLike/JSONLike.test.js b/packages/components/src/ObjectViewer/JSONLike/JSONLike.test.js
index 7009114f4d5..aec3f7e8b12 100644
--- a/packages/components/src/ObjectViewer/JSONLike/JSONLike.test.js
+++ b/packages/components/src/ObjectViewer/JSONLike/JSONLike.test.js
@@ -291,7 +291,9 @@ describe('JSONLike', () => {
expect(screen.getByTestId('injected')).toHaveTextContent('hello world');
});
- it("should toggle item but don't trigger form submit", () => {
+ it("should toggle item but don't trigger form submit", async () => {
+ const user = userEvent.setup();
+
// GIVEN
const mockOnToggle = jest.fn();
const mockOnSubmitClick = jest.fn();
@@ -315,7 +317,7 @@ describe('JSONLike', () => {
expect(mockOnToggle).not.toHaveBeenCalled();
expect(mockOnSubmitClick).not.toHaveBeenCalled();
// WHEN
- userEvent.click(
+ await user.click(
screen.getByRole('link', {
hidden: true,
}),
@@ -325,7 +327,9 @@ describe('JSONLike', () => {
expect(mockOnSubmitClick).not.toHaveBeenCalled();
});
- it('should select item', () => {
+ it('should select item', async () => {
+ const user = userEvent.setup();
+
// GIVEN
const mockOnSelect = jest.fn();
// WHEN
@@ -343,7 +347,7 @@ describe('JSONLike', () => {
expect(mockOnSelect).not.toHaveBeenCalled();
// WHEN
- userEvent.click(screen.getByRole('treeitem'));
+ await user.click(screen.getByRole('treeitem'));
// THEN
expect(mockOnSelect).toHaveBeenCalled();
});
diff --git a/packages/components/src/Typeahead/Typeahead.test.js b/packages/components/src/Typeahead/Typeahead.test.js
index db4cb4a61cb..d793b9cbb34 100644
--- a/packages/components/src/Typeahead/Typeahead.test.js
+++ b/packages/components/src/Typeahead/Typeahead.test.js
@@ -145,7 +145,9 @@ describe('Typeahead', () => {
expect(screen.getByRole('button')).toBeVisible();
});
- it('should call onToggle', () => {
+ it('should call onToggle', async () => {
+ const user = userEvent.setup();
+
// given
const props = {
...initialProps,
@@ -155,7 +157,7 @@ describe('Typeahead', () => {
// when
render();
- userEvent.click(screen.getByRole('button'));
+ await user.click(screen.getByRole('button'));
// then
expect(props.onToggle).toHaveBeenCalled();
@@ -163,7 +165,9 @@ describe('Typeahead', () => {
});
describe('input', () => {
- it('should call onChange', () => {
+ it('should call onChange', async () => {
+ const user = userEvent.setup();
+
// given
const onChange = jest.fn();
const props = {
@@ -173,13 +177,15 @@ describe('Typeahead', () => {
// when
render();
- userEvent.type(screen.getByRole('textbox'), 'toto');
+ await user.type(screen.getByRole('textbox'), 'toto');
// then
expect(onChange).toHaveBeenCalled();
});
- it('should call onBlur', () => {
+ it('should call onBlur', async () => {
+ const user = userEvent.setup();
+
// given
const onBlur = jest.fn();
const props = {
@@ -189,8 +195,8 @@ describe('Typeahead', () => {
// when
render();
- userEvent.click(screen.getByRole('textbox'));
- userEvent.tab();
+ await user.click(screen.getByRole('textbox'));
+ await user.tab();
// then
expect(onBlur).toHaveBeenCalled();
@@ -198,7 +204,9 @@ describe('Typeahead', () => {
});
describe('item', () => {
- it('should call onSelect', () => {
+ it('should call onSelect', async () => {
+ const user = userEvent.setup();
+
// given
const onSelect = jest.fn();
const props = {
@@ -209,7 +217,7 @@ describe('Typeahead', () => {
// when
render();
- userEvent.click(screen.getAllByRole('option')[0]);
+ await user.click(screen.getAllByRole('option')[0]);
// then
expect(onSelect).toHaveBeenCalled();