Skip to content
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

Add CIT for Date Index Processor in Ingest Node Pipelines #103416

Merged
merged 5 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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', () => {
cuff-links marked this conversation as resolved.
Show resolved Hide resolved
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"
/>
</>
);
};