Skip to content

Commit c839ccc

Browse files
committed
提交MapboxStyles单元测试 review by songym
1 parent fd57b2b commit c839ccc

File tree

5 files changed

+124
-2
lines changed

5 files changed

+124
-2
lines changed

test/libs/openlayers/plugins/ol-mapbox-style/2.11.2/olms.js

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import ol from 'openlayers';
2+
import * as oldebug from 'openlayers/dist/ol-debug';
3+
import '../../../libs/openlayers/plugins/ol-mapbox-style/2.11.2/olms';
4+
import { MapboxStyles } from '../../../../src/openlayers/overlay/vectortile/MapboxStyles';
5+
import { MapService } from '../../../../src/openlayers/services/MapService';
6+
import { VectorTileSuperMapRest } from '../../../../src/openlayers/overlay/VectorTileSuperMapRest';
7+
import { FetchRequest } from '../../../../src/common/util/FetchRequest';
8+
9+
ol.render.canvas = oldebug.render.canvas;
10+
ol.geom.flat = oldebug.geom.flat;
11+
12+
describe('openlayers_MapboxStyles', () => {
13+
var url = GlobeParameter.californiaURL
14+
var testDiv, map, mapboxStyles, originalTimeout;
15+
beforeAll(() => {
16+
testDiv = window.document.createElement("div");
17+
testDiv.setAttribute("id", "map");
18+
testDiv.style.styleFloat = "left";
19+
testDiv.style.marginLeft = "8px";
20+
testDiv.style.marginTop = "50px";
21+
testDiv.style.width = "500px";
22+
testDiv.style.height = "500px";
23+
window.document.body.appendChild(testDiv);
24+
25+
map = new ol.Map({
26+
target: 'map',
27+
view: new ol.View({
28+
center: [-122.228687503369, 38.1364932162598],
29+
zoom: 10,
30+
minZoom: 10,
31+
maxZoom: 14,
32+
projection: 'EPSG:4326',
33+
})
34+
});
35+
spyOn(FetchRequest, 'get').and.callFake((testUrl, params, options) => {
36+
expect(testUrl).toBe(url + "/tileFeature/vectorstyles.json?type=MapBox_GL&styleonly=true");
37+
return Promise.resolve(new Response(vectorstylesEscapedJson));
38+
});
39+
40+
});
41+
beforeEach(() => {
42+
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
43+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
44+
});
45+
afterEach(() => {
46+
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
47+
});
48+
afterAll(() => {
49+
window.document.body.removeChild(testDiv);
50+
});
51+
52+
it('getStyleFunction', (done) => {
53+
var stylesOptions = {
54+
url: url,
55+
map: map,
56+
source: 'California'
57+
};
58+
var style;
59+
mapboxStyles = new MapboxStyles(stylesOptions);
60+
setTimeout(() => {
61+
style = mapboxStyles.getStyleFunction();
62+
}, 8000);
63+
setTimeout(() => {
64+
expect(style).not.toBeNull();
65+
mapboxStyles = null;
66+
done();
67+
}, 1000);
68+
});
69+
70+
it('getStyleFunction,setSelectedId', (done) => {
71+
var stylesOptions = {
72+
url: url,
73+
map: map,
74+
source: 'California'
75+
};
76+
var style;
77+
mapboxStyles = new MapboxStyles(stylesOptions);
78+
setTimeout(() => {
79+
mapboxStyles.setSelectedId(1, 1);
80+
style = mapboxStyles.getStyleFunction();
81+
}, 8000);
82+
setTimeout(() => {
83+
expect(style).not.toBeNull();
84+
mapboxStyles = null;
85+
done();
86+
}, 1000);
87+
});
88+
89+
it('getStylesBySourceLayer', (done) => {
90+
var stylesOptions = {
91+
url: url,
92+
map: map,
93+
source: 'California'
94+
};
95+
var layer;
96+
mapboxStyles = new MapboxStyles(stylesOptions);
97+
setTimeout(() => {
98+
layer= mapboxStyles.getStylesBySourceLayer("Military_R@California");
99+
}, 8000);
100+
setTimeout(() => {
101+
expect(layer).not.toBeNull();
102+
mapboxStyles = null;
103+
done();
104+
}, 1000);
105+
106+
});
107+
})

test/resources/MapboxStyles.js

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

test/test-main-openlayers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import './openlayers/overlay/theme/GeoFeatureSpec.js';
2525
import './openlayers/overlay/theme/ThemeFeatureSpec.js';
2626
import './openlayers/overlay/theme/ThemeSpec.js';
2727
import './openlayers/overlay/vectortile/VectorTileStylesSpec.js';
28+
import './openlayers/overlay/vectortile/MapboxStylesSpec.js';
2829
import './openlayers/overlay/TurfSpec.js';
2930

3031
/**openlayers --services**/

test/tool/GlobeParameter.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@
2929
China4326URL: "http://localhost:8090/iserver/services/map-china400/rest/maps/China_4326",
3030
addressMatchURL_code: "http://localhost:8090/iserver/services/addressmatch-Address/restjsr/v1/address/geocoding",
3131
addressMatchURL_decode: "http://localhost:8090/iserver/services/addressmatch-Address/restjsr/v1/address/geodecoding",
32-
ChinaProvincesURL: "http://localhost:8090/iserver/services/map-ChinaProvinces/rest/maps/ChinaProvinces"
33-
}
32+
ChinaProvincesURL: "http://localhost:8090/iserver/services/map-ChinaProvinces/rest/maps/ChinaProvinces",
33+
californiaURL: "http://localhost:8090/iserver/services/map-mvt-California/rest/maps/California"
34+
}

0 commit comments

Comments
 (0)