Skip to content

Commit 0031caf

Browse files
kibanamachineJohn Dorlus
andauthored
CIT for circle processor (renewed PR) (#102277) (#102375)
* Added CITs for Circle processor. * Fixed issue with form function using int instead of string. * Added changed per nits. Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: John Dorlus <silne.dorlus@elastic.co>
1 parent 8d34ba7 commit 0031caf

3 files changed

Lines changed: 118 additions & 0 deletions

File tree

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import { act } from 'react-dom/test-utils';
9+
import { setup, SetupResult, getProcessorValue } from './processor.helpers';
10+
11+
const CIRCLE_TYPE = 'circle';
12+
13+
describe('Processor: Circle', () => {
14+
let onUpdate: jest.Mock;
15+
let testBed: SetupResult;
16+
17+
beforeAll(() => {
18+
jest.useFakeTimers();
19+
});
20+
21+
afterAll(() => {
22+
jest.useRealTimers();
23+
});
24+
25+
beforeEach(async () => {
26+
onUpdate = jest.fn();
27+
28+
await act(async () => {
29+
testBed = await setup({
30+
value: {
31+
processors: [],
32+
},
33+
onFlyoutOpen: jest.fn(),
34+
onUpdate,
35+
});
36+
});
37+
testBed.component.update();
38+
const {
39+
actions: { addProcessor, addProcessorType },
40+
} = testBed;
41+
// Open the processor flyout
42+
addProcessor();
43+
44+
// Add type (the other fields are not visible until a type is selected)
45+
await addProcessorType(CIRCLE_TYPE);
46+
});
47+
48+
test('prevents form submission if required fields are not provided', async () => {
49+
const {
50+
actions: { saveNewProcessor },
51+
form,
52+
} = testBed;
53+
54+
// Click submit button with only the type defined
55+
await saveNewProcessor();
56+
57+
// Expect form error as "field" and "shape_type" are required parameters
58+
expect(form.getErrorsMessages()).toEqual([
59+
'A field value is required.',
60+
'A shape type value is required.',
61+
]);
62+
});
63+
64+
test('saves with required parameter values', async () => {
65+
const {
66+
actions: { saveNewProcessor },
67+
form,
68+
} = testBed;
69+
70+
// Add "field" value (required)
71+
form.setInputValue('fieldNameField.input', 'field_1');
72+
// Save the field
73+
form.setSelectValue('shapeSelectorField', 'shape');
74+
// Set the error distance
75+
form.setInputValue('errorDistanceField.input', '10');
76+
77+
await saveNewProcessor();
78+
79+
const processors = getProcessorValue(onUpdate, CIRCLE_TYPE);
80+
81+
expect(processors[0].circle).toEqual({
82+
field: 'field_1',
83+
error_distance: 10,
84+
shape_type: 'shape',
85+
});
86+
});
87+
88+
test('allows optional parameters to be set', async () => {
89+
const {
90+
actions: { saveNewProcessor },
91+
form,
92+
} = testBed;
93+
94+
// Add "field" value (required)
95+
form.setInputValue('fieldNameField.input', 'field_1');
96+
// Select the shape
97+
form.setSelectValue('shapeSelectorField', 'geo_shape');
98+
// Add "target_field" value
99+
form.setInputValue('targetField.input', 'target_field');
100+
101+
form.setInputValue('errorDistanceField.input', '10');
102+
103+
// Save the field with new changes
104+
await saveNewProcessor();
105+
106+
const processors = getProcessorValue(onUpdate, CIRCLE_TYPE);
107+
expect(processors[0].circle).toEqual({
108+
field: 'field_1',
109+
error_distance: 10,
110+
shape_type: 'geo_shape',
111+
target_field: 'target_field',
112+
});
113+
});
114+
});

x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/processor.helpers.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ type TestSubject =
151151
| 'keepOriginalField.input'
152152
| 'removeIfSuccessfulField.input'
153153
| 'targetFieldsField.input'
154+
| 'shapeSelectorField'
155+
| 'errorDistanceField.input'
154156
| 'separatorValueField.input'
155157
| 'quoteValueField.input'
156158
| 'emptyValueField.input'

x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/circle.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export const Circle: FunctionComponent = () => {
9797
/>
9898

9999
<UseField
100+
data-test-subj="errorDistanceField"
100101
config={fieldsConfig.error_distance}
101102
component={NumericField}
102103
path="fields.error_distance"
@@ -105,6 +106,7 @@ export const Circle: FunctionComponent = () => {
105106
<UseField
106107
componentProps={{
107108
euiFieldProps: {
109+
'data-test-subj': 'shapeSelectorField',
108110
options: [
109111
{
110112
value: 'shape',

0 commit comments

Comments
 (0)