Hide action types in action form that don't have actionParamsFields set (#68171)
* Hide action types in alert flyout that don't have actionParamsFields set * Fix jest tests
This commit is contained in:
parent
3602f0f9aa
commit
c8e6855281
2 changed files with 44 additions and 4 deletions
|
@ -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';
|
||||
|
@ -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',
|
||||
|
@ -41,7 +48,7 @@ describe('action_form', () => {
|
|||
return validationResult;
|
||||
},
|
||||
actionConnectorFields: null,
|
||||
actionParamsFields: null,
|
||||
actionParamsFields: mockedActionParamsFields,
|
||||
};
|
||||
|
||||
const disabledByConfigActionType = {
|
||||
|
@ -56,7 +63,7 @@ describe('action_form', () => {
|
|||
return validationResult;
|
||||
},
|
||||
actionConnectorFields: null,
|
||||
actionParamsFields: null,
|
||||
actionParamsFields: mockedActionParamsFields,
|
||||
};
|
||||
|
||||
const disabledByLicenseActionType = {
|
||||
|
@ -71,7 +78,7 @@ describe('action_form', () => {
|
|||
return validationResult;
|
||||
},
|
||||
actionConnectorFields: null,
|
||||
actionParamsFields: null,
|
||||
actionParamsFields: mockedActionParamsFields,
|
||||
};
|
||||
|
||||
const preconfiguredOnly = {
|
||||
|
@ -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,
|
||||
};
|
||||
|
||||
|
@ -153,6 +175,7 @@ describe('action_form', () => {
|
|||
disabledByConfigActionType,
|
||||
disabledByLicenseActionType,
|
||||
preconfiguredOnly,
|
||||
actionTypeWithoutParams,
|
||||
]);
|
||||
actionTypeRegistry.has.mockReturnValue(true);
|
||||
actionTypeRegistry.get.mockReturnValue(actionType);
|
||||
|
@ -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}
|
||||
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -547,6 +547,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)
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue