Skip to content

Commit 9eb8609

Browse files
committed
补充一些ut ,增加 Proj4Leaflet 测试
1 parent 884bd13 commit 9eb8609

File tree

7 files changed

+142
-9
lines changed

7 files changed

+142
-9
lines changed

test/karma.conf.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = function (config) {
2121
ignore: ["**/libs/**"],
2222
plugins: ['istanbul']
2323
}],
24-
[require('browserify-css'),{global: true}],
24+
[require('browserify-css'), {global: true}],
2525
require('browserify-imgify')
2626
]
2727
},
@@ -38,33 +38,47 @@ module.exports = function (config) {
3838
{pattern: '../src/classic/libs/Lang/*.js', include: false},
3939
{pattern: '../src/classic/theme/default/*.css', include: false},
4040
/**测试文件**/
41-
'./test-main-classic.js',
41+
// './test-main-classic.js',
4242

4343
/***common的源码***/
4444
'../src/common/**/*.js',
4545
/**测试文件**/
46-
'./test-main-common.js',
46+
// './test-main-common.js',
4747

4848
/***leaflet的源码***/
4949
{pattern: '../node_modules/leaflet/dist/leaflet.css', include: false},
5050
{pattern: '../src/leaflet/**/**/*.css', include: false},
5151
'../src/leaflet/**/!(ClientComputationView|index).js',
5252
/**测试文件**/
53-
'./test-main-leaflet.js',
53+
// './test-main-leaflet.js',
5454

5555
/***openlayers的源码***/
5656
{pattern: '../node_modules/openlayers/dist/ol-debug.css', include: false},
5757
{pattern: '../src/openlayers/**/**/*.css', include: false},
5858
'../src/openlayers/**/!(index).js',
5959
/**测试文件**/
60-
'./test-main-openlayers.js',
60+
// './test-main-openlayers.js',
6161

6262
/***mapboxgl***/
6363
{pattern: '../node_modules/mapbox-gl/dist/mapbox-gl.css', include: false},
6464
'../src/mapboxgl/**/!(index).js',
6565
/**测试文件**/
66-
'./test-main-mapboxgl.js'
66+
// './test-main-mapboxgl.js'
6767

68+
69+
'./mapboxgl/overlay/GraphicLayerSpec.js',
70+
'./mapboxgl/overlay/graphic/GraphicSpec.js',
71+
72+
'./leaflet/overlay/GraphicLayerSpec.js',
73+
'./leaflet/overlay/graphic/GraphicSpec.js',
74+
75+
'./openlayers/overlay/graphic/GraphicSpec.js',
76+
77+
'./mapboxgl/overlay/GraphicLayerSpec.js',
78+
'./mapboxgl/overlay/GraphThemeLayerSpec.js',
79+
'./openlayers/overlay/GraphicSpec.js',
80+
81+
'./leaflet/core/Proj4LeafletSpec.js',
6882
],
6983

7084
// list of files to exclude 测试时排除的文件

test/leaflet/core/Proj4LeafletSpec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import {crs} from '../../../src/leaflet/core/Proj4Leaflet';
2+
3+
4+
describe("leaflet_crs", () => {
5+
const options = {
6+
origin: [-180, 90],
7+
scaleDenominators: [2000, 1000, 500, 200, 100, 50, 20, 10],
8+
dpi: 80
9+
};
10+
let src4328;
11+
12+
beforeAll(() => {
13+
src4328 = crs("EPSG:4326", options);
14+
});
15+
16+
it("initialize", () => {
17+
expect(src4328).not.toBeNull();
18+
expect(src4328.options.dpi).toEqual(80);
19+
});
20+
it("initialize", () => {
21+
expect(src4328).not.toBeNull();
22+
expect(src4328.options.dpi).toEqual(80);
23+
});
24+
it("scale", () => {
25+
const scale = src4328.scale(2);
26+
expect(scale.toFixed(4)).toBe('701225.1389');
27+
});
28+
it("zoom", () => {
29+
const zoom = src4328.zoom(700000);
30+
expect(zoom.toFixed(4)).toBe('1.9965');
31+
});
32+
});

test/leaflet/overlay/GraphicLayerSpec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,12 @@ describe('leaflet_GraphicLayer', () => {
149149
}, 1000);
150150
});
151151

