Skip to content

Commit c6ca6a1

Browse files
committed
handle clicks with userEvent
1 parent afe7383 commit c6ca6a1

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/platform/packages/private/kbn-esql-editor/src/esql_editor.test.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { dataPluginMock } from '@kbn/data-plugin/public/mocks';
1414
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
1515
import { renderWithI18n } from '@kbn/test-jest-helpers';
1616
import { waitFor } from '@testing-library/dom';
17-
import { act } from '@testing-library/react';
1817
import userEvent from '@testing-library/user-event';
1918
import React from 'react';
2019
import { BehaviorSubject } from 'rxjs';
@@ -184,6 +183,7 @@ describe('ESQLEditor', () => {
184183
});
185184

186185
it('should render correctly if editorIsInline prop is set to true', async () => {
186+
const user = userEvent.setup();
187187
const onTextLangQuerySubmit = jest.fn();
188188
const newProps = {
189189
...props,
@@ -198,7 +198,7 @@ describe('ESQLEditor', () => {
198198
expect(runQueryButton).toBeInTheDocument(); // Assert it exists
199199

200200
if (runQueryButton) {
201-
await userEvent.click(runQueryButton);
201+
await user.click(runQueryButton);
202202
expect(onTextLangQuerySubmit).toHaveBeenCalledTimes(1);
203203
}
204204
});
@@ -215,6 +215,8 @@ describe('ESQLEditor', () => {
215215

216216
describe('data errors switch', () => {
217217
test('shown with errors enabled', async () => {
218+
const user = userEvent.setup();
219+
218220
const newProps = {
219221
...props,
220222
dataErrorsControl: { enabled: true, onChange: jest.fn() },
@@ -230,15 +232,17 @@ describe('ESQLEditor', () => {
230232
await waitFor(() => {
231233
expect(queryByTestId('ESQLEditor-footerPopoverButton-error')).toBeInTheDocument();
232234
});
233-
act(() => {
234-
queryByTestId('ESQLEditor-footerPopoverButton-error')?.click();
235-
});
235+
236+
await user.click(queryByTestId('ESQLEditor-footerPopoverButton-error')!);
237+
236238
expect(queryByTestId('ESQLEditor-footerPopover-dataErrorsSwitch')).toBeInTheDocument();
237239

238240
expect(queryAllByText('Data error example')).toHaveLength(2);
239241
});
240242

241243
test('shown with errors disabled', async () => {
244+
const user = userEvent.setup();
245+
242246
const newProps = {
243247
...props,
244248
dataErrorsControl: { enabled: false, onChange: jest.fn() },
@@ -254,15 +258,17 @@ describe('ESQLEditor', () => {
254258
await waitFor(() => {
255259
expect(queryByTestId('ESQLEditor-footerPopoverButton-error')).toBeInTheDocument();
256260
});
257-
act(() => {
258-
queryByTestId('ESQLEditor-footerPopoverButton-error')?.click();
259-
});
261+
262+
await user.click(queryByTestId('ESQLEditor-footerPopoverButton-error')!);
263+
260264
expect(queryByTestId('ESQLEditor-footerPopover-dataErrorsSwitch')).toBeInTheDocument();
261265

262266
expect(queryAllByText('Data error example')).toHaveLength(0);
263267
});
264268

265269
test('not shown when prop not set', async () => {
270+
const user = userEvent.setup();
271+
266272
mockValidate.mockResolvedValue({
267273
errors: [{ message: 'Data error example', severity: 'error' }],
268274
warnings: [],
@@ -271,9 +277,9 @@ describe('ESQLEditor', () => {
271277
await waitFor(() => {
272278
expect(queryByTestId('ESQLEditor-footerPopoverButton-error')).toBeInTheDocument();
273279
});
274-
act(() => {
275-
queryByTestId('ESQLEditor-footerPopoverButton-error')?.click();
276-
});
280+
281+
await user.click(queryByTestId('ESQLEditor-footerPopoverButton-error')!);
282+
277283
expect(queryByTestId('ESQLEditor-footerPopover-dataErrorsSwitch')).not.toBeInTheDocument();
278284
});
279285
});

0 commit comments

Comments
 (0)