Skip to content

Commit 485e9e1

Browse files
committed
新增打开文件微件的ut review by songym
1 parent bc343fc commit 485e9e1

File tree

4 files changed

+185
-1
lines changed

4 files changed

+185
-1
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { openFile } from '../../../../src/leaflet/widgets/openfile/OpenFileView'
2+
var map, url = GlobeParameter.WorldURL, testDiv;
3+
var dataServiceURL = GlobeParameter.wokerURL;
4+
describe('leaflet_openfile_OpenFileView', () => {
5+
var serviceResult;
6+
var originalTimeout;
7+
beforeAll(() => {
8+
testDiv = document.createElement("div");
9+
testDiv.id = 'map';
10+
testDiv.style.margin = "0 auto";
11+
testDiv.style.width = "800px";
12+
testDiv.style.height = "800px";
13+
document.body.appendChild(testDiv);
14+
map = L.map('map', {
15+
preferCanvas: true,
16+
crs: L.CRS.EPSG4326,
17+
center: [20, 80],
18+
maxZoom: 18,
19+
zoom: 2
20+
});
21+
22+
});
23+
beforeEach(() => {
24+
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
25+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
26+
serviceResult = null;
27+
});
28+
afterEach(() => {
29+
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
30+
});
31+
afterAll(() => {
32+
map = null;
33+
document.body.removeChild(testDiv);
34+
});
35+
36+
it('readFile', (done) => {
37+
38+
var openFile = L.supermap.widgets.openFile().addTo(map).setPosition('bottomleft');
39+
40+
openFile.viewModel.on('openfilesuccess', function (e) {
41+
try {
42+
expect(e.result.features.length).toBe(2);
43+
done();
44+
} catch (exception) {
45+
console.log("'readfile'案例失败:" + exception.name + ":" + exception.message);
46+
expect(false).toBeTruthy();
47+
done();
48+
}
49+
})
50+
var input = document.getElementById('input_file');
51+
52+
var blob = new Blob([JSON.stringify(china)],
53+
{ type: 'application/json' });
54+
var name = './base/resources/china.json';
55+
var type = 'application/json';
56+
let file = new File([blob], name, {
57+
type: type,
58+
});
59+
60+
var fileEventObject = {
61+
target: {
62+
files: {
63+
0: file
64+
},
65+
value: "./base/resources/china.json"
66+
}
67+
};
68+
openFile.viewModel.readFile(fileEventObject);
69+
})
70+
71+
})

test/libs/workers/TurfWorkerForTest.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
if( 'undefined' === typeof window){
66
importScripts('https://cdnjs.cloudflare.com/ajax/libs/Turf.js/5.1.6/turf.js')
7-
}
7+
88
/**
99
* 空间分析所需工具类
1010
*/
@@ -335,4 +335,5 @@ function analysis(params) {
335335
}
336336
return buffer;
337337
}
338+
}
338339
}

test/resources/OpenFileView.js

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
var china={
2+
"type": "FeatureCollection",
3+
"features": [
4+
{
5+
"type": "Feature",
6+
"properties": {
7+
"id": "81",
8+
"name": "香港",
9+
"cp": [
10+
114.2578,
11+
22.3242
12+
],
13+
"childNum": 1
14+
},
15+
"geometry": {
16+
"type": "Polygon",
17+
"coordinates": [
18+
[
19+
[
20+
114.6094,
21+
22.4121
22+
],
23+
[
24+
114.5215,
25+
22.1484
26+
],
27+
[
28+
114.3457,
29+
22.1484
30+
],
31+
[
32+
113.9063,
33+
22.1484
34+
],
35+
[
36+
113.8184,
37+
22.1924
38+
],
39+
[
40+
113.9063,
41+
22.4121
42+
],
43+
[
44+
114.1699,
45+
22.5439
46+
],
47+
[
48+
114.3457,
49+
22.5439
50+
],
51+
[
52+
114.4336,
53+
22.5439
54+
],
55+
[
56+
114.4336,
57+
22.4121
58+
],
59+
[
60+
114.6094,
61+
22.4121
62+
]
63+
]
64+
]
65+
}
66+
},
67+
{
68+
"type": "Feature",
69+
"properties": {
70+
"id": "82",
71+
"name": "澳门",
72+
"cp": [
73+
113.5547,
74+
22.1484
75+
],
76+
"childNum": 1
77+
},
78+
"geometry": {
79+
"type": "Polygon",
80+
"coordinates": [
81+
[
82+
[
83+
113.5986,
84+
22.1649
85+
],
86+
[
87+
113.6096,
88+
22.1265
89+
],
90+
[
91+
113.5547,
92+
22.11
93+
],
94+
[
95+
113.5437,
96+
22.2034
97+
],
98+
[
99+
113.5767,
100+
22.2034
101+
],
102+
[
103+
113.5986,
104+
22.1649
105+
]
106+
]
107+
]
108+
}
109+
}
110+
]
111+
};

test/test-main-leaflet.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,4 @@ import './leaflet/services/TrafficTransferAnalystServiceSpec.js';
7171
/* widget */
7272
import './leaflet/widgets/dataservicequery/DataServiceQueryViewSpec.js';
7373
import './leaflet/widgets/clientcomputation/ClientComputationViewSpec.js';
74+
import './leaflet/widgets/openfile/OpenFileViewSpec.js';

0 commit comments

Comments
 (0)