Skip to content

Commit

Permalink
Added initial work for date index processor CITs.
Browse files Browse the repository at this point in the history
  • Loading branch information
John Dorlus committed Jun 26, 2021
1 parent df8787b commit 0e85c65
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* 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 = 'dateIndex';

describe('Processor: Date Index', () => {
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 "value" are required parameters
expect(form.getErrorsMessages()).toEqual([
'A field value is required.',
'A value is required.',
]);
});

test('saves with required parameter values', async () => {
const {
actions: { saveNewProcessor },
form,
find,
component,
} = testBed;

// Add "field" value (required)
form.setInputValue('fieldNameField.input', 'field_1');

await act(async () => {
find('appendValueField.input').simulate('change', [{ label: 'Some_Value' }]);
});
component.update();

// Save the field
await saveNewProcessor();

const processors = getProcessorValue(onUpdate, DATE_INDEX_TYPE);
expect(processors[0].dateIndex).toEqual({
field: 'field_1',
value: ['Some_Value'],
});
});

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
await act(async () => {
find('appendValueField.input').simulate('change', [{ label: 'Some_Value' }]);
component.update();
});

form.toggleEuiSwitch('ignoreFailureSwitch.input');
// Save the field with new changes
await saveNewProcessor();

const processors = getProcessorValue(onUpdate, DATE_INDEX_TYPE);
expect(processors[0].dateIndex).toEqual({
field: 'field_1',
ignore_failure: true,
value: ['Some_Value'],
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export const DateIndexName: FunctionComponent = () => {
/>

<UseField
data-test-subj="dateRoundingField"
config={fieldsConfig.date_rounding}
component={SelectField}
componentProps={{
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 0e85c65

Please sign in to comment.