From 5e394c0385f98b9782b0ec9717b2888c6c5c0bff Mon Sep 17 00:00:00 2001 From: Ashley Harrison Date: Tue, 30 Aug 2022 09:30:10 +0100 Subject: [PATCH] Convert influxdb ConfigEditor test to RTL (#54332) --- .betterer.results | 11 +- .../influxdb/components/ConfigEditor.test.tsx | 30 +- .../influxdb/components/ConfigEditor.tsx | 12 +- .../__snapshots__/ConfigEditor.test.tsx.snap | 1053 ----------------- 4 files changed, 22 insertions(+), 1084 deletions(-) delete mode 100644 public/app/plugins/datasource/influxdb/components/__snapshots__/ConfigEditor.test.tsx.snap diff --git a/.betterer.results b/.betterer.results index 4ad4b85002c..4f865a6d105 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/influxdb/components/ConfigEditor.test.tsx:57753101": [ - [0, 19, 13, "RegExp match", "2409514259"] - ], "public/app/plugins/datasource/loki/components/LokiExploreQueryEditor.test.tsx:2984948507": [ [0, 26, 13, "RegExp match", "2409514259"] ], @@ -6906,13 +6903,9 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "1"] ], "public/app/plugins/datasource/influxdb/components/ConfigEditor.tsx:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"], + [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"], - [0, 0, 0, "Unexpected any. Specify a different type.", "2"], - [0, 0, 0, "Do not use any type assertions.", "3"], - [0, 0, 0, "Do not use any type assertions.", "4"], - [0, 0, 0, "Do not use any type assertions.", "5"], - [0, 0, 0, "Do not use any type assertions.", "6"] + [0, 0, 0, "Do not use any type assertions.", "2"] ], "public/app/plugins/datasource/influxdb/components/InfluxCheatSheet.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] diff --git a/public/app/plugins/datasource/influxdb/components/ConfigEditor.test.tsx b/public/app/plugins/datasource/influxdb/components/ConfigEditor.test.tsx index 5962125520c..c3a6179e9a7 100644 --- a/public/app/plugins/datasource/influxdb/components/ConfigEditor.test.tsx +++ b/public/app/plugins/datasource/influxdb/components/ConfigEditor.test.tsx @@ -1,4 +1,4 @@ -import { shallow } from 'enzyme'; +import { render, screen } from '@testing-library/react'; import React from 'react'; import ConfigEditor, { Props } from './ConfigEditor'; @@ -14,7 +14,7 @@ jest.mock('lodash', () => { }; }); -const setup = (propOverrides?: object) => { +const setup = (optionOverrides?: object) => { const props: Props = { options: { id: 21, @@ -39,42 +39,40 @@ const setup = (propOverrides?: object) => { secureJsonFields: {}, version: 1, readOnly: false, + ...optionOverrides, }, onOptionsChange: jest.fn(), }; - Object.assign(props, propOverrides); - - return shallow(); + return render(); }; -describe('Render', () => { - it('should render component', () => { - const wrapper = setup(); - - expect(wrapper).toMatchSnapshot(); +describe('ConfigEditor', () => { + it('should render without throwing an error', () => { + expect(() => setup()).not.toThrow(); }); it('should disable basic auth password input', () => { - const wrapper = setup({ + setup({ + basicAuth: true, secureJsonFields: { basicAuthPassword: true, }, }); - expect(wrapper).toMatchSnapshot(); + expect(screen.getByDisplayValue('configured')).toBeInTheDocument(); }); it('should hide white listed cookies input when browser access chosen', () => { - const wrapper = setup({ + setup({ access: 'direct', }); - expect(wrapper).toMatchSnapshot(); + expect(screen.queryByLabelText('Allowed cookies')).not.toBeInTheDocument(); }); it('should hide basic auth fields when switch off', () => { - const wrapper = setup({ + setup({ basicAuth: false, }); - expect(wrapper).toMatchSnapshot(); + expect(screen.queryByRole('heading', { name: 'Basic Auth Details' })).not.toBeInTheDocument(); }); }); diff --git a/public/app/plugins/datasource/influxdb/components/ConfigEditor.tsx b/public/app/plugins/datasource/influxdb/components/ConfigEditor.tsx index b1b431cd8f4..7918fc0546b 100644 --- a/public/app/plugins/datasource/influxdb/components/ConfigEditor.tsx +++ b/public/app/plugins/datasource/influxdb/components/ConfigEditor.tsx @@ -17,12 +17,12 @@ const { Input, SecretFormField } = LegacyForms; import { BROWSER_MODE_DISABLED_MESSAGE } from '../constants'; import { InfluxOptions, InfluxSecureJsonData, InfluxVersion } from '../types'; -const httpModes = [ +const httpModes: SelectableValue[] = [ { label: 'GET', value: 'GET' }, { label: 'POST', value: 'POST' }, -] as SelectableValue[]; +]; -const versions = [ +const versions: Array> = [ { label: 'InfluxQL', value: InfluxVersion.InfluxQL, @@ -33,7 +33,7 @@ const versions = [ value: InfluxVersion.Flux, description: 'Advanced data scripting and query language. Supported in InfluxDB 2.x and 1.8+', }, -] as Array>; +]; export type Props = DataSourcePluginOptionsEditorProps; type State = { @@ -112,7 +112,7 @@ export class ConfigEditor extends PureComponent {
{
-

- Query Language -

-
-
-
- -
-
-
-
-
- - User - -
- -
-
-
-
-
- -
-
-
-
- - HTTP Method - - -
-
-
-
- - - -
-
- -`; - -exports[`Render should hide basic auth fields when switch off 1`] = ` - -

- Query Language -

-
-
-
- -
-
-
-
-
- - User - -
- -
-
-
-
-
- -
-
-
-
- - HTTP Method - - -
-
-
-
- - - -
-
- -`; - -exports[`Render should hide white listed cookies input when browser access chosen 1`] = ` - -

- Query Language -

-
-
-
- -
-
-
-
-
- - User - -
- -
-
-
-
-
- -
-
-
-
- - HTTP Method - - -
-
- -
- - - -
- -
-`; - -exports[`Render should render component 1`] = ` - -

- Query Language -

-
-
-
- -
-
-
-
-
- - User - -
- -
-
-
-
-
- -
-
-
-
- - HTTP Method - - -
-
- -
- - - -
- -
-`;