diff --git a/.betterer.results b/.betterer.results index d46bf998089..aab4e04aaa4 100644 --- a/.betterer.results +++ b/.betterer.results @@ -77,9 +77,6 @@ exports[`no enzyme tests`] = { "public/app/plugins/datasource/cloudwatch/components/ConfigEditor.test.tsx:4057721851": [ [1, 19, 13, "RegExp match", "2409514259"] ], - "public/app/plugins/datasource/elasticsearch/configuration/ConfigEditor.test.tsx:4128034878": [ - [0, 26, 13, "RegExp match", "2409514259"] - ], "public/app/plugins/datasource/influxdb/components/ConfigEditor.test.tsx:57753101": [ [0, 19, 13, "RegExp match", "2409514259"] ], diff --git a/public/app/plugins/datasource/elasticsearch/configuration/ConfigEditor.test.tsx b/public/app/plugins/datasource/elasticsearch/configuration/ConfigEditor.test.tsx index 10b4ad53b00..49eb91a8d5e 100644 --- a/public/app/plugins/datasource/elasticsearch/configuration/ConfigEditor.test.tsx +++ b/public/app/plugins/datasource/elasticsearch/configuration/ConfigEditor.test.tsx @@ -1,26 +1,31 @@ -import { mount, shallow } from 'enzyme'; +import { render, screen } from '@testing-library/react'; import React from 'react'; -import { DataSourceHttpSettings } from '@grafana/ui'; - import { ConfigEditor } from './ConfigEditor'; -import { ElasticDetails } from './ElasticDetails'; -import { LogsConfig } from './LogsConfig'; import { createDefaultConfigOptions } from './mocks'; describe('ConfigEditor', () => { it('should render without error', () => { - mount( {}} options={createDefaultConfigOptions()} />); + expect(() => + render( {}} options={createDefaultConfigOptions()} />) + ).not.toThrow(); }); it('should render all parts of the config', () => { - const wrapper = shallow( {}} options={createDefaultConfigOptions()} />); - expect(wrapper.find(DataSourceHttpSettings).length).toBe(1); - expect(wrapper.find(ElasticDetails).length).toBe(1); - expect(wrapper.find(LogsConfig).length).toBe(1); + render( {}} options={createDefaultConfigOptions()} />); + + // Check DataSourceHttpSettings are rendered + expect(screen.getByRole('heading', { name: 'HTTP' })).toBeInTheDocument(); + + // Check ElasticDetails are rendered + expect(screen.getByText('Elasticsearch details')).toBeInTheDocument(); + + // Check LogsConfig are rendered + expect(screen.getByText('Logs')).toBeInTheDocument(); }); it('should set defaults', () => { + const mockOnOptionsChange = jest.fn(); const options = createDefaultConfigOptions(); // @ts-ignore delete options.jsonData.esVersion; @@ -28,25 +33,24 @@ describe('ConfigEditor', () => { delete options.jsonData.timeField; delete options.jsonData.maxConcurrentShardRequests; - expect.assertions(3); + render(); - mount( - { - expect(options.jsonData.esVersion).toBe('5.0.0'); - expect(options.jsonData.timeField).toBe('@timestamp'); - expect(options.jsonData.maxConcurrentShardRequests).toBe(5); - }} - options={options} - /> + expect(mockOnOptionsChange).toHaveBeenCalledWith( + expect.objectContaining({ + jsonData: expect.objectContaining({ + esVersion: '5.0.0', + timeField: '@timestamp', + maxConcurrentShardRequests: 5, + }), + }) ); }); it('should not apply default if values are set', () => { - const onChange = jest.fn(); + const mockOnOptionsChange = jest.fn(); - mount(); + render(); - expect(onChange).toHaveBeenCalledTimes(0); + expect(mockOnOptionsChange).toHaveBeenCalledTimes(0); }); });