Skip to content

Commit

Permalink
test success case
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmorris committed Sep 14, 2020
1 parent b1f327b commit 181d284
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,48 +32,47 @@ export const IndexParamsFields = ({
};

return (
<>
<JsonEditorWithMessageVariables
messageVariables={messageVariables}
paramsProperty={'documents'}
inputTargetValue={
documents && documents.length > 0 ? ((documents[0] as unknown) as string) : undefined
<JsonEditorWithMessageVariables
messageVariables={messageVariables}
paramsProperty={'documents'}
data-test-subj="documentToIndex"
inputTargetValue={
documents && documents.length > 0 ? ((documents[0] as unknown) as string) : undefined
}
label={i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.indexAction.documentsFieldLabel',
{
defaultMessage: 'Document to index',
}
label={i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.indexAction.documentsFieldLabel',
{
defaultMessage: 'Document to index',
}
)}
aria-label={i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.indexAction.jsonDocAriaLabel',
{
defaultMessage: 'Code editor',
}
)}
errors={errors.documents as string[]}
onDocumentsChange={onDocumentsChange}
helpText={
<EuiLink
href={`${docLinks.ELASTIC_WEBSITE_URL}guide/en/kibana/${docLinks.DOC_LINK_VERSION}/index-action-type.html#index-action-configuration`}
target="_blank"
>
<FormattedMessage
id="xpack.triggersActionsUI.components.builtinActionTypes.indexAction.indexDocumentHelpLabel"
defaultMessage="Index document example."
/>
</EuiLink>
)}
aria-label={i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.indexAction.jsonDocAriaLabel',
{
defaultMessage: 'Code editor',
}
onBlur={() => {
if (
!(documents && documents.length > 0 ? ((documents[0] as unknown) as string) : undefined)
) {
// set document as empty to turn on the validation for non empty valid JSON object
onDocumentsChange('{}');
}
}}
/>
</>
)}
errors={errors.documents as string[]}
onDocumentsChange={onDocumentsChange}
helpText={
<EuiLink
href={`${docLinks.ELASTIC_WEBSITE_URL}guide/en/kibana/${docLinks.DOC_LINK_VERSION}/index-action-type.html#index-action-configuration`}
target="_blank"
>
<FormattedMessage
id="xpack.triggersActionsUI.components.builtinActionTypes.indexAction.indexDocumentHelpLabel"
defaultMessage="Index document example."
/>
</EuiLink>
}
onBlur={() => {
if (
!(documents && documents.length > 0 ? ((documents[0] as unknown) as string) : undefined)
) {
// set document as empty to turn on the validation for non empty valid JSON object
onDocumentsChange('{}');
}
}}
/>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
EuiDescriptionList,
EuiCallOut,
} from '@elastic/eui';
import { isEmpty } from 'lodash';
import { Option, map, getOrElse } from 'fp-ts/lib/Option';
import { pipe } from 'fp-ts/lib/pipeable';
import { FormattedMessage } from '@kbn/i18n/react';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
const pageObjects = getPageObjects(['common', 'triggersActionsUI', 'header']);
const find = getService('find');
const retry = getService('retry');
const comboBox = getService('comboBox');

describe('Connectors', function () {
before(async () => {
Expand Down Expand Up @@ -95,7 +96,8 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {

it('should test a connector', async () => {
const connectorName = generateUniqueKey();
await createConnector(connectorName);
const indexName = generateUniqueKey();
await createIndexConnector(connectorName, indexName);

await pageObjects.triggersActionsUI.searchConnectors(connectorName);

Expand All @@ -106,14 +108,26 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {

await find.clickByCssSelector('[data-test-subj="testConnectorTab"]');

await testSubjects.setValue('messageTextArea', 'some message');
// test success
await testSubjects.setValue('documentsJsonEditor', '{ "key": "value" }');

await find.clickByCssSelector('[data-test-subj="executeActionButton"]:not(disabled)');

await retry.try(async () => {
await testSubjects.find('executionSuccessfulResult');
});

// test failure
await testSubjects.setValue('documentsJsonEditor', '{ "": "value" }', {
clearWithKeyboard: true,
});

await find.clickByCssSelector('[data-test-subj="executeActionButton"]:not(disabled)');

await retry.try(async () => {
const executionFailureResultCallout = await testSubjects.find('executionFailureResult');
expect(await executionFailureResultCallout.getVisibleText()).to.match(
/error posting slack message/
/error indexing documents/
);
});
});
Expand Down Expand Up @@ -235,4 +249,17 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await find.clickByCssSelector('[data-test-subj="saveNewActionButton"]:not(disabled)');
await pageObjects.common.closeToast();
}

async function createIndexConnector(connectorName: string, indexName: string) {
await pageObjects.triggersActionsUI.clickCreateConnectorButton();

await testSubjects.click('.index-card');

await testSubjects.setValue('nameInput', connectorName);

await comboBox.set('connectorIndexesComboBox', indexName);

await find.clickByCssSelector('[data-test-subj="saveNewActionButton"]:not(disabled)');
await pageObjects.common.closeToast();
}
};

0 comments on commit 181d284

Please sign in to comment.