Skip to content

Commit 2d4d8de

Browse files
Leaflet测试代码升级ES6
1 parent ec2c60b commit 2d4d8de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2065
-1954
lines changed

test/karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = function (config) {
1818
transform: [
1919
[require('babelify'), {
2020
presets: ["env"],
21-
ignore: ["**/libs/**", "**/test/**"],
21+
ignore: ["**/libs/**"],
2222
plugins: ['istanbul']
2323
}],
2424
require('browserify-css'),
Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
require('../../../src/leaflet/control/ChangeTileVersion');
1+
import {changeTileVersion} from '../../../src/leaflet/control/ChangeTileVersion';
2+
import {tiledMapLayer} from '../../../src/leaflet/mapping/TiledMapLayer';
23

34
var url = GlobeParameter.ChinaProvincesURL;
4-
describe('leaflet_ChangeTileVersion', function () {
5+
describe('leaflet_ChangeTileVersion', () => {
56
var originalTimeout;
6-
var testDiv, map, changeTileVersion;
7-
beforeAll(function () {
7+
var testDiv, map, tileVersion;
8+
beforeAll(() => {
89
testDiv = document.createElement("div");
910
testDiv.setAttribute("id", "map");
1011
testDiv.style.styleFloat = "left";
@@ -18,91 +19,90 @@ describe('leaflet_ChangeTileVersion', function () {
1819
center: [33.03, 104.79],
1920
zoom: 3,
2021
});
21-
var baseLayer = L.supermap.tiledMapLayer(url).addTo(map);
22-
changeTileVersion = L.supermap.control.changeTileVersion({
22+
var baseLayer = tiledMapLayer(url).addTo(map);
23+
tileVersion = changeTileVersion({
2324
layer: baseLayer,
2425
position: "topleft",
2526
orientation: "horizontal"
2627
}).addTo(map);
2728
});
28-
beforeEach(function () {
29+
beforeEach(() => {
2930
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
3031
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
3132
});
32-
afterEach(function () {
33+
afterEach(() => {
3334
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
3435
});
35-
afterAll(function () {
36+
afterAll(() => {
3637
document.body.removeChild(testDiv);
3738
map.remove();
3839
});
3940

40-
it('initialize,', function () {
41-
expect(changeTileVersion).not.toBeNull();
42-
expect(changeTileVersion.options.layer).not.toBeNull();
43-
expect(changeTileVersion.slider).not.toBeNull();
44-
expect(changeTileVersion._sliderValue.innerHTML).toEqual("V");
45-
expect(changeTileVersion.tooltip.innerHTML).toEqual("V");
41+
it('initialize,', () => {
42+
expect(tileVersion).not.toBeNull();
43+
expect(tileVersion.options.layer).not.toBeNull();
44+
expect(tileVersion.slider).not.toBeNull();
45+
expect(tileVersion._sliderValue.innerHTML).toEqual("V");
46+
expect(tileVersion.tooltip.innerHTML).toEqual("V");
4647
});
4748

48-
it('setContent', function () {
49+
it('setContent', () => {
4950
var version = {
5051
desc: "1.1.0"
5152
};
52-
changeTileVersion.setContent(version);
53-
expect(changeTileVersion._sliderValue.innerHTML).toEqual("1.1.0");
54-
expect(changeTileVersion.tooltip.innerHTML).toEqual("1.1.0");
55-
changeTileVersion.setVersionName();
56-
expect(changeTileVersion._sliderValue.innerHTML).toEqual("0");
53+
tileVersion.setContent(version);
54+
expect(tileVersion._sliderValue.innerHTML).toEqual("1.1.0");
55+
expect(tileVersion.tooltip.innerHTML).toEqual("1.1.0");
56+
tileVersion.setVersionName();
57+
expect(tileVersion._sliderValue.innerHTML).toEqual("0");
5758
});
5859

59-
it('updateLength', function () {
60-
changeTileVersion.updateLength(1);
61-
expect(changeTileVersion.length).toEqual(1);
62-
expect(changeTileVersion.max).toEqual(0);
60+
it('updateLength', () => {
61+
tileVersion.updateLength(1);
62+
expect(tileVersion.length).toEqual(1);
63+
expect(tileVersion.max).toEqual(0);
6364
});
6465

65-
it('nextTilesVersion',function () {
66-
changeTileVersion.nextTilesVersion();
67-
expect(changeTileVersion.options.layer.tempIndex).toBe(0);
66+
it('nextTilesVersion', () => {
67+
tileVersion.nextTilesVersion();
68+
expect(tileVersion.options.layer.tempIndex).toBe(0);
6869
});
6970

70-
it('nextTilesVersion_firstLoad, lastTilesVersion', function () {
71-
changeTileVersion.firstLoad = false;
72-
changeTileVersion.nextTilesVersion();
73-
expect(changeTileVersion.options.layer.tempIndex).toBe(0);
74-
changeTileVersion.lastTilesVersion();
75-
expect(changeTileVersion.options.layer.tempIndex).toBe(0);
71+
it('nextTilesVersion_firstLoad, lastTilesVersion', () => {
72+
tileVersion.firstLoad = false;
73+
tileVersion.nextTilesVersion();
74+
expect(tileVersion.options.layer.tempIndex).toBe(0);
75+
tileVersion.lastTilesVersion();
76+
expect(tileVersion.options.layer.tempIndex).toBe(0);
7677
});
7778

78-
it('nextTilesVersion, lastTilesVersion',function () {
79-
changeTileVersion.updateLength(2);
80-
expect(changeTileVersion.length).toEqual(2);
81-
expect(changeTileVersion.max).toEqual(1);
82-
changeTileVersion.nextTilesVersion();
83-
expect(changeTileVersion.options.layer.tempIndex).toBe(0);
84-
changeTileVersion.lastTilesVersion();
85-
expect(changeTileVersion.options.layer.tempIndex).toBe(-2);
79+
it('nextTilesVersion, lastTilesVersion', () => {
80+
tileVersion.updateLength(2);
81+
expect(tileVersion.length).toEqual(2);
82+
expect(tileVersion.max).toEqual(1);
83+
tileVersion.nextTilesVersion();
84+
expect(tileVersion.options.layer.tempIndex).toBe(0);
85+
tileVersion.lastTilesVersion();
86+
expect(tileVersion.options.layer.tempIndex).toBe(-2);
8687
});
8788

88-
it('update',function () {
89-
changeTileVersion.update([
90-
{name:"0",desc: "1.1.0"},
91-
{name:"1",desc: "1.1.1"}
89+
it('update', () => {
90+
tileVersion.update([
91+
{name: "0", desc: "1.1.0"},
92+
{name: "1", desc: "1.1.1"}
9293
],);
93-
expect(changeTileVersion.tileVersions).not.toBeNull();
94-
expect(changeTileVersion.tileVersions.length).toEqual(2);
94+
expect(tileVersion.tileVersions).not.toBeNull();
95+
expect(tileVersion.tileVersions.length).toEqual(2);
9596
});
9697

97-
it('tilesVersion',function () {
98-
changeTileVersion.tilesVersion("0");
99-
var version = changeTileVersion.getVersion();
98+
it('tilesVersion', () => {
99+
tileVersion.tilesVersion("0");
100+
var version = tileVersion.getVersion();
100101
expect(version).toEqual("0");
101102
});
102103

103-
it('removeLayer',function () {
104-
changeTileVersion.removeLayer();
105-
expect(changeTileVersion.options.layer).toBeNull();
104+
it('removeLayer', () => {
105+
tileVersion.removeLayer();
106+
expect(tileVersion.options.layer).toBeNull();
106107
});
107-
108108
});
Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,70 @@
1-
require('../../../src/leaflet/core/NonEarthCRS');
1+
import {nonEarthCRS} from '../../../src/leaflet/core/NonEarthCRS';
2+
import {nonProjection} from '../../../src/leaflet/core/NonEarthCRS';
23

3-
describe('leaflet_NonEarthCRS', function () {
4-
it('initialize', function () {
4+
describe('leaflet_NonEarthCRS', () => {
5+
it('initialize', () => {
56
var bounds = L.bounds([-180, -90], [180, 90]);
6-
var nonProjection = L.Projection.NonProjection(bounds);
7-
expect(nonProjection).not.toBeNull();
8-
expect(nonProjection.bounds).not.toBeNull();
9-
expect(nonProjection.bounds.max.x).toEqual(180);
10-
expect(nonProjection.bounds.max.y).toEqual(90);
11-
expect(nonProjection.bounds.min.x).toEqual(-180);
12-
expect(nonProjection.bounds.min.y).toEqual(-90);
7+
var nonProjectionObject = nonProjection(bounds);
8+
expect(nonProjectionObject).not.toBeNull();
9+
expect(nonProjectionObject.bounds).not.toBeNull();
10+
expect(nonProjectionObject.bounds.max.x).toEqual(180);
11+
expect(nonProjectionObject.bounds.max.y).toEqual(90);
12+
expect(nonProjectionObject.bounds.min.x).toEqual(-180);
13+
expect(nonProjectionObject.bounds.min.y).toEqual(-90);
1314
});
1415

15-
it('project, unproject', function () {
16+
it('project, unproject', () => {
1617
var bounds = L.bounds([-180, -90], [180, 90]);
1718
var latlng = L.latLng(50.5, 30.5);
18-
var nonProjection = L.Projection.NonProjection(bounds);
19-
var point = nonProjection.project(latlng);
19+
var nonProjectionObject = nonProjection(bounds);
20+
var point = nonProjectionObject.project(latlng);
2021
expect(point).not.toBeNull();
2122
expect(point.x).toEqual(30.5);
2223
expect(point.y).toEqual(50.5);
23-
var newLatlng = nonProjection.unproject(point);
24+
var newLatlng = nonProjectionObject.unproject(point);
2425
expect(newLatlng).not.toBeNull();
2526
expect(newLatlng.lat).toEqual(50.5);
2627
expect(newLatlng.lng).toEqual(30.5);
2728
});
2829

29-
it('CRS_initialize', function () {
30+
it('CRS_initialize', () => {
3031
var options = {
3132
origin: {x: 30, y: 50},
3233
bounds: L.bounds([-180, -90], [180, 90]),
3334
resolutions: [1000, 100000]
3435
};
35-
var nonEarthCRS = L.CRS.NonEarthCRS(options);
36-
expect(nonEarthCRS).not.toBeNull();
37-
expect(nonEarthCRS.bounds).not.toBeNull();
38-
expect(nonEarthCRS.origin).toEqual(options.origin);
39-
expect(nonEarthCRS.projection.bounds).toEqual(nonEarthCRS.bounds);
40-
expect(nonEarthCRS.resolutions[0]).toEqual(1000);
41-
expect(nonEarthCRS.resolutions[1]).toEqual(100000);
42-
expect(nonEarthCRS.transformation).not.toBeNull();
43-
expect(nonEarthCRS._initHooksCalled).toBeTruthy();
36+
var nonEarthCRSObject = nonEarthCRS(options);
37+
expect(nonEarthCRSObject).not.toBeNull();
38+
expect(nonEarthCRSObject.bounds).not.toBeNull();
39+
expect(nonEarthCRSObject.origin).toEqual(options.origin);
40+
expect(nonEarthCRSObject.projection.bounds).toEqual(nonEarthCRSObject.bounds);
41+
expect(nonEarthCRSObject.resolutions[0]).toEqual(1000);
42+
expect(nonEarthCRSObject.resolutions[1]).toEqual(100000);
43+
expect(nonEarthCRSObject.transformation).not.toBeNull();
44+
expect(nonEarthCRSObject._initHooksCalled).toBeTruthy();
4445
});
4546

46-
it('CRS_scale', function () {
47+
it('CRS_scale', () => {
4748
var options = {
4849
origin: {x: 30, y: 50},
4950
bounds: L.bounds([-180, -90], [180, 90]),
5051
resolutions: [100, 100000]
5152
};
52-
var nonEarthCRS = L.CRS.NonEarthCRS(options);
53-
var scale1 = nonEarthCRS.scale(0);
53+
var nonEarthCRSObject = nonEarthCRS(options);
54+
var scale1 = nonEarthCRSObject.scale(0);
5455
expect(scale1).toEqual(0.01);
55-
nonEarthCRS.resolutions = [];
56-
var scale2 = nonEarthCRS.scale(1);
56+
nonEarthCRSObject.resolutions = [];
57+
var scale2 = nonEarthCRSObject.scale(1);
5758
expect(scale2).not.toBeNaN();
5859
});
5960

60-
it('CRS_zoom', function () {
61+
it('CRS_zoom', () => {
6162
var options1 = {
6263
origin: {x: 30, y: 50},
6364
bounds: L.bounds([-180, -90], [180, 90]),
6465
resolutions: [100, 100000]
6566
};
66-
var nonEarthCRS1 = L.CRS.NonEarthCRS(options1);
67+
var nonEarthCRS1 = nonEarthCRS(options1);
6768
var bound1 = nonEarthCRS1.zoom(0.1);
6869
expect(bound1).toEqual(-1);
6970

@@ -73,29 +74,29 @@ describe('leaflet_NonEarthCRS', function () {
7374
// bounds: L.bounds([-180, -90], [180, 90]),
7475
// resolutions: [100, 100000]
7576
// };
76-
// var nonEarthCRS2 = L.CRS.NonEarthCRS(options2);
77+
// var nonEarthCRS2 = nonEarthCRS(options2);
7778
// var bound2 = nonEarthCRS2.zoom(0.01);
7879
// expect(bound2).toEqual(0);
7980

8081
var options3 = {
8182
origin: {x: 30, y: 50},
8283
bounds: L.bounds([-128, -90], [128, 90]),
8384
};
84-
var nonEarthCRS3 = L.CRS.NonEarthCRS(options3);
85+
var nonEarthCRS3 = nonEarthCRS(options3);
8586
var bound3 = nonEarthCRS3.zoom(10);
8687
expect(bound3).toEqual(10);
8788
});
8889

89-
it('CRS_distance', function () {
90+
it('CRS_distance', () => {
9091
var latlng1 = L.latLng(50.5, 30.5);
9192
var latlng2 = L.latLng(40, 60.5);
9293
var options = {
9394
origin: {x: 30, y: 50},
9495
bounds: L.bounds([-180, -90], [180, 90]),
9596
resolutions: [100, 100000]
9697
};
97-
var nonEarthCRS = L.CRS.NonEarthCRS(options);
98-
var distance = nonEarthCRS.distance(latlng1, latlng2);
98+
var nonEarthCRSObject = nonEarthCRS(options);
99+
var distance = nonEarthCRSObject.distance(latlng1, latlng2);
99100
expect(distance).not.toBeNaN();
100101
});
101102
});

0 commit comments

Comments
 (0)