From bffbffcb0ebf8e746ad50353b5181fdd9d04f2be Mon Sep 17 00:00:00 2001 From: Alison Goryachev Date: Thu, 14 May 2020 08:52:44 -0400 Subject: [PATCH] [7.x] [Ingest pipelines] Create pipeline functional test (#64945) (#66514) --- .../helpers/pipeline_form.helpers.ts | 2 +- .../pipeline_form/pipeline_form_fields.tsx | 4 +- .../sections/pipelines_list/table.tsx | 18 ++++++- .../apps/ingest_pipelines/ingest_pipelines.ts | 41 +++++++++++++- .../page_objects/ingest_pipelines_page.ts | 53 ++++++++++++++++++- 5 files changed, 112 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/pipeline_form.helpers.ts b/x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/pipeline_form.helpers.ts index d56e92a2419c4..8a14ed13f2022 100644 --- a/x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/pipeline_form.helpers.ts +++ b/x-pack/plugins/ingest_pipelines/__jest__/client_integration/helpers/pipeline_form.helpers.ts @@ -47,7 +47,7 @@ export type PipelineFormTestSubjects = | 'versionField' | 'nameField.input' | 'descriptionField.input' - | 'processorsField' + | 'processorsEditor' | 'onFailureToggle' | 'onFailureEditor' | 'testPipelineButton' diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/pipeline_form_fields.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/pipeline_form_fields.tsx index 8144228b1e9d5..dfdd9ea2f748e 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/pipeline_form_fields.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/pipeline_form_fields.tsx @@ -159,7 +159,7 @@ export const PipelineFormFields: React.FunctionComponent = ({ component={JsonEditorField} componentProps={{ euiCodeEditorProps: { - ['data-test-subj']: 'processorsField', + 'data-test-subj': 'processorsEditor', height: '300px', 'aria-label': i18n.translate('xpack.ingestPipelines.form.processorsFieldAriaLabel', { defaultMessage: 'Processors JSON editor', @@ -217,7 +217,7 @@ export const PipelineFormFields: React.FunctionComponent = ({ component={JsonEditorField} componentProps={{ euiCodeEditorProps: { - ['data-test-subj']: 'onFailureEditor', + 'data-test-subj': 'onFailureEditor', height: '300px', 'aria-label': i18n.translate('xpack.ingestPipelines.form.onFailureFieldAriaLabel', { defaultMessage: 'Failure processors JSON editor', diff --git a/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_list/table.tsx b/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_list/table.tsx index 7f7020c41a298..e5c708b5c0e53 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_list/table.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_list/table.tsx @@ -6,7 +6,13 @@ import React, { FunctionComponent, useState } from 'react'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; -import { EuiInMemoryTable, EuiLink, EuiButton, EuiInMemoryTableProps } from '@elastic/eui'; +import { + EuiInMemoryTable, + EuiLink, + EuiButton, + EuiInMemoryTableProps, + EuiTableFieldDataColumnType, +} from '@elastic/eui'; import { BASE_PATH } from '../../../../common/constants'; import { Pipeline } from '../../../../common/types'; @@ -36,6 +42,16 @@ export const PipelineTable: FunctionComponent = ({ selection: { onSelectionChange: setSelection, }, + rowProps: () => ({ + 'data-test-subj': 'pipelineTableRow', + }), + cellProps: (pipeline, column) => { + const { field } = column as EuiTableFieldDataColumnType; + + return { + 'data-test-subj': `pipelineTableRow-${field}`, + }; + }, search: { toolsLeft: selection.length > 0 ? ( diff --git a/x-pack/test/functional/apps/ingest_pipelines/ingest_pipelines.ts b/x-pack/test/functional/apps/ingest_pipelines/ingest_pipelines.ts index 1b22f8f35d7ad..c69488f68215d 100644 --- a/x-pack/test/functional/apps/ingest_pipelines/ingest_pipelines.ts +++ b/x-pack/test/functional/apps/ingest_pipelines/ingest_pipelines.ts @@ -7,9 +7,32 @@ import expect from '@kbn/expect'; import { FtrProviderContext } from '../../ftr_provider_context'; +const PIPELINE = { + name: 'test_pipeline', + description: 'My pipeline description.', + version: 1, + processors: JSON.stringify([ + { + set: { + field: 'foo', + value: 'new', + }, + }, + ]), + onFailureProcessors: JSON.stringify([ + { + set: { + field: '_index', + value: 'failed-{{ _index }}', + }, + }, + ]), +}; + export default ({ getPageObjects, getService }: FtrProviderContext) => { const pageObjects = getPageObjects(['common', 'ingestPipelines']); const log = getService('log'); + const es = getService('legacyEs'); describe('Ingest Pipelines', function() { this.tags('smoke'); @@ -18,10 +41,26 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { }); it('Loads the app', async () => { - await log.debug('Checking for section heading to say Ingest Node Pipelines.'); + log.debug('Checking for section heading to say Ingest Node Pipelines.'); const headingText = await pageObjects.ingestPipelines.sectionHeadingText(); expect(headingText).to.be('Ingest Node Pipelines'); }); + + it('Creates a pipeline', async () => { + await pageObjects.ingestPipelines.createNewPipeline(PIPELINE); + + const pipelinesList = await pageObjects.ingestPipelines.getPipelinesList(); + const newPipelineExists = Boolean( + pipelinesList.find(pipelineName => pipelineName === PIPELINE.name) + ); + + expect(newPipelineExists).to.be(true); + }); + + after(async () => { + // Delete the pipeline that was created + await es.ingest.deletePipeline({ id: PIPELINE.name }); + }); }); }; diff --git a/x-pack/test/functional/page_objects/ingest_pipelines_page.ts b/x-pack/test/functional/page_objects/ingest_pipelines_page.ts index abc85277a3617..fb81694363bf4 100644 --- a/x-pack/test/functional/page_objects/ingest_pipelines_page.ts +++ b/x-pack/test/functional/page_objects/ingest_pipelines_page.ts @@ -4,14 +4,65 @@ * you may not use this file except in compliance with the Elastic License. */ +import { WebElementWrapper } from 'test/functional/services/lib/web_element_wrapper'; import { FtrProviderContext } from '../ftr_provider_context'; -export function IngestPipelinesPageProvider({ getService }: FtrProviderContext) { +export function IngestPipelinesPageProvider({ getService, getPageObjects }: FtrProviderContext) { const testSubjects = getService('testSubjects'); + const pageObjects = getPageObjects(['header']); + const aceEditor = getService('aceEditor'); return { async sectionHeadingText() { return await testSubjects.getVisibleText('appTitle'); }, + + async createNewPipeline({ + name, + description, + version, + processors, + onFailureProcessors, + }: { + name: string; + description: string; + version?: number; + processors?: string; + onFailureProcessors?: string; + }) { + await testSubjects.click('createPipelineButton'); + await testSubjects.exists('pipelineForm'); + + await testSubjects.setValue('nameField > input', name); + await testSubjects.setValue('descriptionField > input', description); + + if (version) { + await testSubjects.click('versionToggle'); + await testSubjects.setValue('versionField > input', version.toString()); + } + + if (processors) { + await aceEditor.setValue('processorsEditor', processors); + } + + if (onFailureProcessors) { + await testSubjects.click('onFailureToggle'); + await aceEditor.setValue('onFailureEditor', processors); + } + + await testSubjects.click('submitButton'); + await pageObjects.header.waitUntilLoadingHasFinished(); + }, + + async getPipelinesList() { + const pipelines = await testSubjects.findAll('pipelineTableRow'); + + const getPipelineName = async (pipeline: WebElementWrapper) => { + const pipelineNameElement = await pipeline.findByTestSubject('pipelineTableRow-name'); + return await pipelineNameElement.getVisibleText(); + }; + + return await Promise.all(pipelines.map(pipeline => getPipelineName(pipeline))); + }, }; }