From 02e680f7d3461a14884608cd5c7195237b6aa5c2 Mon Sep 17 00:00:00 2001 From: Yuliia Naumenko Date: Mon, 20 Apr 2020 18:27:41 -0700 Subject: [PATCH 1/5] Fixed bug with no possibility to edit the index name after adding --- .../builtin_action_types/es_index.tsx | 2 +- .../apps/triggers_actions_ui/connectors.ts | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/es_index.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/es_index.tsx index 15f68e6a9f441..55a219ca94aea 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/es_index.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/es_index.tsx @@ -151,7 +151,7 @@ const IndexActionConnectorFields: React.FunctionComponent { - editActionConfig('index', selected[0].value); + editActionConfig('index', selected.length > 0 ? selected[0].value : ''); const indices = selected.map(s => s.value as string); // reset time field and expression fields if indices are deleted diff --git a/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/connectors.ts b/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/connectors.ts index 562f64656319e..db16aaefc95b5 100644 --- a/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/connectors.ts +++ b/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/connectors.ts @@ -209,5 +209,23 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { expect(await testSubjects.exists('preconfiguredBadge')).to.be(true); expect(await testSubjects.exists('saveEditedActionButton')).to.be(false); }); + + it('should not be able to clear selected index on index connector form', async () => { + await pageObjects.triggersActionsUI.clickCreateConnectorButton(); + + await testSubjects.click('.index-card'); + + const indexComboBox = await testSubjects.find('connectorIndexesComboBox'); + await indexComboBox.click(); + await indexComboBox.type('k'); + const filterSelectItem = await find.byCssSelector(`.euiFilterSelectItem`); + await filterSelectItem.click(); + + expect(await indexComboBox.getVisibleText()).to.be('.kibana'); + + await testSubjects.click('comboBoxClearButton'); + + expect(await indexComboBox.getVisibleText()).to.be(''); + }); }); }; From f57a104518662ea9b4c545caf064887b5634e3e0 Mon Sep 17 00:00:00 2001 From: Yuliia Naumenko Date: Mon, 20 Apr 2020 21:07:38 -0700 Subject: [PATCH 2/5] fixed test --- .../apps/triggers_actions_ui/connectors.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/connectors.ts b/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/connectors.ts index db16aaefc95b5..1f0501b201866 100644 --- a/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/connectors.ts +++ b/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/connectors.ts @@ -210,12 +210,14 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { expect(await testSubjects.exists('saveEditedActionButton')).to.be(false); }); - it('should not be able to clear selected index on index connector form', async () => { + it('should be able to clear selected index on index connector form', async () => { + await pageObjects.common.navigateToApp('triggersActions'); + await testSubjects.click('connectorsTab'); await pageObjects.triggersActionsUI.clickCreateConnectorButton(); await testSubjects.click('.index-card'); - const indexComboBox = await testSubjects.find('connectorIndexesComboBox'); + const indexComboBox = await find.byCssSelector('#indexConnectorSelectSearchBox'); await indexComboBox.click(); await indexComboBox.type('k'); const filterSelectItem = await find.byCssSelector(`.euiFilterSelectItem`); From 75bc9a9f05e973edf61c7bab6028324118996382 Mon Sep 17 00:00:00 2001 From: Yuliia Naumenko Date: Tue, 21 Apr 2020 08:40:02 -0700 Subject: [PATCH 3/5] fixed test --- .../apps/triggers_actions_ui/connectors.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/connectors.ts b/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/connectors.ts index 1f0501b201866..4d8e8f86f96e7 100644 --- a/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/connectors.ts +++ b/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/connectors.ts @@ -223,11 +223,13 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { const filterSelectItem = await find.byCssSelector(`.euiFilterSelectItem`); await filterSelectItem.click(); - expect(await indexComboBox.getVisibleText()).to.be('.kibana'); + const indexValueBeforeClear = await testSubjects.find('indexConnectorSelectSearchBox'); + expect(await indexValueBeforeClear.getAttribute('value')).to.be('.kibana'); await testSubjects.click('comboBoxClearButton'); - expect(await indexComboBox.getVisibleText()).to.be(''); + const indexValueAfterClear = await testSubjects.find('indexConnectorSelectSearchBox'); + expect(await indexValueAfterClear.getAttribute('value')).to.be(''); }); }); }; From ec43002758be514a70abc7923c180cc6e753c0c1 Mon Sep 17 00:00:00 2001 From: Yuliia Naumenko Date: Tue, 21 Apr 2020 08:50:35 -0700 Subject: [PATCH 4/5] fixed selector --- .../apps/triggers_actions_ui/connectors.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/connectors.ts b/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/connectors.ts index 4d8e8f86f96e7..dff3744a00716 100644 --- a/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/connectors.ts +++ b/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/connectors.ts @@ -223,12 +223,12 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { const filterSelectItem = await find.byCssSelector(`.euiFilterSelectItem`); await filterSelectItem.click(); - const indexValueBeforeClear = await testSubjects.find('indexConnectorSelectSearchBox'); + const indexValueBeforeClear = await find.byCssSelector('.euiComboBoxPill'); expect(await indexValueBeforeClear.getAttribute('value')).to.be('.kibana'); await testSubjects.click('comboBoxClearButton'); - const indexValueAfterClear = await testSubjects.find('indexConnectorSelectSearchBox'); + const indexValueAfterClear = await find.byCssSelector('.euiComboBoxPill'); expect(await indexValueAfterClear.getAttribute('value')).to.be(''); }); }); From f0b1479c9f03d82890bb0be52ad73455ffd02968 Mon Sep 17 00:00:00 2001 From: Yuliia Naumenko Date: Tue, 21 Apr 2020 15:14:12 -0700 Subject: [PATCH 5/5] Move the testing to unit tests --- .../builtin_action_types/es_index.test.tsx | 68 ++++++++++++++++++- .../apps/triggers_actions_ui/connectors.ts | 22 ------ 2 files changed, 66 insertions(+), 24 deletions(-) diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/es_index.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/es_index.test.tsx index 658a0e869548f..fdfaf70648694 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/es_index.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/es_index.test.tsx @@ -4,12 +4,19 @@ * you may not use this file except in compliance with the Elastic License. */ import React, { FunctionComponent } from 'react'; -import { mountWithIntl } from 'test_utils/enzyme_helpers'; +import { mountWithIntl, nextTick } from 'test_utils/enzyme_helpers'; +import { act } from 'react-dom/test-utils'; import { TypeRegistry } from '../../type_registry'; import { registerBuiltInActionTypes } from './index'; import { ActionTypeModel, ActionParamsProps } from '../../../types'; import { IndexActionParams, EsIndexActionConnector } from './types'; import { coreMock } from '../../../../../../../src/core/public/mocks'; +jest.mock('../../../common/index_controls', () => ({ + firstFieldOption: jest.fn(), + getFields: jest.fn(), + getIndexOptions: jest.fn(), + getIndexPatterns: jest.fn(), +})); const ACTION_TYPE_ID = '.index'; let actionTypeModel: ActionTypeModel; @@ -91,13 +98,40 @@ describe('action params validation', () => { }); describe('IndexActionConnectorFields renders', () => { - test('all connector fields is rendered', () => { + test('all connector fields is rendered', async () => { const mocks = coreMock.createSetup(); expect(actionTypeModel.actionConnectorFields).not.toBeNull(); if (!actionTypeModel.actionConnectorFields) { return; } + + const { getIndexPatterns } = jest.requireMock('../../../common/index_controls'); + getIndexPatterns.mockResolvedValueOnce([ + { + id: 'indexPattern1', + attributes: { + title: 'indexPattern1', + }, + }, + { + id: 'indexPattern2', + attributes: { + title: 'indexPattern2', + }, + }, + ]); + const { getFields } = jest.requireMock('../../../common/index_controls'); + getFields.mockResolvedValueOnce([ + { + type: 'date', + name: 'test1', + }, + { + type: 'text', + name: 'test2', + }, + ]); const ConnectorFields = actionTypeModel.actionConnectorFields; const actionConnector = { secrets: {}, @@ -119,8 +153,38 @@ describe('IndexActionConnectorFields renders', () => { http={mocks.http} /> ); + + await act(async () => { + await nextTick(); + wrapper.update(); + }); + expect(wrapper.find('[data-test-subj="connectorIndexesComboBox"]').length > 0).toBeTruthy(); expect(wrapper.find('[data-test-subj="indexRefreshCheckbox"]').length > 0).toBeTruthy(); + + const indexSearchBoxValue = wrapper.find('[data-test-subj="comboBoxSearchInput"]'); + expect(indexSearchBoxValue.first().props().value).toEqual(''); + + const indexComboBox = wrapper.find('#indexConnectorSelectSearchBox'); + indexComboBox.first().simulate('click'); + const event = { target: { value: 'indexPattern1' } }; + indexComboBox + .find('input') + .first() + .simulate('change', event); + + const indexSearchBoxValueBeforeEnterData = wrapper.find( + '[data-test-subj="comboBoxSearchInput"]' + ); + expect(indexSearchBoxValueBeforeEnterData.first().props().value).toEqual('indexPattern1'); + + const indexComboBoxClear = wrapper.find('[data-test-subj="comboBoxClearButton"]'); + indexComboBoxClear.first().simulate('click'); + + const indexSearchBoxValueAfterEnterData = wrapper.find( + '[data-test-subj="comboBoxSearchInput"]' + ); + expect(indexSearchBoxValueAfterEnterData.first().props().value).toEqual('indexPattern1'); }); }); diff --git a/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/connectors.ts b/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/connectors.ts index dff3744a00716..562f64656319e 100644 --- a/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/connectors.ts +++ b/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/connectors.ts @@ -209,27 +209,5 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { expect(await testSubjects.exists('preconfiguredBadge')).to.be(true); expect(await testSubjects.exists('saveEditedActionButton')).to.be(false); }); - - it('should be able to clear selected index on index connector form', async () => { - await pageObjects.common.navigateToApp('triggersActions'); - await testSubjects.click('connectorsTab'); - await pageObjects.triggersActionsUI.clickCreateConnectorButton(); - - await testSubjects.click('.index-card'); - - const indexComboBox = await find.byCssSelector('#indexConnectorSelectSearchBox'); - await indexComboBox.click(); - await indexComboBox.type('k'); - const filterSelectItem = await find.byCssSelector(`.euiFilterSelectItem`); - await filterSelectItem.click(); - - const indexValueBeforeClear = await find.byCssSelector('.euiComboBoxPill'); - expect(await indexValueBeforeClear.getAttribute('value')).to.be('.kibana'); - - await testSubjects.click('comboBoxClearButton'); - - const indexValueAfterClear = await find.byCssSelector('.euiComboBoxPill'); - expect(await indexValueAfterClear.getAttribute('value')).to.be(''); - }); }); };