Skip to content

Commit

Permalink
Add Component Integration Test for Append Processor (#95001) (#99829)
Browse files Browse the repository at this point in the history
* Added first steps for append processor test and added data test subject for append processor input combo box.

* Added first steps for append processor test and added data test subject for append processor input combo box.

* Fixed assertion for processor.

* Merged in newer test functionality and used it in the append processor test.

* Fixed asssertion and form to use append box.

* Update snapshot.

* Fixed assertion for array.

* Made changes per notes in PR.

* Used common fields var in test.

* Fixed merge conflict.

* Fixed unused vars and added data test subject to helper file.

* Removed this snapshot that was erronously added to PR due to a merge conflict.

* Removed old common field var from uri tests.

* Fixed nits in PR in all tet files.

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: John Dorlus <[email protected]>
  • Loading branch information
kibanamachine and John Dorlus authored May 11, 2021
1 parent 7629570 commit dac56c1
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* 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 APPEND_TYPE = 'append';

describe('Processor: Append', () => {
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();
const {
actions: { addProcessor, addProcessorType },
} = testBed;
// Open the processor flyout
addProcessor();

// Add type (the other fields are not visible until a type is selected)
await addProcessorType(APPEND_TYPE);
});

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

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

// Expect form error as "field" and "value" are required parameters
expect(form.getErrorsMessages()).toEqual([
'A field value is required.',
'A value is required.',
]);
});

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

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

await act(async () => {
find('appendValueField.input').simulate('change', [{ label: 'Some_Value' }]);
});
component.update();

// Save the field
await saveNewProcessor();

const processors = getProcessorValue(onUpdate, APPEND_TYPE);
expect(processors[0].append).toEqual({
field: 'field_1',
value: ['Some_Value'],
});
});

test('allows optional parameters to be set', async () => {
const {
actions: { saveNewProcessor },
form,
find,
component,
} = testBed;

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

// Set optional parameteres
await act(async () => {
find('appendValueField.input').simulate('change', [{ label: 'Some_Value' }]);
component.update();
});

form.toggleEuiSwitch('ignoreFailureSwitch.input');
// Save the field with new changes
await saveNewProcessor();

const processors = getProcessorValue(onUpdate, APPEND_TYPE);
expect(processors[0].append).toEqual({
field: 'field_1',
ignore_failure: true,
value: ['Some_Value'],
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,21 @@ describe('Processor: Bytes', () => {
});
});
testBed.component.update();
});

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

// Open flyout to add new processor
// Open the processor flyout
addProcessor();
// Click submit button without entering any fields
await saveNewProcessor();

// Expect form error as a processor type is required
expect(form.getErrorsMessages()).toEqual(['A type is required.']);

// Add type (the other fields are not visible until a type is selected)
await addProcessorType(BYTES_TYPE);
});

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

// Click submit button with only the type defined
await saveNewProcessor();
Expand All @@ -61,16 +58,12 @@ describe('Processor: Bytes', () => {
expect(form.getErrorsMessages()).toEqual(['A field value is required.']);
});

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

// 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');
// Save the field
Expand All @@ -84,14 +77,10 @@ describe('Processor: Bytes', () => {

test('allows optional parameters to be set', async () => {
const {
actions: { addProcessor, addProcessorType, saveNewProcessor },
actions: { saveNewProcessor },
form,
} = testBed;

// 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');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ type TestSubject =
| 'addProcessorForm.submitButton'
| 'addProcessorButton'
| 'addProcessorForm.submitButton'
| 'appendValueField.input'
| 'processorTypeSelector.input'
| 'fieldNameField.input'
| 'mockCodeEditor'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import { setup, SetupResult, getProcessorValue } from './processor.helpers';
const defaultUriPartsParameters = {
keep_original: undefined,
remove_if_successful: undefined,
ignore_failure: undefined,
description: undefined,
};

const URI_PARTS_TYPE = 'uri_parts';
Expand Down Expand Up @@ -43,19 +41,22 @@ describe('Processor: URI parts', () => {
});
});
testBed.component.update();
});

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

// Open flyout to add new processor
// Open the processor flyout
addProcessor();

// Add type (the other fields are not visible until a type is selected)
await addProcessorType(URI_PARTS_TYPE);
});

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

// Click submit button with only the type defined
await saveNewProcessor();
Expand All @@ -64,16 +65,12 @@ describe('Processor: URI parts', () => {
expect(form.getErrorsMessages()).toEqual(['A field value is required.']);
});

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

// Open flyout to add new processor
addProcessor();
// Add type (the other fields are not visible until a type is selected)
await addProcessorType(URI_PARTS_TYPE);
// Add "field" value (required)
form.setInputValue('fieldNameField.input', 'field_1');
// Save the field
Expand All @@ -88,14 +85,10 @@ describe('Processor: URI parts', () => {

test('allows optional parameters to be set', async () => {
const {
actions: { addProcessor, addProcessorType, saveNewProcessor },
actions: { saveNewProcessor },
form,
} = testBed;

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

Expand All @@ -109,9 +102,7 @@ describe('Processor: URI parts', () => {

const processors = getProcessorValue(onUpdate, URI_PARTS_TYPE);
expect(processors[0].uri_parts).toEqual({
description: undefined,
field: 'field_1',
ignore_failure: undefined,
keep_original: false,
remove_if_successful: true,
target_field: 'target_field',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ export const Append: FunctionComponent = () => {
})}
/>

<UseField config={fieldsConfig.value} component={ComboBoxField} path="fields.value" />
<UseField
data-test-subj="appendValueField"
config={fieldsConfig.value}
component={ComboBoxField}
path="fields.value"
/>
</>
);
};

0 comments on commit dac56c1

Please sign in to comment.