diff --git a/.betterer.results b/.betterer.results index 8cdbeb92f5c..53336350c47 100644 --- a/.betterer.results +++ b/.betterer.results @@ -83,9 +83,6 @@ exports[`no enzyme tests`] = { "public/app/plugins/datasource/loki/components/LokiQueryEditor.test.tsx:146069464": [ [0, 19, 13, "RegExp match", "2409514259"] ], - "public/app/plugins/datasource/loki/configuration/ConfigEditor.test.tsx:2659566901": [ - [0, 17, 13, "RegExp match", "2409514259"] - ], "public/app/plugins/datasource/loki/configuration/DerivedFields.test.tsx:2402631398": [ [0, 17, 13, "RegExp match", "2409514259"] ] diff --git a/public/app/plugins/datasource/loki/configuration/ConfigEditor.test.tsx b/public/app/plugins/datasource/loki/configuration/ConfigEditor.test.tsx index f089dec74a1..f447279c1d8 100644 --- a/public/app/plugins/datasource/loki/configuration/ConfigEditor.test.tsx +++ b/public/app/plugins/datasource/loki/configuration/ConfigEditor.test.tsx @@ -1,31 +1,36 @@ -import { mount } from 'enzyme'; +import { render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; import React from 'react'; -import { DataSourceHttpSettings } from '@grafana/ui'; - import { createDefaultConfigOptions } from '../mocks'; import { ConfigEditor } from './ConfigEditor'; -import { DerivedFields } from './DerivedFields'; describe('ConfigEditor', () => { it('should render without error', () => { - mount( {}} options={createDefaultConfigOptions()} />); + expect(() => + render( {}} options={createDefaultConfigOptions()} />) + ).not.toThrow(); }); it('should render the right sections', () => { - const wrapper = mount( {}} options={createDefaultConfigOptions()} />); - expect(wrapper.find(DataSourceHttpSettings).length).toBe(1); - expect(wrapper.find({ label: 'Maximum lines' }).length).toBe(1); - expect(wrapper.find(DerivedFields).length).toBe(1); + render( {}} options={createDefaultConfigOptions()} />); + expect(screen.getByRole('heading', { name: 'HTTP' })).toBeInTheDocument(); + expect(screen.getByText('Maximum lines')).toBeInTheDocument(); + expect(screen.getByRole('heading', { name: 'Derived fields' })).toBeInTheDocument(); }); - it('should pass correct data to onChange', () => { + it('should pass correct data to onChange', async () => { const onChangeMock = jest.fn(); - const wrapper = mount(); - const inputWrapper = wrapper.find({ label: 'Maximum lines' }).find('input'); - inputWrapper.getDOMNode().value = '42'; - inputWrapper.simulate('change'); - expect(onChangeMock.mock.calls[0][0].jsonData.maxLines).toBe('42'); + render(); + const maxLinesInput = await screen.findByDisplayValue('531'); + await userEvent.type(maxLinesInput, '2'); + expect(onChangeMock).toHaveBeenCalledWith( + expect.objectContaining({ + jsonData: expect.objectContaining({ + maxLines: '5312', + }), + }) + ); }); });