forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Component Integration Test For Common Processor Fields (elastic#9…
…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
1 parent
e3824a0
commit 9066827
Showing
4 changed files
with
89 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...plication/components/pipeline_editor/__jest__/processors/common_processor_fields.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters