forked from kiali/kiali
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CytoscapeGraph.test.tsx
122 lines (109 loc) · 3.94 KB
/
CytoscapeGraph.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import * as React from 'react';
import { shallow } from 'enzyme';
import { CytoscapeGraph } from '../CytoscapeGraph';
import * as GRAPH_DATA from '../../../services/__mockData__/getGraphElements';
import { DefaultTrafficRates, EdgeLabelMode, EdgeMode, GraphType, Layout } from '../../../types/Graph';
import { EmptyGraphLayout } from '../EmptyGraphLayout';
import { decorateGraphData } from '../../../store/Selectors/GraphData';
import { GraphDataSource } from '../../../services/GraphDataSource';
import { toSafeCyFieldName } from '../CytoscapeGraphUtils';
import { Theme } from 'types/Common';
jest.mock('../../../services/Api');
const testNamespace = 'ISTIO_SYSTEM';
const testClickHandler = (): void => {
console.log('click');
};
const testReadyHandler = (): void => {
console.log('ready');
};
const testSetHandler = (): void => {
console.log('set');
};
describe('CytoscapeGraph component test', () => {
it('should set correct elements data', done => {
const myLayout: Layout = { name: 'breadthfirst' };
const nsLayout: Layout = { name: 'kiali-dagre' };
const myEdgeLabelMode: EdgeLabelMode[] = [];
const dataSource = new GraphDataSource();
dataSource.fetchGraphData({
duration: 60,
edgeLabels: myEdgeLabelMode,
graphType: GraphType.VERSIONED_APP,
includeHealth: false,
includeLabels: false,
injectServiceNodes: true,
namespaces: [{ name: testNamespace }],
queryTime: 0,
showIdleEdges: false,
showIdleNodes: false,
showOperationNodes: false,
showSecurity: true,
showWaypoints: false,
trafficRates: DefaultTrafficRates
});
dataSource.on('fetchSuccess', () => {
const wrapper = shallow(
<CytoscapeGraph
edgeLabels={myEdgeLabelMode}
edgeMode={EdgeMode.ALL}
graphData={{
elements: dataSource.graphData,
elementsChanged: true,
isLoading: false,
fetchParams: {
duration: 60,
edgeLabels: myEdgeLabelMode,
graphType: GraphType.VERSIONED_APP,
includeHealth: false,
includeLabels: false,
injectServiceNodes: true,
namespaces: [{ name: testNamespace }],
queryTime: 0,
showIdleEdges: false,
showIdleNodes: false,
showOperationNodes: false,
showSecurity: true,
showWaypoints: false,
trafficRates: DefaultTrafficRates
},
timestamp: 0
}}
layout={myLayout}
namespaceLayout={nsLayout}
updateSummary={testClickHandler}
onReady={testReadyHandler}
onEmptyGraphAction={testClickHandler}
refreshInterval={0}
setActiveNamespaces={testSetHandler}
setNode={testSetHandler}
rankBy={[]}
showIdleEdges={false}
showIdleNodes={false}
showOutOfMesh={true}
showOperationNodes={false}
showRank={false}
showSecurity={true}
showServiceNodes={true}
showTrafficAnimation={false}
showVirtualServices={true}
summaryData={null}
toggleIdleNodes={() => undefined}
theme={Theme.LIGHT}
/>
);
const emptyGraphLayoutWrapper = wrapper.find(EmptyGraphLayout);
const emptyGraphDecorated = decorateGraphData(GRAPH_DATA[testNamespace].elements, 60);
expect(emptyGraphLayoutWrapper.prop('elements')!.nodes).toEqual(emptyGraphDecorated.nodes);
expect(emptyGraphLayoutWrapper.prop('elements')!.edges).toEqual(emptyGraphDecorated.edges);
done();
});
});
describe('utils test', () => {
it('should have working utils', done => {
expect(toSafeCyFieldName('foo')).toEqual('foo');
expect(toSafeCyFieldName('label_foo')).toEqual('label_foo');
expect(toSafeCyFieldName('label:kiali.io/foo')).toEqual('label_kiali_io_foo');
done();
});
});
});