Skip to content

Commit 22a5433

Browse files
committed
补充UT。review by chenmy
1 parent 6ef2de0 commit 22a5433

File tree

11 files changed

+621
-0
lines changed

11 files changed

+621
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
var AreaSolarRadiationParameters = require('../../../src/common/iServer/AreaSolarRadiationParameters').AreaSolarRadiationParameters;
2+
3+
describe('AreaSolarRadiationParameters', function () {
4+
it('constructor, destroy', function () {
5+
var options = {
6+
dataset: "JingjinTerrain@Jingjin",
7+
targetDatasourceName: "Jingjin",
8+
totalGridName: "dataset1",
9+
diffuseDatasetGridName: "dataset2",
10+
durationDatasetGridName: "dataset3",
11+
directDatasetGridName: "dataset4",
12+
latitude: 90,
13+
dayStart: 1,
14+
dayEnd: 300,
15+
hourStart: 8,
16+
hourEnd: 18,
17+
};
18+
var parameters = new AreaSolarRadiationParameters(options);
19+
expect(parameters).not.toBeNull();
20+
expect(parameters.dataset).toEqual("JingjinTerrain@Jingjin");
21+
expect(parameters.targetDatasourceName).toEqual("Jingjin");
22+
expect(parameters.totalGridName).toEqual("dataset1");
23+
expect(parameters.diffuseDatasetGridName).toEqual("dataset2");
24+
expect(parameters.durationDatasetGridName).toEqual("dataset3");
25+
expect(parameters.directDatasetGridName).toEqual("dataset4");
26+
expect(parameters.latitude).toEqual(90);
27+
expect(parameters.dayStart).toEqual(1);
28+
expect(parameters.dayEnd).toEqual(300);
29+
expect(parameters.hourStart).toEqual(8);
30+
expect(parameters.hourEnd).toEqual(18);
31+
parameters.destroy();
32+
expect(parameters.dataset).toBeNull();
33+
expect(parameters.zFactor).toBe(1);
34+
expect(parameters.averageCurvatureName).toBeNull();
35+
expect(parameters.profileCurvatureName).toBeNull();
36+
expect(parameters.deleteExistResultDataset).toBeTruthy();
37+
});
38+
39+
it('toObject', function () {
40+
var options = {
41+
dataset: "JingjinTerrain@Jingjin",
42+
targetDatasourceName: "Jingjin",
43+
totalGridName: "dataset1",
44+
diffuseDatasetGridName: "dataset2",
45+
durationDatasetGridName: "dataset3",
46+
directDatasetGridName: "dataset4",
47+
latitude: 90,
48+
dayStart: 1,
49+
dayEnd: 300,
50+
hourStart: 8,
51+
hourEnd: 18,
52+
};
53+
var parameters = new AreaSolarRadiationParameters(options);
54+
new SuperMap.AreaSolarRadiationParameters.toObject(options, parameters);
55+
expect(parameters).not.toBeNull();
56+
expect(parameters.parameter).not.toBeNull();
57+
expect(parameters.parameter.latitude).toEqual(90);
58+
expect(parameters.parameter.dayStart).toEqual(1);
59+
expect(parameters.parameter.dayEnd).toEqual(300);
60+
expect(parameters.parameter.hourStart).toEqual(8);
61+
expect(parameters.parameter.hourEnd).toEqual(18);
62+
parameters.destroy();
63+
});
64+
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
var ChartQueryFilterParameter = require('../../../src/common/iServer/ChartQueryFilterParameter').ChartQueryFilterParameter;
2+
3+
describe('ChartQueryFilterParameter', function () {
4+
it('constructor, destroy', function () {
5+
var options = {
6+
isQueryPoint: true,
7+
isQueryLine: true,
8+
isQueryRegion: true,
9+
attributeFilter: "test",
10+
};
11+
var parameter = new ChartQueryFilterParameter(options);
12+
expect(parameter).not.toBeNull();
13+
expect(parameter.CLASS_NAME).toEqual("SuperMap.ChartQueryFilterParameter");
14+
expect(parameter.attributeFilter).toEqual("test");
15+
expect(parameter.isQueryLine).toBeTruthy();
16+
expect(parameter.isQueryPoint).toBeTruthy();
17+
expect(parameter.isQueryRegion).toBeTruthy();
18+
parameter.destroy();
19+
expect(parameter.isQueryPoint).toBeNull();
20+
expect(parameter.isQueryLine).toBeNull();
21+
expect(parameter.isQueryRegion).toBeNull();
22+
expect(parameter.attributeFilter).toBeNull();
23+
});
24+
25+
it('toJson',function () {
26+
var options = {
27+
isQueryPoint: true,
28+
isQueryLine: true,
29+
isQueryRegion: true,
30+
attributeFilter: "test",
31+
};
32+
var parameter = new ChartQueryFilterParameter(options);
33+
var json = parameter.toJson();
34+
expect(json).not.toBeNull();
35+
expect(json).toContain("\"isQueryPoint\":true");
36+
parameter.destroy();
37+
});
38+
});
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
var ChartQueryParameters = require('../../../src/common/iServer/ChartQueryParameters').ChartQueryParameters;
2+
var ChartQueryFilterParameter = require('../../../src/common/iServer/ChartQueryFilterParameter').ChartQueryFilterParameter;
3+
4+
describe('ChartQueryParameters', function () {
5+
it('constructor, destroy', function () {
6+
var options = {
7+
queryMode: "ChartAttributeQuery",
8+
bounds: new SuperMap.Bounds(-180, -90, 180, 90),
9+
};
10+
var parameter = new ChartQueryParameters(options);
11+
expect(parameter).not.toBeNull();
12+
expect(parameter.CLASS_NAME).toEqual("SuperMap.ChartQueryParameters");
13+
expect(parameter.bounds.bottom).toEqual(-90);
14+
expect(parameter.bounds.left).toEqual(-180);
15+
expect(parameter.bounds.right).toEqual(180);
16+
expect(parameter.bounds.top).toEqual(90);
17+
expect(parameter.queryMode).toEqual("ChartAttributeQuery");
18+
expect(parameter.returnContent).toBeTruthy();
19+
expect(parameter.startRecord).toEqual(0);
20+
parameter.destroy();
21+
expect(parameter.queryMode).toBeNull();
22+
expect(parameter.bounds).toBeNull();
23+
expect(parameter.chartQueryFilterParameters).toBeNull();
24+
expect(parameter.returnContent).toBeTruthy();
25+
expect(parameter.expectCount).toBeNull();
26+
});
27+
28+
it('getVariablesJson', function () {
29+
var options = {
30+
queryMode: "ChartAttributeQuery",
31+
bounds: new SuperMap.Bounds(-180, -90, 180, 90),
32+
chartLayerNames: ["testLayer0", "testLayer1", "testLayer2"],
33+
chartQueryFilterParameters: [
34+
new ChartQueryFilterParameter({isQueryPoint: true}),
35+
new ChartQueryFilterParameter({isQueryPoint: false})
36+
],
37+
};
38+
var parameter = new ChartQueryParameters(options);
39+
var json = parameter.getVariablesJson();
40+
expect(parameter).not.toBeNull();
41+
expect(json).not.toBeNull();
42+
expect(json).toContain("ChartAttributeQuery");
43+
parameter.destroy();
44+
});
45+
});
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
var ClipParameter = require('../../../src/common/iServer/ClipParameter').ClipParameter;
2+
3+
describe('ClipParameter', function () {
4+
it('constructor, destroy', function () {
5+
var points = [new SuperMap.Geometry.Point(111.4687675858, 353.8548114800),
6+
new SuperMap.Geometry.Point(111.4687675858, 408.1485649972),
7+
new SuperMap.Geometry.Point(208.9814293754, 408.1485649972),
8+
new SuperMap.Geometry.Point(208.9814293754, 353.8548114800)];
9+
var options = {
10+
clipDatasetName: "testDataset",
11+
clipDatasourceName: "testDatasource",
12+
clipRegion: new SuperMap.Geometry.Polygon(new SuperMap.Geometry.LinearRing(points)),
13+
isExactClip: false
14+
};
15+
var parameter = new ClipParameter(options);
16+
expect(parameter.clipDatasetName).toEqual("testDataset");
17+
expect(parameter.clipDatasourceName).toEqual("testDatasource");
18+
expect(parameter.clipRegion).not.toBeNull();
19+
expect(parameter.isExactClip).toBeFalsy();
20+
parameter.destroy();
21+
expect(parameter.clipDatasetName).toBeNull();
22+
expect(parameter.clipDatasourceName).toBeNull();
23+
expect(parameter.clipRegion).toBeNull();
24+
expect(parameter.isClipInRegion).toBeNull();
25+
expect(parameter.isExactClip).toBeNull();
26+
});
27+
28+
it('toJSON', function () {
29+
var points = [new SuperMap.Geometry.Point(111.4687675858, 353.8548114800),
30+
new SuperMap.Geometry.Point(111.4687675858, 408.1485649972),
31+
new SuperMap.Geometry.Point(208.9814293754, 408.1485649972),
32+
new SuperMap.Geometry.Point(208.9814293754, 353.8548114800)];
33+
var options = {
34+
clipDatasetName: "testDataset",
35+
clipDatasourceName: "testDatasource",
36+
clipRegion: new SuperMap.Geometry.Polygon(new SuperMap.Geometry.LinearRing(points)),
37+
isClipInRegion: true,
38+
isExactClip: false
39+
};
40+
var parameter = new ClipParameter(options);
41+
var json = parameter.toJSON();
42+
expect(json).not.toBeNull();
43+
expect(json).toContain("'clipDatasetName':\"testDataset\"");
44+
parameter.isClipInRegion = false;
45+
var json1 = parameter.toJSON();
46+
expect(json1).toBeNull();
47+
parameter.destroy();
48+
});
49+
});

test/common/online/OnlineSpec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var Online = require('../../../src/common/online/Online').Online;
2+
3+
describe('Online',function () {
4+
it('constructor',function () {
5+
var online = new Online();
6+
expect(online.rootUrl).toEqual("http://www.supermapol.com");
7+
expect(online.webUrl).toEqual("http://www.supermapol.com/web");
8+
expect(online.mDatasUrl).toEqual("http://www.supermapol.com/web/mycontent/datas");
9+
});
10+
});
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
var Transformable = require('../../../../src/common/overlay/levelRenderer/Transformable').Transformable;
2+
3+
describe('Transformable', function () {
4+
var canvas, ctx;
5+
beforeAll(function () {
6+
canvas = window.document.createElement('CANVAS');
7+
canvas.width = 400;
8+
canvas.height = 400;
9+
canvas.style.border = "1px solid #000000";
10+
ctx = canvas.getContext('2d');
11+
window.document.body.appendChild(canvas);
12+
});
13+
afterAll(function () {
14+
window.document.body.removeChild(canvas);
15+
});
16+
it('updateNeedTransform, updateTransform', function () {
17+
var transformable = new Transformable();
18+
transformable.lookAt([1, 1]);
19+
transformable.lookAt([0, 0]);
20+
transformable.position = [1, 1];
21+
transformable.rotation = [1, 2];
22+
transformable.scale = [1, 1, 2, 2];
23+
spyOn(transformable, 'updateNeedTransform').and.callThrough();
24+
expect(transformable.needLocalTransform).toBeFalsy();
25+
expect(transformable.needTransform).toBeFalsy();
26+
transformable.updateTransform();
27+
expect(transformable.needLocalTransform).toBeTruthy();
28+
expect(transformable.needTransform).toBeTruthy();
29+
expect(transformable.transform).not.toBeNull();
30+
transformable.rotation = 3;
31+
transformable.updateTransform();
32+
expect(transformable.needLocalTransform).toBeTruthy();
33+
expect(transformable.needTransform).toBeTruthy();
34+
expect(transformable.rotation).toEqual(3);
35+
expect(transformable.transform).not.toBeNull();
36+
expect(transformable.updateNeedTransform).toHaveBeenCalled();
37+
expect(transformable.updateNeedTransform.calls.count()).toEqual(2);
38+
transformable.destroy();
39+
});
40+
41+
it('setTransform', function () {
42+
var transformable = new Transformable();
43+
transformable.position = [1, 1];
44+
spyOn(ctx, 'transform').and.callThrough();
45+
transformable.updateTransform();
46+
transformable.setTransform(ctx);
47+
expect(ctx.transform).toHaveBeenCalled();
48+
transformable.destroy();
49+
});
50+
51+
it('decomposeTransform', function () {
52+
var transformable = new Transformable();
53+
transformable.decomposeTransform();
54+
transformable.position = [12, 10];
55+
transformable.rotation = [10, 20];
56+
transformable.scale = [10, 10, 20, 20];
57+
transformable.updateTransform();
58+
expect(transformable.position[0]).toEqual(12);
59+
expect(transformable.position[1]).toEqual(10);
60+
expect(transformable.rotation[0]).toEqual(10);
61+
expect(transformable.rotation[1]).toEqual(20);
62+
expect(transformable.scale[0]).toEqual(10);
63+
expect(transformable.scale[1]).toEqual(10);
64+
expect(transformable.scale[2]).toEqual(20);
65+
expect(transformable.scale[3]).toEqual(20);
66+
transformable.decomposeTransform();
67+
expect(transformable.position[0]).not.toBe(12);
68+
expect(transformable.position[1]).not.toBe(10);
69+
expect(transformable.rotation[0]).not.toBe(10);
70+
expect(transformable.rotation[1]).not.toBe(20);
71+
expect(transformable.scale[0]).not.toBe(10);
72+
expect(transformable.scale[1]).not.toBe(10);
73+
expect(transformable.scale[2]).not.toBe(20);
74+
expect(transformable.scale[3]).not.toBe(20);
75+
transformable.destroy();
76+
});
77+
});

0 commit comments

Comments
 (0)