Skip to content

Commit

Permalink
Hide action types in action form that don't have actionParamsFields s…
Browse files Browse the repository at this point in the history
…et (#68171)

* Hide action types in alert flyout that don't have actionParamsFields set

* Fix jest tests
  • Loading branch information
mikecote committed Jun 4, 2020
1 parent 241efc4 commit 1f17928
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import React, { Fragment } from 'react';
import React, { Fragment, lazy } from 'react';
import { mountWithIntl, nextTick } from 'test_utils/enzyme_helpers';
import { coreMock } from '../../../../../../../src/core/public/mocks';
import { ReactWrapper } from 'enzyme';
Expand All @@ -18,6 +18,13 @@ jest.mock('../../lib/action_connector_api', () => ({
const actionTypeRegistry = actionTypeRegistryMock.create();
describe('action_form', () => {
let deps: any;

const mockedActionParamsFields = lazy(async () => ({
default() {
return <Fragment />;
},
}));

const alertType = {
id: 'my-alert-type',
iconClass: 'test',
Expand All @@ -41,7 +48,7 @@ describe('action_form', () => {
return validationResult;
},
actionConnectorFields: null,
actionParamsFields: null,
actionParamsFields: mockedActionParamsFields,
};

const disabledByConfigActionType = {
Expand All @@ -56,7 +63,7 @@ describe('action_form', () => {
return validationResult;
},
actionConnectorFields: null,
actionParamsFields: null,
actionParamsFields: mockedActionParamsFields,
};

const disabledByLicenseActionType = {
Expand All @@ -71,7 +78,7 @@ describe('action_form', () => {
return validationResult;
},
actionConnectorFields: null,
actionParamsFields: null,
actionParamsFields: mockedActionParamsFields,
};

const preconfiguredOnly = {
Expand All @@ -86,6 +93,21 @@ describe('action_form', () => {
return validationResult;
},
actionConnectorFields: null,
actionParamsFields: mockedActionParamsFields,
};

const actionTypeWithoutParams = {
id: 'my-action-type-without-params',
iconClass: 'test',
selectMessage: 'test',
validateConnector: (): ValidationResult => {
return { errors: {} };
},
validateParams: (): ValidationResult => {
const validationResult = { errors: {} };
return validationResult;
},
actionConnectorFields: null,
actionParamsFields: null,
};

Expand Down Expand Up @@ -153,6 +175,7 @@ describe('action_form', () => {
disabledByConfigActionType,
disabledByLicenseActionType,
preconfiguredOnly,
actionTypeWithoutParams,
]);
actionTypeRegistry.has.mockReturnValue(true);
actionTypeRegistry.get.mockReturnValue(actionType);
Expand Down Expand Up @@ -237,6 +260,14 @@ describe('action_form', () => {
enabledInLicense: false,
minimumLicenseRequired: 'gold',
},
{
id: actionTypeWithoutParams.id,
name: 'Action type without params',
enabled: true,
enabledInConfig: true,
enabledInLicense: true,
minimumLicenseRequired: 'basic',
},
]}
toastNotifications={deps!.toastNotifications}
docLinks={deps.docLinks}
Expand Down Expand Up @@ -340,5 +371,13 @@ describe('action_form', () => {
.exists()
).toBeTruthy();
});

it(`shouldn't render action types without params component`, async () => {
await setup();
const actionOption = wrapper.find(
`[data-test-subj="${actionTypeWithoutParams.id}-ActionTypeSelectOption"]`
);
expect(actionOption.exists()).toBeFalsy();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ export const ActionForm = ({
actionTypeNodes = actionTypeRegistry
.list()
.filter((item) => actionTypesIndex[item.id])
.filter((item) => !!item.actionParamsFields)
.sort((a, b) =>
actionTypeCompare(actionTypesIndex[a.id], actionTypesIndex[b.id], preconfiguredConnectors)
)
Expand Down

0 comments on commit 1f17928

Please sign in to comment.