Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ingest Pipelines] add tests for grok processor #130123

Merged
merged 1 commit into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { act } from 'react-dom/test-utils';
import { setup, SetupResult, getProcessorValue, setupEnvironment } from './processor.helpers';

const GROK_TYPE = 'grok';

describe('Processor: Grok', () => {
let onUpdate: jest.Mock;
let testBed: SetupResult;
let clickAddPattern: () => Promise<void>;
const { httpSetup } = setupEnvironment();

beforeAll(() => {
jest.useFakeTimers();
// disable all react-beautiful-dnd development warnings
(window as any)['__react-beautiful-dnd-disable-dev-warnings'] = true;
});

afterAll(() => {
jest.useRealTimers();
// enable all react-beautiful-dnd development warnings
(window as any)['__react-beautiful-dnd-disable-dev-warnings'] = false;
});

beforeEach(async () => {
onUpdate = jest.fn();

await act(async () => {
testBed = await setup(httpSetup, {
value: {
processors: [],
},
onFlyoutOpen: jest.fn(),
onUpdate,
});
});

const { find, component, actions } = testBed;

clickAddPattern = async () => {
await act(async () => {
find('droppableList.addButton').simulate('click');
});
component.update();
};

component.update();

// Open flyout to add new processor
actions.addProcessor();
// Add type (the other fields are not visible until a type is selected)
await actions.addProcessorType(GROK_TYPE);
});

test('prevents form submission if required fields are not provided', async () => {
const {
actions: { saveNewProcessor },
form,
exists,
} = testBed;

// Click submit button with only the type defined
await saveNewProcessor();

// Expect form error as "field" is a required parameter
expect(form.getErrorsMessages()).toEqual(['A field value is required.']);
// Patterns field is also required; it uses EuiDraggable and only shows an error icon when invalid
expect(exists('droppableList.errorIcon')).toBe(true);
});

test('saves with default parameter values', async () => {
const {
actions: { saveNewProcessor },
form,
} = testBed;

// Add "field" value
form.setInputValue('fieldNameField.input', 'test_grok_processor');

// Add pattern 1
form.setInputValue('droppableList.input-0', 'pattern1');

// Add pattern 2
await clickAddPattern();
form.setInputValue('droppableList.input-1', 'pattern2');

// Add pattern 3
await clickAddPattern();
form.setInputValue('droppableList.input-2', 'pattern3');

// Save the field
await saveNewProcessor();

const processors = getProcessorValue(onUpdate, GROK_TYPE);

expect(processors[0][GROK_TYPE]).toEqual({
field: 'test_grok_processor',
patterns: ['pattern1', 'pattern2', 'pattern3'],
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,9 @@ type TestSubject =
| 'transportField.input'
| 'seedField.input'
| 'copyFromInput'
| 'trimSwitch.input';
| 'trimSwitch.input'
| 'droppableList.addButton'
| 'droppableList.errorIcon'
| 'droppableList.input-0'
| 'droppableList.input-1'
| 'droppableList.input-2';
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ function DragAndDropTextListComponent({
[onMove]
);
return (
<EuiFormRow isInvalid={typeof error === 'string'} error={error} fullWidth>
<EuiFormRow
isInvalid={typeof error === 'string'}
error={error}
fullWidth
data-test-subj="droppableList"
>
<>
{/* Label and help text. Also wire up the htmlFor so the label points to the first text field. */}
<EuiFlexGroup
Expand Down Expand Up @@ -158,6 +163,7 @@ function DragAndDropTextListComponent({
<EuiFlexGroup gutterSize="none" alignItems="center">
<EuiFlexItem>
<EuiFieldText
data-test-subj={`input-${idx}`}
id={idx === 0 ? firstItemId : undefined}
isInvalid={isInvalid}
value={field.value}
Expand All @@ -168,7 +174,10 @@ function DragAndDropTextListComponent({
</EuiFlexItem>
{typeof errorMessage === 'string' && (
<EuiFlexItem grow={false}>
<div className="pipelineProcessorsEditor__form__dragAndDropList__errorIcon">
<div
className="pipelineProcessorsEditor__form__dragAndDropList__errorIcon"
data-test-subj="errorIcon"
>
<EuiIconTip
aria-label={errorMessage}
content={errorMessage}
Expand Down Expand Up @@ -208,7 +217,7 @@ function DragAndDropTextListComponent({
})}
</EuiDroppable>
</EuiDragDropContext>
<EuiButtonEmpty iconType="plusInCircle" onClick={onAdd}>
<EuiButtonEmpty iconType="plusInCircle" onClick={onAdd} data-test-subj="addButton">
{addLabel}
</EuiButtonEmpty>
</div>
Expand Down

This file was deleted.