Skip to content

Commit 3a10d06

Browse files
committed
补充common下的UT。review by chenmy
1 parent 130a880 commit 3a10d06

File tree

4 files changed

+933
-0
lines changed

4 files changed

+933
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
require('../../../../src/common/overlay/levelRenderer/SmicImage');
2+
var img = require('../../../resources/img/baiduTileTest.png');
3+
4+
describe('SmicImage', function () {
5+
var originalTimeout;
6+
var canvas, ctx;
7+
beforeAll(function () {
8+
canvas = window.document.createElement('CANVAS');
9+
canvas.width = 400;
10+
canvas.height = 400;
11+
canvas.style.border = "1px solid #000000";
12+
ctx = canvas.getContext('2d');
13+
window.document.body.appendChild(canvas);
14+
});
15+
beforeEach(function () {
16+
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
17+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
18+
});
19+
afterEach(function () {
20+
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
21+
});
22+
afterAll(function () {
23+
window.document.body.removeChild(canvas);
24+
});
25+
26+
it('constructor, destroy', function () {
27+
var image = new SuperMap.LevelRenderer.Shape.SmicImage({
28+
style: {
29+
image: img.src,
30+
x: 100,
31+
y: 100
32+
}
33+
});
34+
expect(image).not.toBeNull();
35+
expect(image.id).not.toBeNull();
36+
expect(image.type).toEqual("smicimage");
37+
expect(image.style.image).not.toBeNull();
38+
expect(image.style.x).toEqual(100);
39+
expect(image.style.y).toEqual(100);
40+
image.destroy();
41+
expect(image.id).toBeNull();
42+
expect(image.type).toBeNull();
43+
expect(image.style).toBeNull();
44+
});
45+
46+
it('brush, clearCache', function (done) {
47+
var image = new SuperMap.LevelRenderer.Shape.SmicImage({
48+
style: {
49+
image: img.src,
50+
x: 100,
51+
y: 100,
52+
sx: 5,
53+
sy: 5,
54+
}
55+
});
56+
image.refOriginalPosition = null;
57+
image.brush(ctx, true, function () {
58+
image.brush(ctx, true, false);
59+
expect(image).not.toBeNull();
60+
expect(image.id).not.toBeNull();
61+
expect(image.type).toEqual("smicimage");
62+
expect(image.style.width).toEqual(128);
63+
expect(image.style.height).toEqual(128);
64+
expect(image.style.x).toEqual(100);
65+
expect(image.style.y).toEqual(100);
66+
expect(image.style.sx).toEqual(5);
67+
expect(image.style.sy).toEqual(5);
68+
expect(image.style.image).not.toBeNull();
69+
expect(image._imageCache).not.toBeNull();
70+
image.clearCache();
71+
expect(image._imageCache).toEqual({});
72+
image.destroy();
73+
done();
74+
});
75+
});
76+
77+
it('getRect', function () {
78+
var image = new SuperMap.LevelRenderer.Shape.SmicImage({
79+
style: {
80+
image: img.src,
81+
x: 100,
82+
y: 100
83+
}
84+
});
85+
var style = {
86+
image: img.src,
87+
x: 100,
88+
y: 100,
89+
height: 128,
90+
width: 128,
91+
};
92+
var rect = image.getRect(style);
93+
expect(rect).not.toBeNull();
94+
expect(rect.width).toEqual(128);
95+
expect(rect.height).toEqual(128);
96+
expect(rect.x).toEqual(100);
97+
expect(rect.y).toEqual(100);
98+
image.destroy();
99+
});
100+
});
Lines changed: 295 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,295 @@
1+
require('../../../../src/common/overlay/levelRenderer/SmicPolygon');
2+
3+
describe('SmicPolygon', function () {
4+
var originalTimeout;
5+
var canvas, ctx;
6+
beforeAll(function () {
7+
canvas = window.document.createElement('CANVAS');
8+
canvas.width = 400;
9+
canvas.height = 400;
10+
canvas.style.border = "1px solid #000000";
11+
ctx = canvas.getContext('2d');
12+
window.document.body.appendChild(canvas);
13+
});
14+
afterAll(function () {
15+
window.document.body.removeChild(canvas);
16+
});
17+
18+
it('constructor, destroy', function () {
19+
var shape = new SuperMap.LevelRenderer.Shape.SmicPolygon({
20+
style: {
21+
//100x100的正方形
22+
pointList: [[0, 0], [100, 0], [100, 100], [0, 100]],
23+
}
24+
});
25+
expect(shape).not.toBeNull();
26+
expect(shape.id).not.toBeNull();
27+
expect(shape.type).toEqual("smicpolygon");
28+
expect(shape.style).not.toBeNull();
29+
expect(shape.style.pointList.length).toEqual(4);
30+
for (var i = 0; i < shape.style.pointList.length; i++) {
31+
expect(shape.style.pointList[i].length).toEqual(2);
32+
expect(shape.style.pointList[i][0]).not.toBeNaN();
33+
expect(shape.style.pointList[i][1]).not.toBeNaN();
34+
}
35+
shape.destroy();
36+
expect(shape.id).toBeNull();
37+
expect(shape.type).toBeNull();
38+
expect(shape.style).toBeNull();
39+
});
40+
41+
//笔触 isHighlight = false 不使用高亮属性
42+
it('brush_isHighlight = false', function () {
43+
var shape = new SuperMap.LevelRenderer.Shape.SmicPolygon({
44+
style: {
45+
//100x100的正方形
46+
pointList: [[0, 0], [100, 0], [100, 100], [0, 100]],
47+
}
48+
});
49+
shape.holePolygonPointLists = [[0, 0, 0], [100, 100, 0], [100, 0, 100], [0, 0, 100]];
50+
shape.refOriginalPosition = null;
51+
shape.brush(ctx, false);
52+
expect(shape).not.toBeNull();
53+
expect(shape.id).not.toBeNull();
54+
expect(shape.type).toEqual("smicpolygon");
55+
expect(shape.style).not.toBeNull();
56+
expect(shape.style.pointList.length).toEqual(4);
57+
expect(shape.holePolygonPointLists.length).toEqual(4);
58+
for (var i = 0; i < shape.holePolygonPointLists.length; i++) {
59+
expect(shape.holePolygonPointLists[i].length).toEqual(3);
60+
expect(shape.holePolygonPointLists[i][0]).not.toBeNaN();
61+
expect(shape.holePolygonPointLists[i][1]).not.toBeNaN();
62+
expect(shape.holePolygonPointLists[i][2]).not.toBeNaN();
63+
}
64+
shape.destroy();
65+
});
66+
67+
//笔触 使用高亮属性
68+
it('brush', function () {
69+
var shape = new SuperMap.LevelRenderer.Shape.SmicPolygon({
70+
style: {
71+
//100x100的正方形
72+
pointList: [[0, 0], [100, 0], [100, 100], [0, 100]],
73+
lineType: 'dashed',
74+
},
75+
});
76+
shape.holePolygonPointLists = [[0, 0, 0], [100, 100, 0], [100, 0, 100], [0, 0, 100]];
77+
shape.refOriginalPosition = null;
78+
shape.brush(ctx, true);
79+
expect(shape).not.toBeNull();
80+
expect(shape.id).not.toBeNull();
81+
expect(shape.type).toEqual("smicpolygon");
82+
expect(shape.style).not.toBeNull();
83+
expect(shape.style.pointList.length).toEqual(4);
84+
expect(shape.holePolygonPointLists.length).toEqual(4);
85+
for (var i = 0; i < shape.holePolygonPointLists.length; i++) {
86+
expect(shape.holePolygonPointLists[i].length).toEqual(3);
87+
expect(shape.holePolygonPointLists[i][0]).not.toBeNaN();
88+
expect(shape.holePolygonPointLists[i][1]).not.toBeNaN();
89+
expect(shape.holePolygonPointLists[i][2]).not.toBeNaN();
90+
}
91+
shape.destroy();
92+
});
93+
94+
it('buildPath_style1', function () {
95+
var shape = new SuperMap.LevelRenderer.Shape.SmicPolygon({
96+
style: {
97+
//100x100的正方形
98+
pointList: [[0, 0], [100, 0], [100, 100], [0, 100]],
99+
lineType: 'solid',
100+
},
101+
});
102+
var style1 = {
103+
//100x100的正方形
104+
pointList: [[0, 0], [100, 0], [100, 100], [0, 100]],
105+
lineType: 'solid',
106+
showShadow: true,
107+
smooth: 'spline',
108+
};
109+
shape.refOriginalPosition = null;
110+
shape.buildPath(ctx, style1);
111+
expect(shape).not.toBeNull();
112+
style1.lineType = "dotted";
113+
shape.buildPath(ctx, style1);
114+
expect(shape).not.toBeNull();
115+
style1.lineType = "dot";
116+
shape.buildPath(ctx, style1);
117+
expect(shape).not.toBeNull();
118+
style1.lineType = "dash";
119+
shape.buildPath(ctx, style1);
120+
expect(shape).not.toBeNull();
121+
style1.lineType = "longdash";
122+
shape.buildPath(ctx, style1);
123+
expect(shape).not.toBeNull();
124+
expect(shape.id).not.toBeNull();
125+
expect(shape.type).toEqual("smicpolygon");
126+
expect(shape.style).not.toBeNull();
127+
expect(shape.style.pointList.length).toEqual(4);
128+
expect(shape.style.lineType).toEqual("solid");
129+
shape.destroy();
130+
});
131+
132+
it('buildPath_style2', function () {
133+
var shape = new SuperMap.LevelRenderer.Shape.SmicPolygon({
134+
style: {
135+
pointList: [[0, 0], [100, 0], [100, 100], [0, 100]],
136+
lineType: 'solid',
137+
},
138+
});
139+
var style2 = {
140+
pointList: [[0, 0], [100, 0], [100, 100], [0, 100]],
141+
lineType: 'dashed',
142+
showShadow: true,
143+
smooth: 'spline',
144+
lineCap: 'round',
145+
};
146+
shape.refOriginalPosition = null;
147+
shape.buildPath(ctx, style2);
148+
expect(shape).not.toBeNull();
149+
style2.lineType = "dotted";
150+
shape.buildPath(ctx, style2);
151+
expect(shape).not.toBeNull();
152+
style2.lineType = "dot";
153+
shape.buildPath(ctx, style2);
154+
expect(shape).not.toBeNull();
155+
style2.lineType = "dash";
156+
shape.buildPath(ctx, style2);
157+
expect(shape).not.toBeNull();
158+
style2.lineType = "longdash";
159+
shape.buildPath(ctx, style2);
160+
expect(shape).not.toBeNull();
161+
expect(shape.id).not.toBeNull();
162+
expect(shape.type).toEqual("smicpolygon");
163+
expect(shape.style).not.toBeNull();
164+
expect(shape.style.pointList.length).toEqual(4);
165+
expect(shape.style.lineType).toEqual("solid");
166+
shape.destroy();
167+
});
168+
169+
it('buildPath_style3', function () {
170+
var shape = new SuperMap.LevelRenderer.Shape.SmicPolygon({
171+
style: {
172+
//100x100的正方形
173+
pointList: [[0, 0], [100, 0], [100, 100], [0, 100]],
174+
lineType: 'dashed',
175+
},
176+
});
177+
var style3 = {
178+
//100x100的正方形
179+
pointList: [[0, 0], [100, 0], [100, 100], [0, 100]],
180+
lineType: 'dashed',
181+
showShadow: true,
182+
smooth: 'bezier',
183+
};
184+
shape.buildPath(ctx, style3);
185+
expect(shape).not.toBeNull();
186+
expect(shape.id).not.toBeNull();
187+
expect(shape.type).toEqual("smicpolygon");
188+
expect(shape.style).not.toBeNull();
189+
expect(shape.style.pointList.length).toEqual(4);
190+
expect(shape.style.lineType).toEqual("dashed");
191+
shape.destroy();
192+
});
193+
194+
it('buildPath_style4', function () {
195+
var shape = new SuperMap.LevelRenderer.Shape.SmicPolygon({
196+
style: {
197+
//100x100的正方形
198+
pointList: [[0, 0], [100, 0], [100, 100], [0, 100]],
199+
lineType: 'longdashdot',
200+
},
201+
});
202+
var style4 = {
203+
//100x100的正方形
204+
pointList: [[0, 0], [100, 0], [100, 100], [0, 100]],
205+
lineType: 'longdashdot',
206+
showShadow: true,
207+
smooth: 'spline',
208+
};
209+
shape.buildPath(ctx, style4);
210+
expect(shape).not.toBeNull();
211+
style4.lineType = "dashot";
212+
shape.buildPath(ctx, style4);
213+
expect(shape).not.toBeNull();
214+
expect(shape.id).not.toBeNull();
215+
expect(shape.type).toEqual("smicpolygon");
216+
expect(shape.style).not.toBeNull();
217+
expect(shape.style.pointList.length).toEqual(4);
218+
expect(shape.style.lineType).toEqual("longdashdot");
219+
shape.destroy();
220+
});
221+
222+
it('buildPath_style5', function () {
223+
var shape = new SuperMap.LevelRenderer.Shape.SmicPolygon({
224+
style: {
225+
//100x100的正方形
226+
pointList: [[0, 0], [100, 0], [100, 100], [0, 100]],
227+
lineType: 'longdashdot',
228+
},
229+
});
230+
var style5 = {
231+
//100x100的正方形
232+
pointList: [[0, 0], [100, 0], [100, 100], [0, 100]],
233+
lineType: 'longdashdot',
234+
showShadow: true,
235+
smooth: 'spline',
236+
lineCap: 'round',
237+
};
238+
shape.buildPath(ctx, style5);
239+
expect(shape).not.toBeNull();
240+
style5.lineType = "dashot";
241+
shape.buildPath(ctx, style5);
242+
expect(shape).not.toBeNull();
243+
expect(shape.id).not.toBeNull();
244+
expect(shape.type).toEqual("smicpolygon");
245+
expect(shape.style).not.toBeNull();
246+
expect(shape.style.pointList.length).toEqual(4);
247+
expect(shape.style.lineType).toEqual("longdashdot");
248+
shape.destroy();
249+
});
250+
251+
it('getRect_style1', function () {
252+
var shape = new SuperMap.LevelRenderer.Shape.SmicPolygon({
253+
style: {
254+
pointList: [[0, 0], [100, 0], [100, 100], [0, 100]],
255+
}
256+
});
257+
var style1 = {
258+
pointList: [[0, 0], [100, 0], [100, 100], [0, 100]],
259+
lineType: 'solid',
260+
showShadow: true,
261+
smooth: 'spline',
262+
brushType: 'fill'
263+
};
264+
shape.refOriginalPosition = null;
265+
var rect = shape.getRect(style1, shape.refOriginalPosition);
266+
expect(rect).not.toBeNull();
267+
expect(rect.height).toEqual(101);
268+
expect(rect.width).toEqual(101);
269+
expect(rect.x).toEqual(-0);
270+
expect(rect.y).toEqual(-0);
271+
shape.destroy();
272+
273+
});
274+
275+
it('getRect_style2', function () {
276+
var shape = new SuperMap.LevelRenderer.Shape.SmicPolygon({
277+
style: {
278+
pointList: [[0, 0], [100, 0], [100, 100], [0, 100]],
279+
}
280+
});
281+
var style2 = {
282+
pointList: [[0, 0], [100, 0], [100, 100], [0, 100]],
283+
lineType: 'solid',
284+
showShadow: true,
285+
smooth: 'spline',
286+
};
287+
var rect = shape.getRect(style2, shape.refOriginalPosition);
288+
expect(rect).not.toBeNull();
289+
expect(rect.height).toEqual(100);
290+
expect(rect.width).toEqual(100);
291+
expect(rect.x).toEqual(0);
292+
expect(rect.y).toEqual(0);
293+
shape.destroy();
294+
});
295+
});

0 commit comments

Comments
 (0)