-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Ingest pipelines] add extract_device_type to user agent processor #100986
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
Merged
sabarasaba
merged 8 commits into
elastic:master
from
sabarasaba:add_extract_device_type_to_useragent_processor
Jun 24, 2021
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5013195
testing layouts
sabarasaba 336d863
fix copy for beta badge
sabarasaba e6b2c92
replace hardcoded text with i18n strings
sabarasaba cb43ec8
Merge branch 'master' into add_extract_device_type_to_useragent_proce…
sabarasaba 7d6fddd
avoid updating types and just replace label
sabarasaba 102f7f3
Small cr changes
sabarasaba 2631402
Merge branch 'master' into add_extract_device_type_to_useragent_proce…
sabarasaba 68ac613
get rid of style prop and just use a smaller badge
sabarasaba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
125 changes: 125 additions & 0 deletions
125
...nes/public/application/components/pipeline_editor/__jest__/processors/user_agent.test.tsx
This file contains hidden or 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,125 @@ | ||
| /* | ||
| * 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'; | ||
|
|
||
| // Default parameter values automatically added to the user agent processor when saved | ||
| const defaultUserAgentParameters = { | ||
| if: undefined, | ||
| regex_file: undefined, | ||
| properties: undefined, | ||
| description: undefined, | ||
| ignore_missing: undefined, | ||
| ignore_failure: undefined, | ||
| extract_device_type: undefined, | ||
| }; | ||
|
|
||
| const USER_AGENT_TYPE = 'user_agent'; | ||
|
|
||
| describe('Processor: User Agent', () => { | ||
| 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(); | ||
|
|
||
| // Open flyout to add new processor | ||
| testBed.actions.addProcessor(); | ||
| // Add type (the other fields are not visible until a type is selected) | ||
| await testBed.actions.addProcessorType(USER_AGENT_TYPE); | ||
| }); | ||
|
|
||
| test('prevents form submission if required fields are not provided', async () => { | ||
| const { | ||
| actions: { saveNewProcessor }, | ||
| form, | ||
| } = testBed; | ||
|
|
||
| // Click submit button with only the processor type defined | ||
| await saveNewProcessor(); | ||
|
|
||
| // Expect form error as "field" is required parameter | ||
| expect(form.getErrorsMessages()).toEqual(['A field value is required.']); | ||
| }); | ||
|
|
||
| test('saves with just the default parameter value', async () => { | ||
| const { | ||
| actions: { saveNewProcessor }, | ||
| form, | ||
| } = testBed; | ||
|
|
||
| // Add "field" value (required) | ||
| form.setInputValue('fieldNameField.input', 'field_1'); | ||
| // Save the field | ||
| await saveNewProcessor(); | ||
|
|
||
| const processors = getProcessorValue(onUpdate, USER_AGENT_TYPE); | ||
| expect(processors[0][USER_AGENT_TYPE]).toEqual({ | ||
| ...defaultUserAgentParameters, | ||
| field: 'field_1', | ||
| }); | ||
| }); | ||
|
|
||
| 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 | ||
| form.setInputValue('targetField.input', 'target_field'); | ||
| form.setInputValue('regexFileField.input', 'hello*'); | ||
| form.toggleEuiSwitch('ignoreMissingSwitch.input'); | ||
| form.toggleEuiSwitch('ignoreFailureSwitch.input'); | ||
| form.toggleEuiSwitch('extractDeviceTypeSwitch.input'); | ||
| await act(async () => { | ||
| find('propertiesValueField').simulate('change', [{ label: 'os' }]); | ||
| }); | ||
| component.update(); | ||
|
|
||
| // Save the field with new changes | ||
| await saveNewProcessor(); | ||
|
|
||
| const processors = getProcessorValue(onUpdate, USER_AGENT_TYPE); | ||
| expect(processors[0][USER_AGENT_TYPE]).toEqual({ | ||
| ...defaultUserAgentParameters, | ||
| field: 'field_1', | ||
| target_field: 'target_field', | ||
| properties: ['os'], | ||
| regex_file: 'hello*', | ||
| extract_device_type: true, | ||
| ignore_missing: true, | ||
| ignore_failure: true, | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.