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,47 @@ describe('Processor: Bytes', () => {
const processors = getProcessorValue(onUpdate, BYTES_TYPE);
expect(processors[0].bytes).toEqual({
field: 'field_1',
...defaultBytesParameters,
});
});

test('saves with common fields set', async () => {
cuff-links marked this conversation as resolved.
Show resolved Hide resolved
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('targetField.input', 'target_field');
cuff-links marked this conversation as resolved.
Show resolved Hide resolved

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

// Trying to get the monaco text editor to work with CITs.
cuff-links marked this conversation as resolved.
Show resolved Hide resolved
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,
target_field: 'target_field',
});
});

Expand All @@ -112,13 +146,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
Expand Up @@ -103,6 +103,13 @@ const createActions = (testBed: TestBed<TestSubject>) => {
};
};

export const commonFormFields = {
cuff-links marked this conversation as resolved.
Show resolved Hide resolved
if: undefined,
tag: undefined,
ignore_failure: undefined,
description: undefined,
};

export const setup = async (props: Props): Promise<SetupResult> => {
const testBed = await testBedSetup(props);
return {
Expand Down Expand Up @@ -139,7 +146,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>
);
};