Skip to content

Commit

Permalink
[Alerting] Fixed issue when connectors dropdown not showing all avail…
Browse files Browse the repository at this point in the history
…able connectors (elastic#63636)

# Conflicts:
#	x-pack/plugins/triggers_actions_ui/public/application/sections/action_connector_form/action_form.test.tsx
  • Loading branch information
YulNaumenko committed May 14, 2020
1 parent 3dba1a0 commit 7d64087
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import { act } from 'react-dom/test-utils';
import { actionTypeRegistryMock } from '../../action_type_registry.mock';
import { ValidationResult, Alert, AlertAction } from '../../../types';
import { ActionForm } from './action_form';
jest.mock('../../lib/action_connector_api', () => ({
loadAllActions: jest.fn(),
loadActionTypes: jest.fn(),
}));
const actionTypeRegistry = actionTypeRegistryMock.create();
describe('action_form', () => {
let deps: any;
Expand Down Expand Up @@ -73,6 +77,16 @@ describe('action_form', () => {
let wrapper: ReactWrapper<any>;

async function setup() {
const { loadAllActions } = jest.requireMock('../../lib/action_connector_api');
loadAllActions.mockResolvedValueOnce([
{
secrets: {},
id: 'test',
actionTypeId: actionType.id,
name: 'Test connector',
config: {},
},
]);
const mockes = coreMock.createSetup();
deps = {
toastNotifications: mockes.notifications.toasts,
Expand All @@ -85,6 +99,7 @@ describe('action_form', () => {
disabledByLicenseActionType,
]);
actionTypeRegistry.has.mockReturnValue(true);
actionTypeRegistry.get.mockReturnValue(actionType);

const initialAlert = ({
name: 'test',
Expand Down Expand Up @@ -191,6 +206,24 @@ describe('action_form', () => {
expect(actionOption.exists()).toBeFalsy();
});

it(`renders available connectors for the selected action type`, async () => {
await setup();
const actionOption = wrapper.find(
`[data-test-subj="${actionType.id}-ActionTypeSelectOption"]`
);
actionOption.first().simulate('click');
const combobox = wrapper.find(`[data-test-subj="selectActionConnector"]`);
expect((combobox.first().props() as any).options).toMatchInlineSnapshot(`
Array [
Object {
"id": "test",
"key": "test",
"label": "Test connector ",
},
]
`);
});

it('renders action types disabled by license', async () => {
await setup();
const actionOption = wrapper.find(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export const ActionForm = ({
label: val.name,
value: val.name,
id: actionItemId,
'data-test-subj': 'itemActionConnector',
},
];
};
Expand All @@ -170,13 +171,9 @@ export const ActionForm = ({
index: number
) => {
const optionsList = connectors
.filter(
connectorItem =>
connectorItem.actionTypeId === actionItem.actionTypeId &&
connectorItem.id === actionItem.id
)
.map(({ name, id }) => ({
label: name,
.filter(connectorItem => connectorItem.actionTypeId === actionItem.actionTypeId)
.map(({ name, id, isPreconfigured }) => ({
label: `${name} ${isPreconfigured ? preconfiguredMessage : ''}`,
key: id,
id,
}));
Expand Down Expand Up @@ -224,6 +221,8 @@ export const ActionForm = ({
fullWidth
singleSelection={{ asPlainText: true }}
options={optionsList}
id={`selectActionConnector-${actionItem.id}`}
data-test-subj="selectActionConnector"
selectedOptions={getSelectedOptions(actionItem.id)}
onChange={selectedOptions => {
setActionIdByIndex(selectedOptions[0].id ?? '', index);
Expand Down Expand Up @@ -439,6 +438,7 @@ export const ActionForm = ({
const actionTypeConnectors = connectors.filter(
field => field.actionTypeId === actionTypeModel.id
);

if (actionTypeConnectors.length > 0) {
actions.push({
id: '',
Expand Down

0 comments on commit 7d64087

Please sign in to comment.