diff --git a/.betterer.results b/.betterer.results
index 865f680adee..333c18a6cba 100644
--- a/.betterer.results
+++ b/.betterer.results
@@ -218,9 +218,6 @@ exports[`no enzyme tests`] = {
"public/app/features/explore/RichHistory/RichHistoryStarredTab.test.tsx:3933225580": [
[0, 17, 13, "RegExp match", "2409514259"]
],
- "public/app/features/explore/SecondaryActions.test.tsx:1177396128": [
- [0, 19, 13, "RegExp match", "2409514259"]
- ],
"public/app/features/folders/FolderSettingsPage.test.tsx:1109052730": [
[0, 19, 13, "RegExp match", "2409514259"]
],
diff --git a/public/app/features/explore/SecondaryActions.test.tsx b/public/app/features/explore/SecondaryActions.test.tsx
index fb9c32e34c9..a8dbbd1d9df 100644
--- a/public/app/features/explore/SecondaryActions.test.tsx
+++ b/public/app/features/explore/SecondaryActions.test.tsx
@@ -1,28 +1,27 @@
-import { shallow } from 'enzyme';
+import { render, screen } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
import { noop } from 'lodash';
import React from 'react';
import { SecondaryActions } from './SecondaryActions';
-const addQueryRowButtonSelector = '[aria-label="Add row button"]';
-const richHistoryButtonSelector = '[aria-label="Rich history button"]';
-const queryInspectorButtonSelector = '[aria-label="Query inspector button"]';
-
describe('SecondaryActions', () => {
- it('should render component two buttons', () => {
- const wrapper = shallow(
+ it('should render component with three buttons', () => {
+ render(
);
- expect(wrapper.find(addQueryRowButtonSelector)).toHaveLength(1);
- expect(wrapper.find(richHistoryButtonSelector)).toHaveLength(1);
+
+ expect(screen.getByRole('button', { name: /Add row button/i })).toBeInTheDocument();
+ expect(screen.getByRole('button', { name: /Rich history button/i })).toBeInTheDocument();
+ expect(screen.getByRole('button', { name: /Query inspector button/i })).toBeInTheDocument();
});
it('should not render add row button if addQueryRowButtonHidden=true', () => {
- const wrapper = shallow(
+ render(
{
onClickQueryInspectorButton={noop}
/>
);
- expect(wrapper.find(addQueryRowButtonSelector)).toHaveLength(0);
- expect(wrapper.find(richHistoryButtonSelector)).toHaveLength(1);
+
+ expect(screen.queryByRole('button', { name: /Add row button/i })).not.toBeInTheDocument();
+ expect(screen.getByRole('button', { name: /Rich history button/i })).toBeInTheDocument();
+ expect(screen.getByRole('button', { name: /Query inspector button/i })).toBeInTheDocument();
});
it('should disable add row button if addQueryRowButtonDisabled=true', () => {
- const wrapper = shallow(
+ render(
{
onClickQueryInspectorButton={noop}
/>
);
- expect(wrapper.find(addQueryRowButtonSelector).props().disabled).toBe(true);
+
+ expect(screen.getByRole('button', { name: /Add row button/i })).toBeDisabled();
+ expect(screen.getByRole('button', { name: /Rich history button/i })).toBeInTheDocument();
+ expect(screen.getByRole('button', { name: /Query inspector button/i })).toBeInTheDocument();
});
- it('should map click handlers correctly', () => {
+ it('should map click handlers correctly', async () => {
+ const user = userEvent.setup();
+
const onClickAddRow = jest.fn();
const onClickHistory = jest.fn();
const onClickQueryInspector = jest.fn();
- const wrapper = shallow(
+
+ render(
{
/>
);
- wrapper.find(addQueryRowButtonSelector).simulate('click');
- expect(onClickAddRow).toBeCalled();
+ await user.click(screen.getByRole('button', { name: /Add row button/i }));
+ expect(onClickAddRow).toBeCalledTimes(1);
- wrapper.find(richHistoryButtonSelector).simulate('click');
- expect(onClickHistory).toBeCalled();
+ await user.click(screen.getByRole('button', { name: /Rich history button/i }));
+ expect(onClickHistory).toBeCalledTimes(1);
- wrapper.find(queryInspectorButtonSelector).simulate('click');
- expect(onClickQueryInspector).toBeCalled();
+ await user.click(screen.getByRole('button', { name: /Query inspector button/i }));
+ expect(onClickQueryInspector).toBeCalledTimes(1);
});
});