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
  • Loading branch information
YulNaumenko committed Apr 15, 2020
1 parent 08aa214 commit 8ad59c9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ describe('action_form', () => {
config: {},
isPreconfigured: false,
},
{
secrets: {},
id: 'test2',
actionTypeId: actionType.id,
name: 'Test connector 2',
config: {},
isPreconfigured: true,
},
]);
const mockes = coreMock.createSetup();
deps = {
Expand All @@ -100,6 +108,7 @@ describe('action_form', () => {
disabledByLicenseActionType,
]);
actionTypeRegistry.has.mockReturnValue(true);
actionTypeRegistry.get.mockReturnValue(actionType);

const initialAlert = ({
name: 'test',
Expand Down Expand Up @@ -206,6 +215,29 @@ 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 ",
},
Object {
"id": "test2",
"key": "test2",
"label": "Test connector 2 (pre-configured)",
},
]
`);
});

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 @@ -164,6 +164,7 @@ export const ActionForm = ({
label: optionTitle,
value: optionTitle,
id: actionItemId,
'data-test-subj': 'itemActionConnector',
},
];
};
Expand All @@ -177,13 +178,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 @@ -231,6 +228,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 @@ -448,6 +447,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 8ad59c9

Please sign in to comment.