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

CIT for circle processor (renewed PR) #102277

Merged
merged 5 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all 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,114 @@
/*
* 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 CIRCLE_TYPE = 'circle';

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

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

// Add "field" value (required)
form.setInputValue('fieldNameField.input', 'field_1');
// Save the field
form.setSelectValue('shapeSelectorField', 'shape');
// Set the error distance
form.setInputValue('errorDistanceField.input', '10');

await saveNewProcessor();

const processors = getProcessorValue(onUpdate, CIRCLE_TYPE);

expect(processors[0].circle).toEqual({
field: 'field_1',
error_distance: 10,
shape_type: 'shape',
});
});

test('allows optional parameters to be set', async () => {
const {
actions: { saveNewProcessor },
form,
} = testBed;

// Add "field" value (required)
cuff-links marked this conversation as resolved.
Show resolved Hide resolved
form.setInputValue('fieldNameField.input', 'field_1');
// Select the shape
form.setSelectValue('shapeSelectorField', 'geo_shape');
// Add "target_field" value
form.setInputValue('targetField.input', 'target_field');

form.setInputValue('errorDistanceField.input', '10');

// Save the field with new changes
await saveNewProcessor();

const processors = getProcessorValue(onUpdate, CIRCLE_TYPE);
expect(processors[0].circle).toEqual({
field: 'field_1',
error_distance: 10,
shape_type: 'geo_shape',
target_field: 'target_field',
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ type TestSubject =
| 'keepOriginalField.input'
| 'removeIfSuccessfulField.input'
| 'targetFieldsField.input'
| 'shapeSelectorField'
| 'errorDistanceField.input'
| 'separatorValueField.input'
| 'quoteValueField.input'
| 'emptyValueField.input'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const Circle: FunctionComponent = () => {
/>

<UseField
data-test-subj="errorDistanceField"
config={fieldsConfig.error_distance}
component={NumericField}
path="fields.error_distance"
Expand All @@ -105,6 +106,7 @@ export const Circle: FunctionComponent = () => {
<UseField
componentProps={{
euiFieldProps: {
'data-test-subj': 'shapeSelectorField',
options: [
{
value: 'shape',
Expand Down