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 CIT for Date Index Processor in Ingest Node Pipelines (elastic#10…
…3416) * Added initial work for date index processor CITs. * Fixed the tests and added the remaining coverage. * Fixed message for date rounding error and updated tests to use GMT since that timezone actually works with the API. * Update Date Index Name processor test name. Co-authored-by: Yulia Čech <[email protected]> Co-authored-by: Yulia Čech <[email protected]>
- Loading branch information
1 parent
ca442a4
commit a917835
Showing
3 changed files
with
147 additions
and
3 deletions.
There are no files selected for viewing
124 changes: 124 additions & 0 deletions
124
...nes/public/application/components/pipeline_editor/__jest__/processors/date_index.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,124 @@ | ||
/* | ||
* 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 DATE_INDEX_TYPE = 'date_index_name'; | ||
|
||
describe('Processor: Date Index Name', () => { | ||
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(DATE_INDEX_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 "date rounding" are required parameters | ||
expect(form.getErrorsMessages()).toEqual([ | ||
'A field value is required.', | ||
'A date rounding value is required.', | ||
]); | ||
}); | ||
|
||
test('saves with required field and date rounding parameter values', async () => { | ||
const { | ||
actions: { saveNewProcessor }, | ||
form, | ||
} = testBed; | ||
|
||
// Add "field" value (required) | ||
form.setInputValue('fieldNameField.input', '@timestamp'); | ||
|
||
// Select second value for date rounding | ||
form.setSelectValue('dateRoundingField', 's'); | ||
|
||
// Save the field | ||
await saveNewProcessor(); | ||
|
||
const processors = await getProcessorValue(onUpdate, DATE_INDEX_TYPE); | ||
expect(processors[0].date_index_name).toEqual({ | ||
field: '@timestamp', | ||
date_rounding: 's', | ||
}); | ||
}); | ||
|
||
test('allows optional parameters to be set', async () => { | ||
const { | ||
actions: { saveNewProcessor }, | ||
form, | ||
find, | ||
component, | ||
} = testBed; | ||
|
||
form.setInputValue('fieldNameField.input', 'field_1'); | ||
|
||
form.setSelectValue('dateRoundingField', 'd'); | ||
|
||
form.setInputValue('indexNamePrefixField.input', 'prefix'); | ||
|
||
form.setInputValue('indexNameFormatField.input', 'yyyy-MM'); | ||
|
||
await act(async () => { | ||
find('dateFormatsField.input').simulate('change', [{ label: 'ISO8601' }]); | ||
}); | ||
component.update(); | ||
|
||
form.setInputValue('timezoneField.input', 'GMT'); | ||
|
||
form.setInputValue('localeField.input', 'SPANISH'); | ||
// Save the field with new changes | ||
await saveNewProcessor(); | ||
|
||
const processors = await getProcessorValue(onUpdate, DATE_INDEX_TYPE); | ||
expect(processors[0].date_index_name).toEqual({ | ||
field: 'field_1', | ||
date_rounding: 'd', | ||
index_name_format: 'yyyy-MM', | ||
index_name_prefix: 'prefix', | ||
date_formats: ['ISO8601'], | ||
locale: 'SPANISH', | ||
timezone: 'GMT', | ||
}); | ||
}); | ||
}); |
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