Skip to content

Commit 6fa76dd

Browse files
committed
【UT】add UT
1 parent f0e2836 commit 6fa76dd

File tree

2 files changed

+153
-53
lines changed

2 files changed

+153
-53
lines changed

test/openlayers/mapping/WebMap2Spec.js

Lines changed: 151 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,98 @@ describe('openlayers_WebMap', () => {
2525
const originalNavigator = window.navigator;
2626
var id = 1788054202;
2727
let cookieValue;
28+
const datsets = [
29+
{
30+
name: 'test',
31+
type: 'POINT'
32+
}
33+
];
34+
const result1 = {
35+
fileId: 'test',
36+
datasetName: 'test',
37+
dataItemServices: [
38+
{
39+
serviceType: 'RESTMAP',
40+
accessCount: 0,
41+
address: 'http://fack:8090/iserver/services/map_sichuan-7-/rest',
42+
dataID: 1386367586,
43+
createTime: null,
44+
serviceStatus: 'PUBLISHED',
45+
editable: false,
46+
updateTime: null,
47+
serviceNode: '2e7t6p3r',
48+
serviceID: 'map_sichuan-7-',
49+
serviceName: 'map_sichuan-7-'
50+
},
51+
{
52+
serviceType: 'RESTDATA',
53+
accessCount: 0,
54+
address: 'http://fack:8090/iserver/services/data_sichuan-7-/rest',
55+
dataID: 1386367586,
56+
createTime: null,
57+
serviceStatus: 'PUBLISHED',
58+
editable: true,
59+
updateTime: null,
60+
serviceNode: '2e7t6p3r',
61+
serviceID: 'data_sichuan-7-',
62+
serviceName: 'data_sichuan-7-'
63+
}
64+
]
65+
};
66+
const mapsInfo = [
67+
{
68+
resourceConfigID: 'map',
69+
supportedMediaTypes: ['application/json'],
70+
path: 'http://fack:8090/iserver/services/map_sichuan-7-/rest/maps/test',
71+
name: 'test',
72+
resourceType: 'StaticResource'
73+
}
74+
];
75+
const mapInfo = {
76+
prjCoordSys: {
77+
distanceUnit: 'METER',
78+
epsgCode: 4326,
79+
coordUnit: 'DEGREE',
80+
type: 'PCS_EARTH_LONGITUDE_LATITUDE'
81+
},
82+
visibleScales: [],
83+
dpi: 96,
84+
scale: 5.080888406217531e-7,
85+
maxScale: 1.000000000000032e12,
86+
center: {
87+
x: 116.84538255155,
88+
y: 39.7881922283
89+
},
90+
bounds: {
91+
top: 42.31307532235788,
92+
left: 114.58902605452259,
93+
bottom: 37.76434929128856,
94+
leftBottom: {
95+
x: 114.58902605452259,
96+
y: 37.76434929128856
97+
},
98+
right: 119.51371730073062,
99+
rightTop: {
100+
x: 119.51371730073062,
101+
y: 42.31307532235788
102+
}
103+
},
104+
coordUnit: 'DEGREE'
105+
};
106+
const dataSourceInfo ={
107+
datasourceNames: ['supermap1_pg'],
108+
childUriList: [
109+
'http://fack:8090/iserver/services/data_sichuan-3-/rest/data/datasources/name/supermap1_pg'
110+
],
111+
datasourceCount: 1
112+
}
113+
const datasetsInfo = {
114+
datasetCount: 1,
115+
datasetNames: ['dataGeoJson_2529638'],
116+
childUriList: [
117+
'http://fack:8090/iserver/services/data_sichuan-3-/rest/data/datasources/supermap1_pg/datasets/dataGeoJson_2529638'
118+
]
119+
}
28120
beforeAll(() => {
29121
Object.defineProperty(document, 'cookie', {
30122
get() {
@@ -307,44 +399,6 @@ describe('openlayers_WebMap', () => {
307399
successCallback,
308400
errorCallback: function () {}
309401
};
310-
const datsets = [
311-
{
312-
name: 'test',
313-
type: 'POINT'
314-
}
315-
];
316-
const result1 = {
317-
fileId: 'test',
318-
datasetName: 'test',
319-
dataItemServices: [
320-
{
321-
serviceType: 'RESTMAP',
322-
accessCount: 0,
323-
address: 'http://fack:8090/iserver/services/map_sichuan-7-/rest',
324-
dataID: 1386367586,
325-
createTime: null,
326-
serviceStatus: 'PUBLISHED',
327-
editable: false,
328-
updateTime: null,
329-
serviceNode: '2e7t6p3r',
330-
serviceID: 'map_sichuan-7-',
331-
serviceName: 'map_sichuan-7-'
332-
},
333-
{
334-
serviceType: 'RESTDATA',
335-
accessCount: 0,
336-
address: 'http://fack:8090/iserver/services/data_sichuan-7-/rest',
337-
dataID: 1386367586,
338-
createTime: null,
339-
serviceStatus: 'PUBLISHED',
340-
editable: true,
341-
updateTime: null,
342-
serviceNode: '2e7t6p3r',
343-
serviceID: 'data_sichuan-7-',
344-
serviceName: 'data_sichuan-7-'
345-
}
346-
]
347-
};
348402
spyOn(FetchRequest, 'get').and.callFake((url) => {
349403
if (url.indexOf('map.json') > -1) {
350404
return Promise.resolve(new Response(accessTypeRestData));
@@ -358,26 +412,14 @@ describe('openlayers_WebMap', () => {
358412
if (url.indexOf('data_sichuan-7-/rest/data/datasources.json') > -1) {
359413
return Promise.resolve(
360414
new Response(
361-
JSON.stringify({
362-
datasourceNames: ['supermap1_pg'],
363-
childUriList: [
364-
'http://192.168.12.230:8090/iserver/services/data_sichuan-3-/rest/data/datasources/name/supermap1_pg'
365-
],
366-
datasourceCount: 1
367-
})
415+
JSON.stringify(dataSourceInfo)
368416
)
369417
);
370418
}
371419
if (url.indexOf('data_sichuan-7-/rest/data/datasources/supermap1_pg/datasets') > -1) {
372420
return Promise.resolve(
373421
new Response(
374-
JSON.stringify({
375-
datasetCount: 1,
376-
datasetNames: ['dataGeoJson_2529638'],
377-
childUriList: [
378-
'http://192.168.12.230:8090/iserver/services/data_sichuan-3-/rest/data/datasources/supermap1_pg/datasets/dataGeoJson_2529638'
379-
]
380-
})
422+
JSON.stringify(datasetsInfo)
381423
)
382424
);
383425
}
@@ -420,7 +462,63 @@ describe('openlayers_WebMap', () => {
420462
var datavizWebmap = new WebMap(id, options);
421463

422464
async function successCallback() {
423-
done();
465+
setTimeout(() => {
466+
expect(datavizWebmap.map.getLayers().getLength()).toBe(2);
467+
expect(datavizWebmap.layers[0].autoUpdateInterval).not.toBeNull();
468+
clearInterval(datavizWebmap.layers[0].autoUpdateInterval);
469+
done();
470+
}, 30);
471+
472+
}
473+
});
474+
it('webmap_relationRestMap', (done) => {
475+
let options = {
476+
server: server,
477+
successCallback,
478+
errorCallback: function () {}
479+
};
480+
481+
spyOn(FetchRequest, 'get').and.callFake((url) => {
482+
if (url.indexOf('map.json') > -1) {
483+
return Promise.resolve(new Response(accessTypeRestMap));
484+
}
485+
if (url.indexOf('675746998/datasets.json') > -1) {
486+
return Promise.resolve(new Response(JSON.stringify(datsets)));
487+
}
488+
if (url.indexOf('675746998.json') > -1) {
489+
return Promise.resolve(new Response(JSON.stringify(result1)));
490+
}
491+
if (url.indexOf('data_sichuan-7-/rest/data/datasources.json') > -1) {
492+
return Promise.resolve(
493+
new Response(
494+
JSON.stringify(dataSourceInfo)
495+
)
496+
);
497+
}
498+
if (url.indexOf('data_sichuan-7-/rest/data/datasources/supermap1_pg/datasets') > -1) {
499+
return Promise.resolve(
500+
new Response(
501+
JSON.stringify(datasetsInfo)
502+
)
503+
);
504+
}
505+
if (url.indexOf('/map_sichuan-7-/rest/maps.json') > -1) {
506+
return Promise.resolve(new Response(JSON.stringify(mapsInfo)));
507+
}
508+
if (url.indexOf('/map_sichuan-7-/rest/maps/test.json') > -1) {
509+
return Promise.resolve(new Response(JSON.stringify(mapInfo)));
510+
}
511+
return Promise.resolve(new Response(JSON.stringify({})));
512+
});
513+
var datavizWebmap = new WebMap(id, options);
514+
515+
async function successCallback() {
516+
setTimeout(() => {
517+
expect(datavizWebmap.map.getLayers().getLength()).toBe(2);
518+
expect(datavizWebmap.layers[0].autoUpdateInterval).not.toBeNull();
519+
clearInterval(datavizWebmap.layers[0].autoUpdateInterval);
520+
done();
521+
}, 30);
424522
}
425523
});
426524
});

test/resources/WebMapV5.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)