Skip to content

Commit

Permalink
Add CIT for Date Index Processor in Ingest Node Pipelines (#103416) (#…
Browse files Browse the repository at this point in the history
…104036)

* 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]>

Co-authored-by: John Dorlus <[email protected]>
Co-authored-by: Yulia Čech <[email protected]>
  • Loading branch information
3 people authored Jul 1, 2021
1 parent 062777c commit d90bae4
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 3 deletions.
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',
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,14 @@ type TestSubject =
| 'mockCodeEditor'
| 'tagField.input'
| 'typeSelectorField'
| 'dateRoundingField'
| 'ignoreMissingSwitch.input'
| 'ignoreFailureSwitch.input'
| 'indexNamePrefixField.input'
| 'indexNameFormatField.input'
| 'dateFormatsField.input'
| 'timezoneField.input'
| 'localeField.input'
| 'ifField.textarea'
| 'targetField.input'
| 'keepOriginalField.input'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const fieldsConfig: FieldsConfig = {
i18n.translate(
'xpack.ingestPipelines.pipelineEditor.dateIndexNameForm.dateRoundingRequiredError',
{
defaultMessage: 'A field value is required.',
defaultMessage: 'A date rounding value is required.',
}
)
),
Expand Down Expand Up @@ -160,6 +160,7 @@ export const DateIndexName: FunctionComponent = () => {
component={SelectField}
componentProps={{
euiFieldProps: {
'data-test-subj': 'dateRoundingField',
options: [
{
value: 'y',
Expand Down Expand Up @@ -217,26 +218,39 @@ export const DateIndexName: FunctionComponent = () => {
/>

<UseField
data-test-subj="indexNamePrefixField"
config={fieldsConfig.index_name_prefix}
component={Field}
path="fields.index_name_prefix"
/>

<UseField
data-test-subj="indexNameFormatField"
config={fieldsConfig.index_name_format}
component={Field}
path="fields.index_name_format"
/>

<UseField
data-test-subj="dateFormatsField"
config={fieldsConfig.date_formats}
component={ComboBoxField}
path="fields.date_formats"
/>

<UseField config={fieldsConfig.timezone} component={Field} path="fields.timezone" />
<UseField
data-test-subj="timezoneField"
config={fieldsConfig.timezone}
component={Field}
path="fields.timezone"
/>

<UseField config={fieldsConfig.locale} component={Field} path="fields.locale" />
<UseField
data-test-subj="localeField"
config={fieldsConfig.locale}
component={Field}
path="fields.locale"
/>
</>
);
};

0 comments on commit d90bae4

Please sign in to comment.