Skip to content

Commit 59ff8e9

Browse files
XavierMangoraycelasticmachine
committed
[SECURITY SOLUTIONS] Map embeddable working with index patterns selection (elastic#78610)
* map working with sourcerer * clean up * fix types * fix unit tests * fix incorrect hight for map * show prompt when no index exists * update unit test * fix update with no index available * fixup * unit test * add unit test Co-authored-by: Angela Chuang <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
1 parent 6490428 commit 59ff8e9

File tree

5 files changed

+289
-75
lines changed

5 files changed

+289
-75
lines changed

x-pack/plugins/security_solution/public/network/components/embeddables/__snapshots__/embedded_map.test.tsx.snap

+12-30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugins/security_solution/public/network/components/embeddables/embedded_map.test.tsx

+144-11
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,169 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { shallow } from 'enzyme';
7+
import { mount, ReactWrapper, shallow } from 'enzyme';
88
import React from 'react';
9+
import * as redux from 'react-redux';
10+
import { act } from 'react-dom/test-utils';
911

1012
import '../../../common/mock/match_media';
1113
import { useIndexPatterns } from '../../../common/hooks/use_index_patterns';
14+
import { TestProviders } from '../../../common/mock';
15+
1216
import { EmbeddedMapComponent } from './embedded_map';
17+
import { createEmbeddable } from './embedded_map_helpers';
1318

1419
const mockUseIndexPatterns = useIndexPatterns as jest.Mock;
1520
jest.mock('../../../common/hooks/use_index_patterns');
1621
mockUseIndexPatterns.mockImplementation(() => [true, []]);
1722

1823
jest.mock('../../../common/lib/kibana');
24+
jest.mock('./embedded_map_helpers', () => ({
25+
createEmbeddable: jest.fn(),
26+
}));
27+
jest.mock('../../../common/lib/kibana', () => {
28+
return {
29+
useKibana: jest.fn().mockReturnValue({
30+
services: {
31+
embeddable: {
32+
EmbeddablePanel: jest.fn(() => <div data-test-subj="EmbeddablePanel" />),
33+
},
34+
docLinks: { ELASTIC_WEBSITE_URL: 'ELASTIC_WEBSITE_URL' },
35+
},
36+
}),
37+
};
38+
});
39+
40+
jest.mock('./index_patterns_missing_prompt', () => {
41+
return {
42+
IndexPatternsMissingPrompt: jest.fn(() => <div data-test-subj="IndexPatternsMissingPrompt" />),
43+
};
44+
});
1945

2046
describe('EmbeddedMapComponent', () => {
21-
let setQuery: jest.Mock;
47+
const setQuery: jest.Mock = jest.fn();
48+
const mockSelector = {
49+
kibanaIndexPatterns: [
50+
{ id: '6f1eeb50-023d-11eb-bcb6-6ba0578012a9', title: 'filebeat-*' },
51+
{ id: '28995490-023d-11eb-bcb6-6ba0578012a9', title: 'auditbeat-*' },
52+
],
53+
sourcererScope: { selectedPatterns: ['filebeat-*', 'packetbeat-*'] },
54+
};
55+
const mockCreateEmbeddable = {
56+
destroyed: false,
57+
enhancements: { dynamicActions: {} },
58+
getActionContext: jest.fn(),
59+
getFilterActions: jest.fn(),
60+
id: '70969ddc-4d01-4048-8073-4ea63d595638',
61+
input: {
62+
viewMode: 'view',
63+
title: 'Source -> Destination Point-to-Point Map',
64+
id: '70969ddc-4d01-4048-8073-4ea63d595638',
65+
filters: Array(0),
66+
hidePanelTitles: true,
67+
},
68+
input$: {},
69+
isContainer: false,
70+
output: {},
71+
output$: {},
72+
parent: undefined,
73+
parentSubscription: undefined,
74+
renderComplete: {},
75+
runtimeId: 1,
76+
reload: jest.fn(),
77+
setLayerList: jest.fn(),
78+
setEventHandlers: jest.fn(),
79+
setRenderTooltipContent: jest.fn(),
80+
type: 'map',
81+
updateInput: jest.fn(),
82+
};
83+
const testProps = {
84+
endDate: '2019-08-28T05:50:57.877Z',
85+
filters: [],
86+
query: { query: '', language: 'kuery' },
87+
setQuery,
88+
startDate: '2019-08-28T05:50:47.877Z',
89+
};
2290

2391
beforeEach(() => {
24-
setQuery = jest.fn();
92+
setQuery.mockClear();
2593
});
2694

2795
test('renders correctly against snapshot', () => {
2896
const wrapper = shallow(
29-
<EmbeddedMapComponent
30-
endDate="2019-08-28T05:50:57.877Z"
31-
filters={[]}
32-
query={{ query: '', language: 'kuery' }}
33-
setQuery={setQuery}
34-
startDate="2019-08-28T05:50:47.877Z"
35-
/>
97+
<TestProviders>
98+
<EmbeddedMapComponent {...testProps} />
99+
</TestProviders>
36100
);
37-
expect(wrapper).toMatchSnapshot();
101+
expect(wrapper.find('EmbeddedMapComponent')).toMatchSnapshot();
102+
});
103+
104+
test('renders services.embeddable.EmbeddablePanel', async () => {
105+
const spy = jest.spyOn(redux, 'useSelector');
106+
spy.mockReturnValue(mockSelector);
107+
108+
(createEmbeddable as jest.Mock).mockResolvedValue(mockCreateEmbeddable);
109+
110+
let wrapper: ReactWrapper;
111+
await act(async () => {
112+
wrapper = mount(
113+
<TestProviders>
114+
<EmbeddedMapComponent {...testProps} />
115+
</TestProviders>
116+
);
117+
});
118+
119+
wrapper!.update();
120+
121+
expect(wrapper!.find('[data-test-subj="EmbeddablePanel"]').exists()).toEqual(true);
122+
expect(wrapper!.find('[data-test-subj="IndexPatternsMissingPrompt"]').exists()).toEqual(false);
123+
expect(wrapper!.find('[data-test-subj="loading-panel"]').exists()).toEqual(false);
124+
});
125+
126+
test('renders IndexPatternsMissingPrompt', async () => {
127+
const spy = jest.spyOn(redux, 'useSelector');
128+
spy.mockReturnValue({
129+
...mockSelector,
130+
kibanaIndexPatterns: [],
131+
});
132+
133+
(createEmbeddable as jest.Mock).mockResolvedValue(mockCreateEmbeddable);
134+
135+
let wrapper: ReactWrapper;
136+
await act(async () => {
137+
wrapper = mount(
138+
<TestProviders>
139+
<EmbeddedMapComponent {...testProps} />
140+
</TestProviders>
141+
);
142+
});
143+
144+
wrapper!.update();
145+
146+
expect(wrapper!.find('[data-test-subj="EmbeddablePanel"]').exists()).toEqual(false);
147+
expect(wrapper!.find('[data-test-subj="IndexPatternsMissingPrompt"]').exists()).toEqual(true);
148+
expect(wrapper!.find('[data-test-subj="loading-panel"]').exists()).toEqual(false);
149+
});
150+
151+
test('renders Loader', async () => {
152+
const spy = jest.spyOn(redux, 'useSelector');
153+
spy.mockReturnValue(mockSelector);
154+
155+
(createEmbeddable as jest.Mock).mockResolvedValue(null);
156+
157+
let wrapper: ReactWrapper;
158+
await act(async () => {
159+
wrapper = mount(
160+
<TestProviders>
161+
<EmbeddedMapComponent {...testProps} />
162+
</TestProviders>
163+
);
164+
});
165+
166+
wrapper!.update();
167+
168+
expect(wrapper!.find('[data-test-subj="EmbeddablePanel"]').exists()).toEqual(false);
169+
expect(wrapper!.find('[data-test-subj="IndexPatternsMissingPrompt"]').exists()).toEqual(false);
170+
expect(wrapper!.find('[data-test-subj="loading-panel"]').exists()).toEqual(true);
38171
});
39172
});

0 commit comments

Comments
 (0)