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

Add Component Integration Test For Common Processor Fields #97194

Merged
merged 10 commits into from
May 6, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
import { act } from 'react-dom/test-utils';
import { setup, SetupResult, getProcessorValue } from './processor.helpers';

// Default parameter values automatically added to the Bytes processor when saved
const defaultBytesParameters = {
ignore_failure: undefined,
description: undefined,
};

const BYTES_TYPE = 'bytes';

describe('Processor: Bytes', () => {
Expand Down Expand Up @@ -85,7 +79,6 @@ describe('Processor: Bytes', () => {
const processors = getProcessorValue(onUpdate, BYTES_TYPE);
expect(processors[0].bytes).toEqual({
field: 'field_1',
...defaultBytesParameters,
});
});

Expand All @@ -112,13 +105,9 @@ describe('Processor: Bytes', () => {

const processors = getProcessorValue(onUpdate, BYTES_TYPE);
expect(processors[0].bytes).toEqual({
description: undefined,
field: 'field_1',
ignore_failure: undefined,
target_field: 'target_field',
ignore_missing: true,
tag: undefined,
if: undefined,
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* 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 } from './processor.helpers';

const BYTES_TYPE = 'bytes';

describe('Processor: Common Fields For All Processors', () => {
let onUpdate: jest.Mock;
let testBed: SetupResult;

beforeAll(() => {
jest.useFakeTimers();
});

afterAll(() => {
jest.useRealTimers();
});

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

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

test('saves with common fields set', async () => {
const {
actions: { addProcessor, saveNewProcessor, addProcessorType },
form,
find,
} = testBed;

// This test ensures that the common fields that are used across all processors
// works and removes the need for those fields to be in every processors' test.

// Open flyout to add new processor
addProcessor();
// Add type (the other fields are not visible until a type is selected)
await addProcessorType(BYTES_TYPE);
// Add "field" value (required)
form.setInputValue('fieldNameField.input', 'field_1');

form.toggleEuiSwitch('ignoreFailureSwitch.input');

form.setInputValue('tagField.input', 'some_tag');

// Edit the Code Editor
const jsonContent = JSON.stringify({ content: "ctx?.network?.name == 'Guest'" });
await find('mockCodeEditor').simulate('change', { jsonContent });

// Save the field
await saveNewProcessor();

const processors = getProcessorValue(onUpdate, BYTES_TYPE);
expect(processors[0].bytes).toEqual({
field: 'field_1',
ignore_failure: true,
if: jsonContent,
tag: 'some_tag',
ignore_missing: undefined,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ type TestSubject =
| 'addProcessorForm.submitButton'
| 'processorTypeSelector.input'
| 'fieldNameField.input'
| 'mockCodeEditor'
| 'tagField.input'
| 'ignoreMissingSwitch.input'
| 'ignoreFailureSwitch.input'
| 'ifField.textarea'
| 'targetField.input'
| 'keepOriginalField.input'
| 'removeIfSuccessfulField.input';
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const CommonProcessorFields: FunctionComponent = () => {
return (
<section>
<UseField
data-test-subj="ifField"
config={ifConfig}
component={TextEditor}
componentProps={{
Expand All @@ -81,9 +82,14 @@ export const CommonProcessorFields: FunctionComponent = () => {
path="fields.if"
/>

<UseField config={tagConfig} component={Field} path="fields.tag" />
<UseField data-test-subj="tagField" config={tagConfig} component={Field} path="fields.tag" />

<UseField config={ignoreFailureConfig} component={ToggleField} path="fields.ignore_failure" />
<UseField
data-test-subj="ignoreFailureSwitch"
config={ignoreFailureConfig}
component={ToggleField}
path="fields.ignore_failure"
/>
</section>
);
};