152-
it("getState", (done) => {
152+
it("getState,getRenderer", (done) => {
153153
layer = graphicLayer(graphics).addTo(map);
154154
setTimeout(() => {
155155
const state = layer.getState();
156156
expect(state).not.toBeNull();
157+
expect(layer.getRenderer()).not.toBeNull();
157158
expect(state.color).toBe("#3388ff");
158159
done();
159160
}, 1000);

test/leaflet/overlay/graphic/GraphicSpec.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,25 @@ describe('leaflet_Graphic', () => {
3131
expect(graphic.getAttributes().type).toBe("point");
3232
graphic = null;
3333
});
34-
it("getCanvas", () => {
34+
it("setCanvas, getCanvas", () => {
3535
graphic = graphicObj(option);
3636
expect(graphic.getCanvas()).toBeUndefined();
37+
graphic.setCanvas("canvas");
38+
expect(graphic.getCanvas()).toBe("canvas");
39+
graphic = null;
40+
});
41+
it("setLatLng, getLatLng", () => {
42+
graphic = graphicObj(option);
43+
graphic.setLatLng(L.latLng(0, 0));
44+
expect(graphic.getLatLng().lat).toEqual(0);
45+
expect(graphic.getLatLng().lng).toEqual(0);
46+
graphic = null;
47+
});
48+
it("setStyle, getStyle", () => {
49+
graphic = graphicObj(option);
50+
expect(graphic.getStyle()).toBeUndefined();
51+
graphic.setStyle("Style");
52+
expect(graphic.getStyle()).toBe("Style");
3753
graphic = null;
3854
});
3955
});

test/mapboxgl/overlay/GraphThemeLayerSpec.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,55 @@ describe('mapboxgl_GraphThemeLayer', () => {
290290
expect(graphThemeLayer.cache).toEqual(Object({}));
291291
graphThemeLayer.clear();
292292
});
293+
294+
it('setVisibility', () => {
295+
var graphThemeLayer = new Graph("GraphThemeLayer", "Bar", {
296+
map: map,
297+
isOverLay: false,
298+
themeFields: ["CON2009", "CON2010", "CON2011", "CON2012", "CON2013"],
299+
chartsSetting: {
300+
width: 240,
301+
height: 100,
302+
codomain: [0, 40000]
303+
},
304+
charts: [1, 2, 3],
305+
cache: {'name': 'ONETWO'}
306+
});
307+
expect(graphThemeLayer.visibility).toBeTruthy();
308+
graphThemeLayer.setVisibility(false);
309+
expect(graphThemeLayer.visibility).toBeFalsy();
310+
});
311+
xit('moveTo', () => {
312+
const graphThemeLayer = new Graph("GraphThemeLayer", "Bar", {
313+
map: map,
314+
isOverLay: false,
315+
themeFields: ["CON2009", "CON2010", "CON2011", "CON2012", "CON2013"],
316+
chartsSetting: {
317+
width: 240,
318+
height: 100,
319+
codomain: [0, 40000]
320+
},
321+
charts: [1, 2, 3],
322+
cache: {'name': 'ONETWO'}
323+
});
324+
map.addLayer(graphThemeLayer);
325+
const graphThemeLayer2 = new Graph("GraphThemeLayer2", "Bar", {
326+
map: map,
327+
isOverLay: false,
328+
themeFields: ["CON2009", "CON2010", "CON2011", "CON2012", "CON2013"],
329+
chartsSetting: {
330+
width: 240,
331+
height: 100,
332+
codomain: [0, 40000]
333+
},
334+
charts: [1, 2, 3],
335+
cache: {'name': 'ONETWO'}
336+
});
337+
map.addLayer(graphThemeLayer2);
338+
const zIndex = graphThemeLayer.div.style.zIndex;
339+
const zIndex2 = graphThemeLayer2.div.style.zIndex;
340+
expect(zIndex2).toBeGreaterThan(zIndex);
341+
graphThemeLayer.moveTo("graphThemeLayer2");
342+
expect(zIndex).toBeGreaterThan(zIndex2);
343+
});
293344
});

test/mapboxgl/overlay/graphic/GraphicSpec.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {Graphic} from '../../../../src/mapboxgl/overlay/graphic/Graphic';
22

33
describe('mapboxgl_Graphic', () => {
44
//todo
5-
var graphic, lngLat= {
5+
var graphic, lngLat = {
66
lng: -35.16,
77
lat: 38.05
88
};
@@ -32,4 +32,22 @@ describe('mapboxgl_Graphic', () => {
3232
expect(graphic.getAttributes().type).toBe("point");
3333
graphic = null;
3434
});
35+
it("setLngLat add getLngLat", () => {
36+
graphic = new Graphic(lngLat);
37+
expect(graphic.getLngLat().lng).toEqual(-35.16);
38+
expect(graphic.getLngLat().lat).toEqual(38.05);
39+
graphic.setLngLat({
40+
lng: 0,
41+
lat: 0
42+
});
43+
expect(graphic.getLngLat().lng).toEqual(0);
44+
expect(graphic.getLngLat().lat).toEqual(0);
45+
graphic = null;
46+
});
47+
it("setStyle add getStyle", () => {
48+
graphic = new Graphic(lngLat);
49+
graphic.setStyle({color: "red"});
50+
expect(graphic.getStyle().color).toBe("red");
51+
graphic = null;
52+
});
3553
});

test/test-main-leaflet.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import './leaflet/control/ChangeTileVersionSpec.js';
44
/*leaflet -- core*/
55
import './leaflet/core/NonEarthCRSSpec.js';
66
import './leaflet/core/TransformUtilSpec.js';
7+
import './leaflet/core/Proj4LeafletSpec.js';
78

89
/*leaflet -- mapping*/
910
import './leaflet/mapping/ImageMapLayerSpec.js';

0 commit comments

Comments
 (0)