Skip to content

Commit e103c08

Browse files
committed
added few tests
1 parent 3b6a371 commit e103c08

File tree

5 files changed

+216
-10
lines changed

5 files changed

+216
-10
lines changed

x-pack/plugins/apm/public/components/app/RumDashboard/VisitorBreakdownMap/EmbeddedMap.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import React, { useEffect, useState, useRef } from 'react';
88
import uuid from 'uuid';
99
import styled from 'styled-components';
1010

11-
import { createPortalNode, InPortal, OutPortal } from 'react-reverse-portal';
12-
1311
import {
1412
MapEmbeddable,
1513
MapEmbeddableInput,
@@ -60,6 +58,7 @@ export function EmbeddedMapComponent() {
6058
const [embeddable, setEmbeddable] = useState<
6159
MapEmbeddable | ErrorEmbeddable | undefined
6260
>();
61+
6362
const embeddableRoot: React.RefObject<HTMLDivElement> = useRef<
6463
HTMLDivElement
6564
>(null);
@@ -68,8 +67,6 @@ export function EmbeddedMapComponent() {
6867
services: { embeddable: embeddablePlugin },
6968
} = useKibana<KibanaDeps>();
7069

71-
const portalNode = React.useMemo(() => createPortalNode(), []);
72-
7370
if (!embeddablePlugin) {
7471
throw new Error('Embeddable start plugin not found');
7572
}
@@ -116,7 +113,7 @@ export function EmbeddedMapComponent() {
116113
loadFeatureGeometry,
117114
};
118115

119-
return <OutPortal {...props} node={portalNode} features={features} />;
116+
return <MapToolTip {...props} features={features} />;
120117
}
121118

122119
useEffect(() => {
@@ -172,13 +169,10 @@ export function EmbeddedMapComponent() {
172169
return (
173170
<EmbeddedPanel>
174171
<div
175-
data-test-subj="xpack.uptime.locationMap.embeddedPanel"
172+
data-test-subj="xpack.apm.regionMap.embeddedPanel"
176173
className="embPanel__content"
177174
ref={embeddableRoot}
178175
/>
179-
<InPortal node={portalNode}>
180-
<MapToolTip />
181-
</InPortal>
182176
</EmbeddedPanel>
183177
);
184178
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 { render } from 'enzyme';
8+
import React from 'react';
9+
10+
import { EmbeddedMap } from '../EmbeddedMap';
11+
import { KibanaContextProvider } from '../../../../../../../security_solution/public/common/lib/kibana';
12+
import { embeddablePluginMock } from '../../../../../../../../../src/plugins/embeddable/public/mocks';
13+
14+
describe('Embedded Map', () => {
15+
test('it renders', () => {
16+
const [core] = mockCore();
17+
18+
const wrapper = render(
19+
<KibanaContextProvider services={{ ...core }}>
20+
<EmbeddedMap />
21+
</KibanaContextProvider>
22+
);
23+
24+
expect(wrapper).toMatchSnapshot();
25+
});
26+
});
27+
28+
const mockEmbeddable = embeddablePluginMock.createStartContract();
29+
30+
mockEmbeddable.getEmbeddableFactory = jest.fn().mockImplementation(() => ({
31+
create: () => ({
32+
reload: jest.fn(),
33+
setRenderTooltipContent: jest.fn(),
34+
setLayerList: jest.fn(),
35+
}),
36+
}));
37+
38+
const mockCore: () => [any] = () => {
39+
const core = {
40+
embeddable: mockEmbeddable,
41+
};
42+
43+
return [core];
44+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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 { mockLayerList } from './__mocks__/regions_layer.mock';
8+
import { getLayerList } from '../LayerList';
9+
10+
describe('LayerList', () => {
11+
describe('getLayerList', () => {
12+
test('it returns the region layer', () => {
13+
const layerList = getLayerList();
14+
expect(layerList).toStrictEqual(mockLayerList);
15+
});
16+
});
17+
});
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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+
export const mockLayerList = [
8+
{
9+
sourceDescriptor: { type: 'EMS_TMS', isAutoSelect: true },
10+
id: 'b7af286d-2580-4f47-be93-9653d594ce7e',
11+
label: null,
12+
minZoom: 0,
13+
maxZoom: 24,
14+
alpha: 1,
15+
visible: true,
16+
style: { type: 'TILE' },
17+
type: 'VECTOR_TILE',
18+
},
19+
{
20+
joins: [
21+
{
22+
leftField: 'iso2',
23+
right: {
24+
type: 'ES_TERM_SOURCE',
25+
id: '3657625d-17b0-41ef-99ba-3a2b2938655c',
26+
indexPatternTitle: 'apm-*',
27+
term: 'client.geo.country_iso_code',
28+
metrics: [
29+
{
30+
type: 'avg',
31+
field: 'transaction.duration.us',
32+
label: 'Page load duration',
33+
},
34+
],
35+
indexPatternId: 'apm_static_index_pattern_id',
36+
applyGlobalQuery: true,
37+
},
38+
},
39+
],
40+
sourceDescriptor: {
41+
type: 'EMS_FILE',
42+
id: 'world_countries',
43+
tooltipProperties: ['name'],
44+
applyGlobalQuery: true,
45+
},
46+
style: {
47+
type: 'VECTOR',
48+
properties: {
49+
icon: { type: 'STATIC', options: { value: 'marker' } },
50+
fillColor: {
51+
type: 'DYNAMIC',
52+
options: {
53+
color: 'Blue to Red',
54+
colorCategory: 'palette_0',
55+
fieldMetaOptions: { isEnabled: true, sigma: 3 },
56+
type: 'ORDINAL',
57+
field: {
58+
name:
59+
'__kbnjoin__avg_of_transaction.duration.us__3657625d-17b0-41ef-99ba-3a2b2938655c',
60+
origin: 'join',
61+
},
62+
useCustomColorRamp: false,
63+
},
64+
},
65+
lineColor: {
66+
type: 'DYNAMIC',
67+
options: { color: '#3d3d3d', fieldMetaOptions: { isEnabled: true } },
68+
},
69+
lineWidth: { type: 'STATIC', options: { size: 1 } },
70+
iconSize: { type: 'STATIC', options: { size: 6 } },
71+
iconOrientation: { type: 'STATIC', options: { orientation: 0 } },
72+
labelText: { type: 'STATIC', options: { value: '' } },
73+
labelColor: { type: 'STATIC', options: { color: '#000000' } },
74+
labelSize: { type: 'STATIC', options: { size: 14 } },
75+
labelBorderColor: { type: 'STATIC', options: { color: '#FFFFFF' } },
76+
symbolizeAs: { options: { value: 'circle' } },
77+
labelBorderSize: { options: { size: 'SMALL' } },
78+
},
79+
isTimeAware: true,
80+
},
81+
id: 'e8d1d974-eed8-462f-be2c-f0004b7619b2',
82+
label: null,
83+
minZoom: 0,
84+
maxZoom: 24,
85+
alpha: 0.75,
86+
visible: true,
87+
type: 'VECTOR',
88+
},
89+
{
90+
joins: [
91+
{
92+
leftField: 'region_iso_code',
93+
right: {
94+
type: 'ES_TERM_SOURCE',
95+
id: 'e62a1b9c-d7ff-4fd4-a0f6-0fdc44bb9e41',
96+
indexPatternTitle: 'apm-*',
97+
term: 'client.geo.region_iso_code',
98+
metrics: [{ type: 'avg', field: 'transaction.duration.us' }],
99+
indexPatternId: 'apm_static_index_pattern_id',
100+
},
101+
},
102+
],
103+
sourceDescriptor: {
104+
type: 'EMS_FILE',
105+
id: 'administrative_regions_lvl2',
106+
tooltipProperties: ['region_iso_code', 'region_name'],
107+
},
108+
style: {
109+
type: 'VECTOR',
110+
properties: {
111+
icon: { type: 'STATIC', options: { value: 'marker' } },
112+
fillColor: {
113+
type: 'DYNAMIC',
114+
options: {
115+
color: 'Blue to Red',
116+
colorCategory: 'palette_0',
117+
fieldMetaOptions: { isEnabled: true, sigma: 3 },
118+
type: 'ORDINAL',
119+
field: {
120+
name:
121+
'__kbnjoin__avg_of_transaction.duration.us__e62a1b9c-d7ff-4fd4-a0f6-0fdc44bb9e41',
122+
origin: 'join',
123+
},
124+
useCustomColorRamp: false,
125+
},
126+
},
127+
lineColor: {
128+
type: 'DYNAMIC',
129+
options: { color: '#3d3d3d', fieldMetaOptions: { isEnabled: true } },
130+
},
131+
lineWidth: { type: 'STATIC', options: { size: 1 } },
132+
iconSize: { type: 'STATIC', options: { size: 6 } },
133+
iconOrientation: { type: 'STATIC', options: { orientation: 0 } },
134+
labelText: { type: 'STATIC', options: { value: '' } },
135+
labelColor: { type: 'STATIC', options: { color: '#000000' } },
136+
labelSize: { type: 'STATIC', options: { size: 14 } },
137+
labelBorderColor: { type: 'STATIC', options: { color: '#FFFFFF' } },
138+
symbolizeAs: { options: { value: 'circle' } },
139+
labelBorderSize: { options: { size: 'SMALL' } },
140+
},
141+
isTimeAware: true,
142+
},
143+
id: '0e936d41-8765-41c9-97f0-05e166391366',
144+
label: null,
145+
minZoom: 3,
146+
maxZoom: 24,
147+
alpha: 0.75,
148+
visible: true,
149+
type: 'VECTOR',
150+
},
151+
];

x-pack/plugins/apm/public/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export class ApmPlugin implements Plugin<ApmPluginSetup, ApmPluginStart> {
139139
pluginSetupDeps,
140140
params,
141141
config,
142-
corePlugins
142+
corePlugins as ApmPluginStartDeps
143143
);
144144
},
145145
});

0 commit comments

Comments
 (0)