Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Actions] Adds a "Test Connector" button on the Connectors List to make discovery of the Test tab easier #78746

Merged
merged 18 commits into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import React from 'react';
import { mountWithIntl } from 'test_utils/enzyme_helpers';
import { DocLinksStart } from 'kibana/public';
import { coreMock } from 'src/core/public/mocks';
import EmailParamsFields from './email_params';

describe('EmailParamsFields renders', () => {
test('all params fields is rendered', () => {
const mocks = coreMock.createSetup();
const actionParams = {
cc: [],
bcc: [],
Expand All @@ -25,6 +27,8 @@ describe('EmailParamsFields renders', () => {
editAction={() => {}}
index={0}
docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart}
toastNotifications={mocks.notifications.toasts}
http={mocks.http}
/>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import React from 'react';
import { mountWithIntl } from 'test_utils/enzyme_helpers';
import ParamsFields from './es_index_params';
import { DocLinksStart } from 'kibana/public';
import { coreMock } from 'src/core/public/mocks';

describe('IndexParamsFields renders', () => {
test('all params fields is rendered', () => {
const mocks = coreMock.createSetup();
const actionParams = {
documents: [{ test: 123 }],
};
Expand All @@ -21,6 +23,8 @@ describe('IndexParamsFields renders', () => {
editAction={() => {}}
index={0}
docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart}
toastNotifications={mocks.notifications.toasts}
http={mocks.http}
/>
);
expect(wrapper.find('[data-test-subj="documentsJsonEditor"]').first().prop('value')).toBe(`{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,16 @@ import React from 'react';
import { mountWithIntl } from 'test_utils/enzyme_helpers';
import JiraParamsFields from './jira_params';
import { DocLinksStart } from 'kibana/public';
import { coreMock } from 'src/core/public/mocks';

import { useGetIssueTypes } from './use_get_issue_types';
import { useGetFieldsByIssueType } from './use_get_fields_by_issue_type';

jest.mock('../../../app_context', () => {
const post = jest.fn();
return {
useAppDependencies: jest.fn(() => ({ http: { post } })),
};
});

jest.mock('./use_get_issue_types');
jest.mock('./use_get_fields_by_issue_type');

const mocks = coreMock.createSetup();

const useGetIssueTypesMock = useGetIssueTypes as jest.Mock;
const useGetFieldsByIssueTypeMock = useGetFieldsByIssueType as jest.Mock;

Expand Down Expand Up @@ -93,6 +89,8 @@ describe('JiraParamsFields renders', () => {
index={0}
messageVariables={[]}
docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart}
toastNotifications={mocks.notifications.toasts}
http={mocks.http}
actionConnector={connector}
/>
);
Expand All @@ -118,6 +116,8 @@ describe('JiraParamsFields renders', () => {
index={0}
messageVariables={[]}
docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart}
toastNotifications={mocks.notifications.toasts}
http={mocks.http}
actionConnector={connector}
/>
);
Expand All @@ -141,6 +141,8 @@ describe('JiraParamsFields renders', () => {
index={0}
messageVariables={[]}
docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart}
toastNotifications={mocks.notifications.toasts}
http={mocks.http}
actionConnector={connector}
/>
);
Expand All @@ -164,6 +166,8 @@ describe('JiraParamsFields renders', () => {
index={0}
messageVariables={[]}
docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart}
toastNotifications={mocks.notifications.toasts}
http={mocks.http}
actionConnector={connector}
/>
);
Expand Down Expand Up @@ -191,6 +195,8 @@ describe('JiraParamsFields renders', () => {
index={0}
messageVariables={[]}
docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart}
toastNotifications={mocks.notifications.toasts}
http={mocks.http}
actionConnector={connector}
/>
);
Expand Down Expand Up @@ -218,6 +224,8 @@ describe('JiraParamsFields renders', () => {
index={0}
messageVariables={[]}
docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart}
toastNotifications={mocks.notifications.toasts}
http={mocks.http}
actionConnector={connector}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { EuiFlexGroup } from '@elastic/eui';
import { EuiFlexItem } from '@elastic/eui';
import { EuiSpacer } from '@elastic/eui';

import { useAppDependencies } from '../../../app_context';
import { ActionParamsProps } from '../../../../types';
import { TextAreaWithMessageVariables } from '../../text_area_with_message_variables';
import { TextFieldWithMessageVariables } from '../../text_field_with_message_variables';
Expand All @@ -28,14 +27,15 @@ const JiraParamsFields: React.FunctionComponent<ActionParamsProps<JiraActionPara
errors,
messageVariables,
actionConnector,
http,
toastNotifications,
}) => {
const { title, description, comments, issueType, priority, labels, savedObjectId } =
actionParams.subActionParams || {};

const [issueTypesSelectOptions, setIssueTypesSelectOptions] = useState<EuiSelectOption[]>([]);
const [firstLoad, setFirstLoad] = useState(false);
const [prioritiesSelectOptions, setPrioritiesSelectOptions] = useState<EuiSelectOption[]>([]);
const { http, toastNotifications } = useAppDependencies();

useEffect(() => {
setFirstLoad(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import { mountWithIntl } from 'test_utils/enzyme_helpers';
import { EventActionOptions, SeverityActionOptions } from '.././types';
import PagerDutyParamsFields from './pagerduty_params';
import { DocLinksStart } from 'kibana/public';
import { coreMock } from 'src/core/public/mocks';

describe('PagerDutyParamsFields renders', () => {
test('all params fields is rendered', () => {
const mocks = coreMock.createSetup();
const actionParams = {
eventAction: EventActionOptions.TRIGGER,
dedupKey: 'test',
Expand All @@ -30,6 +32,8 @@ describe('PagerDutyParamsFields renders', () => {
editAction={() => {}}
index={0}
docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart}
toastNotifications={mocks.notifications.toasts}
http={mocks.http}
/>
);
expect(wrapper.find('[data-test-subj="severitySelect"]').length > 0).toBeTruthy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ import { DocLinksStart } from 'kibana/public';

import { useGetIncidentTypes } from './use_get_incident_types';
import { useGetSeverity } from './use_get_severity';
import { coreMock } from 'src/core/public/mocks';

jest.mock('../../../app_context', () => {
const post = jest.fn();
return {
useAppDependencies: jest.fn(() => ({ http: { post } })),
};
});
const mocks = coreMock.createSetup();

jest.mock('./use_get_incident_types');
jest.mock('./use_get_severity');
Expand Down Expand Up @@ -92,6 +88,8 @@ describe('ResilientParamsFields renders', () => {
index={0}
messageVariables={[]}
docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart}
toastNotifications={mocks.notifications.toasts}
http={mocks.http}
actionConnector={connector}
/>
);
Expand All @@ -114,6 +112,8 @@ describe('ResilientParamsFields renders', () => {
index={0}
messageVariables={[]}
docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart}
toastNotifications={mocks.notifications.toasts}
http={mocks.http}
actionConnector={connector}
/>
);
Expand All @@ -137,6 +137,8 @@ describe('ResilientParamsFields renders', () => {
index={0}
messageVariables={[]}
docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart}
toastNotifications={mocks.notifications.toasts}
http={mocks.http}
actionConnector={connector}
/>
);
Expand All @@ -157,6 +159,8 @@ describe('ResilientParamsFields renders', () => {
index={0}
messageVariables={[]}
docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart}
toastNotifications={mocks.notifications.toasts}
http={mocks.http}
actionConnector={connector}
/>
);
Expand All @@ -180,6 +184,8 @@ describe('ResilientParamsFields renders', () => {
index={0}
messageVariables={[]}
docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart}
toastNotifications={mocks.notifications.toasts}
http={mocks.http}
actionConnector={connector}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
import { i18n } from '@kbn/i18n';

import { ActionParamsProps } from '../../../../types';
import { useAppDependencies } from '../../../app_context';
import { ResilientActionParams } from './types';
import { TextAreaWithMessageVariables } from '../../text_area_with_message_variables';
import { TextFieldWithMessageVariables } from '../../text_field_with_message_variables';
Expand All @@ -32,9 +31,10 @@ const ResilientParamsFields: React.FunctionComponent<ActionParamsProps<Resilient
errors,
messageVariables,
actionConnector,
http,
toastNotifications,
}) => {
const [firstLoad, setFirstLoad] = useState(false);
const { http, toastNotifications } = useAppDependencies();
const { title, description, comments, incidentTypes, severityCode, savedObjectId } =
actionParams.subActionParams || {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import { mountWithIntl } from 'test_utils/enzyme_helpers';
import { ServerLogLevelOptions } from '.././types';
import ServerLogParamsFields from './server_log_params';
import { DocLinksStart } from 'kibana/public';
import { coreMock } from 'src/core/public/mocks';

describe('ServerLogParamsFields renders', () => {
const mocks = coreMock.createSetup();

test('all params fields is rendered', () => {
const actionParams = {
level: ServerLogLevelOptions.TRACE,
Expand All @@ -23,6 +26,8 @@ describe('ServerLogParamsFields renders', () => {
index={0}
defaultMessage={'test default message'}
docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart}
toastNotifications={mocks.notifications.toasts}
http={mocks.http}
/>
);
expect(wrapper.find('[data-test-subj="loggingLevelSelect"]').length > 0).toBeTruthy();
Expand All @@ -44,6 +49,8 @@ describe('ServerLogParamsFields renders', () => {
editAction={() => {}}
index={0}
docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart}
toastNotifications={mocks.notifications.toasts}
http={mocks.http}
/>
);
expect(wrapper.find('[data-test-subj="loggingLevelSelect"]').length > 0).toBeTruthy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import React from 'react';
import { mountWithIntl } from 'test_utils/enzyme_helpers';
import ServiceNowParamsFields from './servicenow_params';
import { DocLinksStart } from 'kibana/public';
import { coreMock } from 'src/core/public/mocks';

describe('ServiceNowParamsFields renders', () => {
test('all params fields is rendered', () => {
const mocks = coreMock.createSetup();
const actionParams = {
subAction: 'pushToService',
subActionParams: {
Expand All @@ -32,6 +34,8 @@ describe('ServiceNowParamsFields renders', () => {
index={0}
messageVariables={[]}
docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart}
toastNotifications={mocks.notifications.toasts}
http={mocks.http}
/>
);
expect(wrapper.find('[data-test-subj="urgencySelect"]').length > 0).toBeTruthy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import React from 'react';
import { mountWithIntl } from 'test_utils/enzyme_helpers';
import SlackParamsFields from './slack_params';
import { DocLinksStart } from 'kibana/public';
import { coreMock } from 'src/core/public/mocks';

describe('SlackParamsFields renders', () => {
test('all params fields is rendered', () => {
const mocks = coreMock.createSetup();
const actionParams = {
message: 'test message',
};
Expand All @@ -21,6 +23,8 @@ describe('SlackParamsFields renders', () => {
editAction={() => {}}
index={0}
docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart}
toastNotifications={mocks.notifications.toasts}
http={mocks.http}
/>
);
expect(wrapper.find('[data-test-subj="messageTextArea"]').length > 0).toBeTruthy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import React from 'react';
import { mountWithIntl } from 'test_utils/enzyme_helpers';
import WebhookParamsFields from './webhook_params';
import { DocLinksStart } from 'kibana/public';
import { coreMock } from 'src/core/public/mocks';

describe('WebhookParamsFields renders', () => {
test('all params fields is rendered', () => {
const mocks = coreMock.createSetup();
const actionParams = {
body: 'test message',
};
Expand All @@ -21,6 +23,8 @@ describe('WebhookParamsFields renders', () => {
editAction={() => {}}
index={0}
docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart}
toastNotifications={mocks.notifications.toasts}
http={mocks.http}
/>
);
expect(wrapper.find('[data-test-subj="bodyJsonEditor"]').length > 0).toBeTruthy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@
*/

import React, { createContext, useContext } from 'react';
import { HttpSetup, ToastsApi, ApplicationStart, DocLinksStart } from 'kibana/public';
import { ActionTypeModel } from '../../types';
import { HttpSetup, ApplicationStart, DocLinksStart, ToastsSetup } from 'kibana/public';
import { ActionTypeModel, ActionConnector } from '../../types';
import { TypeRegistry } from '../type_registry';

export interface ActionsConnectorsContextValue {
http: HttpSetup;
actionTypeRegistry: TypeRegistry<ActionTypeModel>;
toastNotifications: Pick<
ToastsApi,
'get$' | 'add' | 'remove' | 'addSuccess' | 'addWarning' | 'addDanger' | 'addError'
>;
toastNotifications: ToastsSetup;
capabilities: ApplicationStart['capabilities'];
reloadConnectors?: () => Promise<void>;
reloadConnectors?: () => Promise<ActionConnector[] | void>;
docLinks: DocLinksStart;
consumer?: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
EuiText,
EuiLoadingSpinner,
} from '@elastic/eui';
import { HttpSetup, ToastsApi, ApplicationStart, DocLinksStart } from 'kibana/public';
import { HttpSetup, ToastsSetup, ApplicationStart, DocLinksStart } from 'kibana/public';
import { loadActionTypes, loadAllActions as loadConnectors } from '../../lib/action_connector_api';
import {
IErrorObject,
Expand All @@ -56,10 +56,7 @@ interface ActionAccordionFormProps {
setActionParamsProperty: (key: string, value: any, index: number) => void;
http: HttpSetup;
actionTypeRegistry: TypeRegistry<ActionTypeModel>;
toastNotifications: Pick<
ToastsApi,
'get$' | 'add' | 'remove' | 'addSuccess' | 'addWarning' | 'addDanger' | 'addError'
>;
toastNotifications: ToastsSetup;
docLinks: DocLinksStart;
actionTypes?: ActionType[];
messageVariables?: ActionVariable[];
Expand Down Expand Up @@ -311,6 +308,8 @@ export const ActionForm = ({
messageVariables={messageVariables}
defaultMessage={defaultActionMessage ?? undefined}
docLinks={docLinks}
http={http}
toastNotifications={toastNotifications}
actionConnector={actionConnector}
/>
</Suspense>
Expand Down
Loading