Skip to content

Commit

Permalink
Add Component Integration Test For Common Processor Fields (elastic#9…
Browse files Browse the repository at this point in the history
…7194)

* Added test for setting common fields. All except the if field as it uses monaco text editor. Reaching out for help with this issue.

* Added  assertion for the code editor.

* Added await to fix promise rejection.

* Added mockCodeEditor data test subject to correct file.

* Removed unneeded comment.

* Split out common processors test and fixed nits in PR feedback.

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
John Dorlus and kibanamachine committed May 6, 2021
1 parent e3824a0 commit 9066827
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 13 deletions.
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>
);
};

0 comments on commit 9066827

Please sign in to comment.