Skip to content

Commit a50d115

Browse files
add component integration tests for processor items
1 parent a86dd6f commit a50d115

File tree

8 files changed

+388
-233
lines changed

8 files changed

+388
-233
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { Pipeline } from '../../../../../common/types';
8+
import { VerboseTestOutput, Document } from '../types';
9+
10+
export const PROCESSORS: Pick<Pipeline, 'processors'> = {
11+
processors: [
12+
{
13+
set: {
14+
field: 'field1',
15+
value: 'value1',
16+
},
17+
},
18+
],
19+
};
20+
21+
export const DOCUMENTS: Document[] = [
22+
{
23+
_index: 'index',
24+
_id: 'id1',
25+
_source: {
26+
name: 'foo',
27+
},
28+
},
29+
{
30+
_index: 'index',
31+
_id: 'id2',
32+
_source: {
33+
name: 'bar',
34+
},
35+
},
36+
];
37+
38+
export const SIMULATE_RESPONSE: VerboseTestOutput = {
39+
docs: [
40+
{
41+
processor_results: [
42+
{
43+
processor_type: 'set',
44+
status: 'success',
45+
tag: 'some_tag',
46+
doc: {
47+
_index: 'index',
48+
_id: 'id1',
49+
_source: {
50+
name: 'foo',
51+
foo: 'bar',
52+
},
53+
},
54+
},
55+
],
56+
},
57+
{
58+
processor_results: [
59+
{
60+
processor_type: 'set',
61+
status: 'success',
62+
tag: 'some_tag',
63+
doc: {
64+
_index: 'index',
65+
_id: 'id2',
66+
_source: {
67+
name: 'bar',
68+
foo: 'bar',
69+
},
70+
},
71+
},
72+
],
73+
},
74+
],
75+
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import axiosXhrAdapter from 'axios/lib/adapters/xhr';
1111
/* eslint-disable @kbn/eslint/no-restricted-paths */
1212
import { usageCollectionPluginMock } from 'src/plugins/usage_collection/public/mocks';
1313

14-
import { uiMetricService, apiService } from '../../../../../services';
14+
import { uiMetricService, apiService } from '../../../services';
1515

1616
type HttpResponse = Record<string, any> | any[];
1717

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,42 @@ import { notificationServiceMock, scopedHistoryMock } from 'src/core/public/mock
1010

1111
import { LocationDescriptorObject } from 'history';
1212
import { KibanaContextProvider } from 'src/plugins/kibana_react/public';
13-
import { registerTestBed, TestBed } from '../../../../../../../../../test_utils';
14-
import { stubWebWorker } from '../../../../../../../../../test_utils/stub_web_worker';
15-
import { ProcessorsEditorContextProvider, Props } from '../../../';
13+
import { registerTestBed, TestBed } from '../../../../../../../test_utils';
14+
import { stubWebWorker } from '../../../../../../../test_utils/stub_web_worker';
15+
import {
16+
ProcessorsEditorContextProvider,
17+
Props,
18+
GlobalOnFailureProcessorsEditor,
19+
ProcessorsEditor,
20+
} from '../';
1621
import { TestPipelineActions } from '../';
1722

1823
import {
1924
breadcrumbService,
2025
uiMetricService,
2126
documentationService,
2227
apiService,
23-
} from '../../../../../services';
28+
} from '../../../services';
2429

2530
stubWebWorker();
2631

32+
jest.mock('../../../../../../../../src/plugins/kibana_react/public', () => {
33+
const original = jest.requireActual('../../../../../../../../src/plugins/kibana_react/public');
34+
return {
35+
...original,
36+
// Mocking CodeEditor, which uses React Monaco under the hood
37+
CodeEditor: (props: any) => (
38+
<input
39+
data-test-subj={props['data-test-subj'] || 'mockCodeEditor'}
40+
data-currentvalue={props.value}
41+
onChange={(e: any) => {
42+
props.onChange(e.jsonContent);
43+
}}
44+
/>
45+
),
46+
};
47+
});
48+
2749
jest.mock('@elastic/eui', () => {
2850
const original = jest.requireActual('@elastic/eui');
2951
return {
@@ -40,6 +62,17 @@ jest.mock('@elastic/eui', () => {
4062
};
4163
});
4264

65+
jest.mock('react-virtualized', () => {
66+
const original = jest.requireActual('react-virtualized');
67+
68+
return {
69+
...original,
70+
AutoSizer: ({ children }: { children: any }) => (
71+
<div>{children({ height: 500, width: 500 })}</div>
72+
),
73+
};
74+
});
75+
4376
const history = scopedHistoryMock.create();
4477
history.createHref.mockImplementation((location: LocationDescriptorObject) => {
4578
return `${location.pathname}?${location.search}`;
@@ -52,13 +85,15 @@ const appServices = {
5285
api: apiService,
5386
notifications: notificationServiceMock.createSetupContract(),
5487
history,
88+
uiSettings: {},
5589
};
5690

5791
const testBedSetup = registerTestBed<TestSubject>(
5892
(props: Props) => (
5993
<KibanaContextProvider services={appServices}>
6094
<ProcessorsEditorContextProvider {...props}>
6195
<TestPipelineActions />
96+
<ProcessorsEditor /> <GlobalOnFailureProcessorsEditor />
6297
</ProcessorsEditorContextProvider>
6398
</KibanaContextProvider>
6499
),
@@ -96,6 +131,13 @@ const createActions = (testBed: TestBed<TestSubject>) => {
96131
component.update();
97132
},
98133

134+
clickProcessorOutputTab() {
135+
act(() => {
136+
find('outputTab').simulate('click');
137+
});
138+
component.update();
139+
},
140+
99141
async clickRefreshOutputButton() {
100142
await act(async () => {
101143
find('refreshOutputButton').simulate('click');
@@ -122,6 +164,13 @@ const createActions = (testBed: TestBed<TestSubject>) => {
122164
jsonString,
123165
});
124166
},
167+
168+
async clickProcessor(processorSelector: string) {
169+
await act(async () => {
170+
find(`${processorSelector}.manageItemButton`).simulate('click');
171+
});
172+
component.update();
173+
},
125174
};
126175
};
127176

@@ -147,4 +196,11 @@ type TestSubject =
147196
| 'viewOutputButton'
148197
| 'pipelineExecutionError'
149198
| 'euiFlyoutCloseButton'
150-
| 'documentsTab';
199+
| 'processorStatusIcon'
200+
| 'documentsTab'
201+
| 'manageItemButton'
202+
| 'processorSettingsForm'
203+
| 'configurationTab'
204+
| 'outputTab'
205+
| 'processorOutputTabContent'
206+
| string;

0 commit comments

Comments
 (0)