diff --git a/.betterer.results b/.betterer.results index f72393aa21f..3fff26564be 100644 --- a/.betterer.results +++ b/.betterer.results @@ -97,9 +97,6 @@ exports[`no enzyme tests`] = { ], "public/app/plugins/datasource/loki/configuration/DerivedFields.test.tsx:2402631398": [ [0, 17, 13, "RegExp match", "2409514259"] - ], - "public/app/plugins/datasource/prometheus/configuration/AzureCredentialsForm.test.tsx:3424320489": [ - [0, 19, 13, "RegExp match", "2409514259"] ] }` }; diff --git a/public/app/plugins/datasource/prometheus/configuration/AzureCredentialsForm.test.tsx b/public/app/plugins/datasource/prometheus/configuration/AzureCredentialsForm.test.tsx index 4e4a38f4024..70d3e0ac3ca 100644 --- a/public/app/plugins/datasource/prometheus/configuration/AzureCredentialsForm.test.tsx +++ b/public/app/plugins/datasource/prometheus/configuration/AzureCredentialsForm.test.tsx @@ -1,4 +1,4 @@ -import { shallow } from 'enzyme'; +import { render, screen } from '@testing-library/react'; import React from 'react'; import AzureCredentialsForm, { Props } from './AzureCredentialsForm'; @@ -21,47 +21,40 @@ const setup = (propsFunc?: (props: Props) => Props) => { { value: 'chinaazuremonitor', label: 'Azure China' }, ], onCredentialsChange: jest.fn(), - getSubscriptions: jest.fn(), + getSubscriptions: jest.fn().mockResolvedValue([]), }; if (propsFunc) { props = propsFunc(props); } - return shallow(); + render(); }; -describe('Render', () => { - it('should render component', () => { - const wrapper = setup(); - expect(wrapper).toMatchSnapshot(); +describe('AzureCredentialsForm', () => { + it('should render without error', () => { + expect(() => setup()).not.toThrow(); }); - it('should disable azure monitor secret input', () => { - const wrapper = setup((props) => ({ + it('should disable azure monitor secret input when the clientSecret is a symbol', async () => { + setup((props) => ({ ...props, credentials: { - authType: 'clientsecret', - azureCloud: 'azuremonitor', - tenantId: 'e7f3f661-a933-3h3f-0294-31c4f962ec48', - clientId: '34509fad-c0r9-45df-9e25-f1ee34af6900', + ...props.credentials, clientSecret: Symbol(), }, })); - expect(wrapper).toMatchSnapshot(); + expect(await screen.findByLabelText('Client Secret')).toBeDisabled(); }); - it('should enable azure monitor load subscriptions button', () => { - const wrapper = setup((props) => ({ + it('should enable azure monitor load subscriptions button when all required fields are defined', async () => { + setup((props) => ({ ...props, credentials: { - authType: 'clientsecret', - azureCloud: 'azuremonitor', - tenantId: 'e7f3f661-a933-3h3f-0294-31c4f962ec48', - clientId: '34509fad-c0r9-45df-9e25-f1ee34af6900', + ...props.credentials, clientSecret: 'e7f3f661-a933-4b3f-8176-51c4f982ec48', }, })); - expect(wrapper).toMatchSnapshot(); + expect(await screen.findByRole('button', { name: 'Load Subscriptions' })).not.toBeDisabled(); }); }); diff --git a/public/app/plugins/datasource/prometheus/configuration/AzureCredentialsForm.tsx b/public/app/plugins/datasource/prometheus/configuration/AzureCredentialsForm.tsx index 23dec0aa749..76fb10fef40 100644 --- a/public/app/plugins/datasource/prometheus/configuration/AzureCredentialsForm.tsx +++ b/public/app/plugins/datasource/prometheus/configuration/AzureCredentialsForm.tsx @@ -211,8 +211,10 @@ export const AzureCredentialsForm: FunctionComponent = (props: Props) => {typeof credentials.clientSecret === 'symbol' ? (
- Client Secret - + + Client Secret + +
diff --git a/public/app/plugins/datasource/prometheus/configuration/__snapshots__/AzureCredentialsForm.test.tsx.snap b/public/app/plugins/datasource/prometheus/configuration/__snapshots__/AzureCredentialsForm.test.tsx.snap deleted file mode 100644 index 12ea8b30e5a..00000000000 --- a/public/app/plugins/datasource/prometheus/configuration/__snapshots__/AzureCredentialsForm.test.tsx.snap +++ /dev/null @@ -1,620 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Render should disable azure monitor secret input 1`] = ` -
-
-
- - Azure Cloud - - -
-
-
-
-
- - Application (client) ID - -
- -
-
-
-
-
- - Client Secret - - -
-
-
- -
-
-
-
-
- - Default Subscription - -
- -
-
-
-
- - Directory (tenant) ID - -
- -
-
-
-
-
- - Application (client) ID - -
- -
-
-
-
-
- - Client Secret - -
- -
-
-
-
-
- - Default Subscription - -
- -
-
-
-
- - Directory (tenant) ID - -
- -
-
-
-
-
- - Application (client) ID - -
- -
-
-
-
-
- - Client Secret - -
- -
-
-
-
-
- - Default Subscription - -
-