forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphMapSpec.js
More file actions
115 lines (111 loc) · 4.49 KB
/
GraphMapSpec.js
File metadata and controls
115 lines (111 loc) · 4.49 KB
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
import { GraphMap } from '../../../src/mapboxgl/overlay/GraphMap';
import { FetchRequest } from '../../../src/common/util/FetchRequest';
import '../../resources/KnowledgeGraphService';
var knowledgegraphURL = `http://fake:8090/iserver/services/knowledgeGraph-test/restjsr/graph`;
var knowledgegraphmapURL = knowledgegraphURL + '/graphmaps/xxx图谱';
describe('GraphMap mapboxgl', () => {
var originalTimeout;
var dom;
beforeAll(() => {
dom = window.document.createElement('div');
dom.setAttribute('id', 'knowledgeGraph');
dom.style.width = '450px';
dom.style.height = '350px';
window.document.body.appendChild(dom);
});
afterAll(() => {
window.document.body.removeChild(dom);
});
beforeEach(() => {
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
});
afterEach(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
});
it('createGraphMap', (done) => {
spyOn(FetchRequest, 'get').and.callFake((testUrl) => {
if (testUrl.includes('/query.json')) {
return Promise.resolve(new Response(queryData));
}
if (testUrl === knowledgegraphURL + '/graphmaps/xxx图谱.json') {
expect(testUrl).toBe(knowledgegraphURL + '/graphmaps/xxx图谱.json');
return Promise.resolve(new Response(graphmapData));
}
});
var graphMap = new GraphMap(knowledgegraphmapURL, { config: { center: [0, 0] } });
graphMap.on('loaded', () => {
expect(graphMap).not.toBeNull();
done();
});
});
it('findShortestPath', (done) => {
spyOn(FetchRequest, 'get').and.callFake((testUrl) => {
if (testUrl.includes('/query.json')) {
return Promise.resolve(new Response(queryData));
}
if (testUrl === knowledgegraphURL + '/graphmaps/xxx图谱.json') {
expect(testUrl).toBe(knowledgegraphURL + '/graphmaps/xxx图谱.json');
return Promise.resolve(new Response(graphmapData));
}
if (testUrl.includes('/shortestPath.json')) {
expect(testUrl).toBe(knowledgegraphURL + '/shortestPath.json?startID=38756&endID=38757');
return Promise.resolve(new Response(findShortestPathData));
}
});
var graphMap = new GraphMap(knowledgegraphmapURL, { config: { center: [0, 0] } });
graphMap.on('loaded', () => {
try {
expect(graphMap).not.toBeNull();
spyOn(graphMap.graph, 'highlight');
spyOn(graphMap.graph, 'clearHighlight');
graphMap.findShortestPath({ startID: 38756, endID: 38757 }, (res) => {
expect(res).not.toBeNull();
expect(res.type).toBe('processCompleted');
expect(res.result).not.toBeNull();
expect(res.result.nodeIDs).toEqual([40229, 40237, 64058]);
expect(res.result.edgeIDs).toEqual([69575, 66619]);
graphMap.highlight({ nodeIDs: [40229], edgeIDs: [69575] });
expect(graphMap.graph.highlight).toHaveBeenCalled();
graphMap.clearHighlight({ nodeIDs: [40229], edgeIDs: [69575] });
expect(graphMap.graph.clearHighlight).toHaveBeenCalled();
done();
});
} catch (exception) {
console.log("'findShortestPath'案例失败:" + exception.name + ':' + exception.message);
expect(false).toBeTruthy();
done();
}
});
});
xit('no graph highlight clearHighlight', (done) => {
spyOn(FetchRequest, 'get').and.callFake((testUrl) => {
if (testUrl.includes('/query.json')) {
return Promise.resolve(new Response(queryData));
}
if (testUrl === knowledgegraphURL + '/graphmaps/xxx图谱.json') {
expect(testUrl).toBe(knowledgegraphURL + '/graphmaps/xxx图谱.json');
return Promise.resolve(new Response(graphmapData));
}
if (testUrl.includes('/shortestPath.json')) {
expect(testUrl).toBe(knowledgegraphURL + '/shortestPath.json?startID=38756&endID=38757');
return Promise.resolve(new Response(findShortestPathData));
}
});
var graphMap = new GraphMap(knowledgegraphmapURL, { config: { center: [0, 0] } });
graphMap.createGraphMap = () => {};
try {
expect(graphMap).not.toBeNull();
graphMap.graph = null;
const res = graphMap.highlight();
const res1 = graphMap.clearHighlight();
expect(res).toBeUndefined();
expect(res1).toBeUndefined();
done();
} catch (exception) {
console.log("'no graph highlight clearHighlight'案例失败:" + exception.name + ':' + exception.message);
expect(false).toBeTruthy();
done();
}
});
});