mirror of
https://github.com/grafana/grafana.git
synced 2024-11-28 03:34:15 -06:00
actually convert Cloudwatch ConfigEditor test to RTL (#56461)
This commit is contained in:
parent
a8b883b1fa
commit
c5171b84a0
@ -46,9 +46,6 @@ exports[`no enzyme tests`] = {
|
||||
],
|
||||
"public/app/features/dimensions/editors/ThresholdsEditor/ThresholdsEditor.test.tsx:145048794": [
|
||||
[0, 17, 13, "RegExp match", "2409514259"]
|
||||
],
|
||||
"public/app/plugins/datasource/cloudwatch/components/ConfigEditor.test.tsx:2983010995": [
|
||||
[1, 19, 13, "RegExp match", "2409514259"]
|
||||
]
|
||||
}`
|
||||
};
|
||||
|
@ -1,10 +1,11 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { shallow } from 'enzyme';
|
||||
import React from 'react';
|
||||
import { Provider } from 'react-redux';
|
||||
import selectEvent from 'react-select-event';
|
||||
|
||||
import { AwsAuthType } from '@grafana/aws-sdk';
|
||||
import { toOption } from '@grafana/data';
|
||||
import { configureStore } from 'app/store/configureStore';
|
||||
|
||||
import { setupMockedDataSource } from '../__mocks__/CloudWatchDataSource';
|
||||
|
||||
@ -79,65 +80,75 @@ const props: Props = {
|
||||
onOptionsChange: jest.fn(),
|
||||
};
|
||||
|
||||
const setup = (propOverrides?: object) => {
|
||||
const newProps = { ...props, ...propOverrides };
|
||||
const setup = (optionOverrides?: Partial<Props['options']>) => {
|
||||
const store = configureStore();
|
||||
const newProps = {
|
||||
...props,
|
||||
options: {
|
||||
...props.options,
|
||||
...optionOverrides,
|
||||
},
|
||||
};
|
||||
|
||||
return shallow(<ConfigEditor {...newProps} />);
|
||||
render(
|
||||
<Provider store={store}>
|
||||
<ConfigEditor {...newProps} />
|
||||
</Provider>
|
||||
);
|
||||
};
|
||||
|
||||
describe('Render', () => {
|
||||
beforeEach(() => {
|
||||
(window as any).grafanaBootData = {
|
||||
settings: {},
|
||||
};
|
||||
jest.resetAllMocks();
|
||||
putMock.mockImplementation(async () => ({ datasource: setupMockedDataSource().datasource }));
|
||||
});
|
||||
it('should render component', () => {
|
||||
const wrapper = setup();
|
||||
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
it('should render component without blowing up', () => {
|
||||
expect(() => setup()).not.toThrow();
|
||||
});
|
||||
|
||||
it('should disable access key id field', () => {
|
||||
const wrapper = setup({
|
||||
setup({
|
||||
secureJsonFields: {
|
||||
secretKey: true,
|
||||
},
|
||||
});
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
expect(screen.getByPlaceholderText('Configured')).toBeDisabled();
|
||||
});
|
||||
|
||||
it('should show credentials profile name field', () => {
|
||||
const wrapper = setup({
|
||||
setup({
|
||||
jsonData: {
|
||||
authType: 'credentials',
|
||||
authType: AwsAuthType.Credentials,
|
||||
},
|
||||
});
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
expect(screen.getByLabelText('Credentials Profile Name')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should show access key and secret access key fields', () => {
|
||||
const wrapper = setup({
|
||||
setup({
|
||||
jsonData: {
|
||||
authType: 'keys',
|
||||
authType: AwsAuthType.Keys,
|
||||
},
|
||||
});
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
expect(screen.getByLabelText('Access Key ID')).toBeInTheDocument();
|
||||
expect(screen.getByLabelText('Secret Access Key')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should show arn role field', () => {
|
||||
const wrapper = setup({
|
||||
setup({
|
||||
jsonData: {
|
||||
authType: 'arn',
|
||||
authType: AwsAuthType.ARN,
|
||||
},
|
||||
});
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
expect(screen.getByLabelText('Assume Role ARN')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should load log groups when multiselect is opened', async () => {
|
||||
(window as any).grafanaBootData = {
|
||||
settings: {},
|
||||
};
|
||||
|
||||
render(<ConfigEditor {...props} />);
|
||||
setup();
|
||||
const multiselect = await screen.findByLabelText('Log Groups');
|
||||
selectEvent.openMenu(multiselect);
|
||||
expect(await screen.findByText('logGroup-foo')).toBeInTheDocument();
|
||||
|
@ -1,511 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Render should disable access key id field 1`] = `
|
||||
<Fragment>
|
||||
<ConnectionConfig
|
||||
onOptionsChange={[MockFunction]}
|
||||
options={
|
||||
Object {
|
||||
"access": "proxy",
|
||||
"basicAuth": false,
|
||||
"basicAuthUser": "",
|
||||
"database": "",
|
||||
"id": 1,
|
||||
"isDefault": true,
|
||||
"jsonData": Object {
|
||||
"assumeRoleArn": "",
|
||||
"authType": "keys",
|
||||
"customMetricsNamespaces": "",
|
||||
"database": "",
|
||||
"defaultRegion": "us-east-2",
|
||||
"externalId": "",
|
||||
"timeField": "@timestamp",
|
||||
},
|
||||
"name": "CloudWatch",
|
||||
"orgId": 1,
|
||||
"readOnly": false,
|
||||
"secureJsonData": Object {
|
||||
"accessKey": "",
|
||||
"secretKey": "",
|
||||
},
|
||||
"secureJsonFields": Object {
|
||||
"accessKey": false,
|
||||
"secretKey": false,
|
||||
},
|
||||
"type": "cloudwatch",
|
||||
"typeLogoUrl": "",
|
||||
"typeName": "Cloudwatch",
|
||||
"uid": "z",
|
||||
"url": "",
|
||||
"user": "",
|
||||
"withCredentials": false,
|
||||
}
|
||||
}
|
||||
secureJsonFields={
|
||||
Object {
|
||||
"secretKey": true,
|
||||
}
|
||||
}
|
||||
>
|
||||
<InlineField
|
||||
label="Namespaces of Custom Metrics"
|
||||
labelWidth={28}
|
||||
tooltip="Namespaces of Custom Metrics."
|
||||
>
|
||||
<Input
|
||||
onChange={[Function]}
|
||||
placeholder="Namespace1,Namespace2"
|
||||
value=""
|
||||
width={60}
|
||||
/>
|
||||
</InlineField>
|
||||
</ConnectionConfig>
|
||||
<h3
|
||||
className="page-heading"
|
||||
>
|
||||
CloudWatch Logs
|
||||
</h3>
|
||||
<div
|
||||
className="gf-form-group"
|
||||
>
|
||||
<InlineField
|
||||
invalid={false}
|
||||
label="Timeout"
|
||||
labelWidth={28}
|
||||
tooltip="Custom timeout for CloudWatch Logs insights queries which have max concurrency limits. Default is 15 minutes. Must be a valid duration string, such as \\"15m\\" \\"30s\\" \\"2000ms\\" etc."
|
||||
>
|
||||
<Input
|
||||
onChange={[Function]}
|
||||
placeholder="15m"
|
||||
title="The timeout must be a valid duration string, such as \\"15m\\" \\"30s\\" \\"2000ms\\" etc."
|
||||
value=""
|
||||
width={60}
|
||||
/>
|
||||
</InlineField>
|
||||
<InlineField
|
||||
label="Default Log Groups"
|
||||
labelWidth={28}
|
||||
tooltip="Optionally, specify default log groups for CloudWatch Logs queries."
|
||||
>
|
||||
<LogGroupSelector
|
||||
onChange={[Function]}
|
||||
onOpenMenu={[Function]}
|
||||
region="us-east-2"
|
||||
saved={false}
|
||||
selectedLogGroups={Array []}
|
||||
width={60}
|
||||
/>
|
||||
</InlineField>
|
||||
</div>
|
||||
<XrayLinkConfig
|
||||
onChange={[Function]}
|
||||
/>
|
||||
</Fragment>
|
||||
`;
|
||||
|
||||
exports[`Render should render component 1`] = `
|
||||
<Fragment>
|
||||
<ConnectionConfig
|
||||
onOptionsChange={[MockFunction]}
|
||||
options={
|
||||
Object {
|
||||
"access": "proxy",
|
||||
"basicAuth": false,
|
||||
"basicAuthUser": "",
|
||||
"database": "",
|
||||
"id": 1,
|
||||
"isDefault": true,
|
||||
"jsonData": Object {
|
||||
"assumeRoleArn": "",
|
||||
"authType": "keys",
|
||||
"customMetricsNamespaces": "",
|
||||
"database": "",
|
||||
"defaultRegion": "us-east-2",
|
||||
"externalId": "",
|
||||
"timeField": "@timestamp",
|
||||
},
|
||||
"name": "CloudWatch",
|
||||
"orgId": 1,
|
||||
"readOnly": false,
|
||||
"secureJsonData": Object {
|
||||
"accessKey": "",
|
||||
"secretKey": "",
|
||||
},
|
||||
"secureJsonFields": Object {
|
||||
"accessKey": false,
|
||||
"secretKey": false,
|
||||
},
|
||||
"type": "cloudwatch",
|
||||
"typeLogoUrl": "",
|
||||
"typeName": "Cloudwatch",
|
||||
"uid": "z",
|
||||
"url": "",
|
||||
"user": "",
|
||||
"withCredentials": false,
|
||||
}
|
||||
}
|
||||
>
|
||||
<InlineField
|
||||
label="Namespaces of Custom Metrics"
|
||||
labelWidth={28}
|
||||
tooltip="Namespaces of Custom Metrics."
|
||||
>
|
||||
<Input
|
||||
onChange={[Function]}
|
||||
placeholder="Namespace1,Namespace2"
|
||||
value=""
|
||||
width={60}
|
||||
/>
|
||||
</InlineField>
|
||||
</ConnectionConfig>
|
||||
<h3
|
||||
className="page-heading"
|
||||
>
|
||||
CloudWatch Logs
|
||||
</h3>
|
||||
<div
|
||||
className="gf-form-group"
|
||||
>
|
||||
<InlineField
|
||||
invalid={false}
|
||||
label="Timeout"
|
||||
labelWidth={28}
|
||||
tooltip="Custom timeout for CloudWatch Logs insights queries which have max concurrency limits. Default is 15 minutes. Must be a valid duration string, such as \\"15m\\" \\"30s\\" \\"2000ms\\" etc."
|
||||
>
|
||||
<Input
|
||||
onChange={[Function]}
|
||||
placeholder="15m"
|
||||
title="The timeout must be a valid duration string, such as \\"15m\\" \\"30s\\" \\"2000ms\\" etc."
|
||||
value=""
|
||||
width={60}
|
||||
/>
|
||||
</InlineField>
|
||||
<InlineField
|
||||
label="Default Log Groups"
|
||||
labelWidth={28}
|
||||
tooltip="Optionally, specify default log groups for CloudWatch Logs queries."
|
||||
>
|
||||
<LogGroupSelector
|
||||
onChange={[Function]}
|
||||
onOpenMenu={[Function]}
|
||||
region="us-east-2"
|
||||
saved={false}
|
||||
selectedLogGroups={Array []}
|
||||
width={60}
|
||||
/>
|
||||
</InlineField>
|
||||
</div>
|
||||
<XrayLinkConfig
|
||||
onChange={[Function]}
|
||||
/>
|
||||
</Fragment>
|
||||
`;
|
||||
|
||||
exports[`Render should show access key and secret access key fields 1`] = `
|
||||
<Fragment>
|
||||
<ConnectionConfig
|
||||
jsonData={
|
||||
Object {
|
||||
"authType": "keys",
|
||||
}
|
||||
}
|
||||
onOptionsChange={[MockFunction]}
|
||||
options={
|
||||
Object {
|
||||
"access": "proxy",
|
||||
"basicAuth": false,
|
||||
"basicAuthUser": "",
|
||||
"database": "",
|
||||
"id": 1,
|
||||
"isDefault": true,
|
||||
"jsonData": Object {
|
||||
"assumeRoleArn": "",
|
||||
"authType": "keys",
|
||||
"customMetricsNamespaces": "",
|
||||
"database": "",
|
||||
"defaultRegion": "us-east-2",
|
||||
"externalId": "",
|
||||
"timeField": "@timestamp",
|
||||
},
|
||||
"name": "CloudWatch",
|
||||
"orgId": 1,
|
||||
"readOnly": false,
|
||||
"secureJsonData": Object {
|
||||
"accessKey": "",
|
||||
"secretKey": "",
|
||||
},
|
||||
"secureJsonFields": Object {
|
||||
"accessKey": false,
|
||||
"secretKey": false,
|
||||
},
|
||||
"type": "cloudwatch",
|
||||
"typeLogoUrl": "",
|
||||
"typeName": "Cloudwatch",
|
||||
"uid": "z",
|
||||
"url": "",
|
||||
"user": "",
|
||||
"withCredentials": false,
|
||||
}
|
||||
}
|
||||
>
|
||||
<InlineField
|
||||
label="Namespaces of Custom Metrics"
|
||||
labelWidth={28}
|
||||
tooltip="Namespaces of Custom Metrics."
|
||||
>
|
||||
<Input
|
||||
onChange={[Function]}
|
||||
placeholder="Namespace1,Namespace2"
|
||||
value=""
|
||||
width={60}
|
||||
/>
|
||||
</InlineField>
|
||||
</ConnectionConfig>
|
||||
<h3
|
||||
className="page-heading"
|
||||
>
|
||||
CloudWatch Logs
|
||||
</h3>
|
||||
<div
|
||||
className="gf-form-group"
|
||||
>
|
||||
<InlineField
|
||||
invalid={false}
|
||||
label="Timeout"
|
||||
labelWidth={28}
|
||||
tooltip="Custom timeout for CloudWatch Logs insights queries which have max concurrency limits. Default is 15 minutes. Must be a valid duration string, such as \\"15m\\" \\"30s\\" \\"2000ms\\" etc."
|
||||
>
|
||||
<Input
|
||||
onChange={[Function]}
|
||||
placeholder="15m"
|
||||
title="The timeout must be a valid duration string, such as \\"15m\\" \\"30s\\" \\"2000ms\\" etc."
|
||||
value=""
|
||||
width={60}
|
||||
/>
|
||||
</InlineField>
|
||||
<InlineField
|
||||
label="Default Log Groups"
|
||||
labelWidth={28}
|
||||
tooltip="Optionally, specify default log groups for CloudWatch Logs queries."
|
||||
>
|
||||
<LogGroupSelector
|
||||
onChange={[Function]}
|
||||
onOpenMenu={[Function]}
|
||||
region="us-east-2"
|
||||
saved={false}
|
||||
selectedLogGroups={Array []}
|
||||
width={60}
|
||||
/>
|
||||
</InlineField>
|
||||
</div>
|
||||
<XrayLinkConfig
|
||||
onChange={[Function]}
|
||||
/>
|
||||
</Fragment>
|
||||
`;
|
||||
|
||||
exports[`Render should show arn role field 1`] = `
|
||||
<Fragment>
|
||||
<ConnectionConfig
|
||||
jsonData={
|
||||
Object {
|
||||
"authType": "arn",
|
||||
}
|
||||
}
|
||||
onOptionsChange={[MockFunction]}
|
||||
options={
|
||||
Object {
|
||||
"access": "proxy",
|
||||
"basicAuth": false,
|
||||
"basicAuthUser": "",
|
||||
"database": "",
|
||||
"id": 1,
|
||||
"isDefault": true,
|
||||
"jsonData": Object {
|
||||
"assumeRoleArn": "",
|
||||
"authType": "keys",
|
||||
"customMetricsNamespaces": "",
|
||||
"database": "",
|
||||
"defaultRegion": "us-east-2",
|
||||
"externalId": "",
|
||||
"timeField": "@timestamp",
|
||||
},
|
||||
"name": "CloudWatch",
|
||||
"orgId": 1,
|
||||
"readOnly": false,
|
||||
"secureJsonData": Object {
|
||||
"accessKey": "",
|
||||
"secretKey": "",
|
||||
},
|
||||
"secureJsonFields": Object {
|
||||
"accessKey": false,
|
||||
"secretKey": false,
|
||||
},
|
||||
"type": "cloudwatch",
|
||||
"typeLogoUrl": "",
|
||||
"typeName": "Cloudwatch",
|
||||
"uid": "z",
|
||||
"url": "",
|
||||
"user": "",
|
||||
"withCredentials": false,
|
||||
}
|
||||
}
|
||||
>
|
||||
<InlineField
|
||||
label="Namespaces of Custom Metrics"
|
||||
labelWidth={28}
|
||||
tooltip="Namespaces of Custom Metrics."
|
||||
>
|
||||
<Input
|
||||
onChange={[Function]}
|
||||
placeholder="Namespace1,Namespace2"
|
||||
value=""
|
||||
width={60}
|
||||
/>
|
||||
</InlineField>
|
||||
</ConnectionConfig>
|
||||
<h3
|
||||
className="page-heading"
|
||||
>
|
||||
CloudWatch Logs
|
||||
</h3>
|
||||
<div
|
||||
className="gf-form-group"
|
||||
>
|
||||
<InlineField
|
||||
invalid={false}
|
||||
label="Timeout"
|
||||
labelWidth={28}
|
||||
tooltip="Custom timeout for CloudWatch Logs insights queries which have max concurrency limits. Default is 15 minutes. Must be a valid duration string, such as \\"15m\\" \\"30s\\" \\"2000ms\\" etc."
|
||||
>
|
||||
<Input
|
||||
onChange={[Function]}
|
||||
placeholder="15m"
|
||||
title="The timeout must be a valid duration string, such as \\"15m\\" \\"30s\\" \\"2000ms\\" etc."
|
||||
value=""
|
||||
width={60}
|
||||
/>
|
||||
</InlineField>
|
||||
<InlineField
|
||||
label="Default Log Groups"
|
||||
labelWidth={28}
|
||||
tooltip="Optionally, specify default log groups for CloudWatch Logs queries."
|
||||
>
|
||||
<LogGroupSelector
|
||||
onChange={[Function]}
|
||||
onOpenMenu={[Function]}
|
||||
region="us-east-2"
|
||||
saved={false}
|
||||
selectedLogGroups={Array []}
|
||||
width={60}
|
||||
/>
|
||||
</InlineField>
|
||||
</div>
|
||||
<XrayLinkConfig
|
||||
onChange={[Function]}
|
||||
/>
|
||||
</Fragment>
|
||||
`;
|
||||
|
||||
exports[`Render should show credentials profile name field 1`] = `
|
||||
<Fragment>
|
||||
<ConnectionConfig
|
||||
jsonData={
|
||||
Object {
|
||||
"authType": "credentials",
|
||||
}
|
||||
}
|
||||
onOptionsChange={[MockFunction]}
|
||||
options={
|
||||
Object {
|
||||
"access": "proxy",
|
||||
"basicAuth": false,
|
||||
"basicAuthUser": "",
|
||||
"database": "",
|
||||
"id": 1,
|
||||
"isDefault": true,
|
||||
"jsonData": Object {
|
||||
"assumeRoleArn": "",
|
||||
"authType": "keys",
|
||||
"customMetricsNamespaces": "",
|
||||
"database": "",
|
||||
"defaultRegion": "us-east-2",
|
||||
"externalId": "",
|
||||
"timeField": "@timestamp",
|
||||
},
|
||||
"name": "CloudWatch",
|
||||
"orgId": 1,
|
||||
"readOnly": false,
|
||||
"secureJsonData": Object {
|
||||
"accessKey": "",
|
||||
"secretKey": "",
|
||||
},
|
||||
"secureJsonFields": Object {
|
||||
"accessKey": false,
|
||||
"secretKey": false,
|
||||
},
|
||||
"type": "cloudwatch",
|
||||
"typeLogoUrl": "",
|
||||
"typeName": "Cloudwatch",
|
||||
"uid": "z",
|
||||
"url": "",
|
||||
"user": "",
|
||||
"withCredentials": false,
|
||||
}
|
||||
}
|
||||
>
|
||||
<InlineField
|
||||
label="Namespaces of Custom Metrics"
|
||||
labelWidth={28}
|
||||
tooltip="Namespaces of Custom Metrics."
|
||||
>
|
||||
<Input
|
||||
onChange={[Function]}
|
||||
placeholder="Namespace1,Namespace2"
|
||||
value=""
|
||||
width={60}
|
||||
/>
|
||||
</InlineField>
|
||||
</ConnectionConfig>
|
||||
<h3
|
||||
className="page-heading"
|
||||
>
|
||||
CloudWatch Logs
|
||||
</h3>
|
||||
<div
|
||||
className="gf-form-group"
|
||||
>
|
||||
<InlineField
|
||||
invalid={false}
|
||||
label="Timeout"
|
||||
labelWidth={28}
|
||||
tooltip="Custom timeout for CloudWatch Logs insights queries which have max concurrency limits. Default is 15 minutes. Must be a valid duration string, such as \\"15m\\" \\"30s\\" \\"2000ms\\" etc."
|
||||
>
|
||||
<Input
|
||||
onChange={[Function]}
|
||||
placeholder="15m"
|
||||
title="The timeout must be a valid duration string, such as \\"15m\\" \\"30s\\" \\"2000ms\\" etc."
|
||||
value=""
|
||||
width={60}
|
||||
/>
|
||||
</InlineField>
|
||||
<InlineField
|
||||
label="Default Log Groups"
|
||||
labelWidth={28}
|
||||
tooltip="Optionally, specify default log groups for CloudWatch Logs queries."
|
||||
>
|
||||
<LogGroupSelector
|
||||
onChange={[Function]}
|
||||
onOpenMenu={[Function]}
|
||||
region="us-east-2"
|
||||
saved={false}
|
||||
selectedLogGroups={Array []}
|
||||
width={60}
|
||||
/>
|
||||
</InlineField>
|
||||
</div>
|
||||
<XrayLinkConfig
|
||||
onChange={[Function]}
|
||||
/>
|
||||
</Fragment>
|
||||
`;
|
Loading…
Reference in New Issue
Block a user