This repository has been archived by the owner on Apr 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestsuite.js
111 lines (84 loc) · 2.88 KB
/
testsuite.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
(function() {
'use strict';
if(! window.Tabletop) { window.Tabletop = {init: function() {}}; }
var createLeafletMap = function() {
return L.map($('<div>')[0]);
};
var getFirstLayer = function(map) {
return _.values(map._layers)[0];
}
describe("parseQueryString", function() {
it("parses an empty string", function() {
expect(M.parseQueryString("")).toEqual({});
});
it("parses a simple key value pair", function() {
expect(M.parseQueryString("a=b")).toEqual({a: ['b']});
});
it("parses multiple values for same key", function() {
expect(M.parseQueryString("a=b&a=c&a=d")).toEqual({a: ['b', 'c', 'd']});
});
it("decodes keys and values", function() {
expect(M.parseQueryString("%20=%20")).toEqual({' ': [' ']});
});
it("survives broken input", function() {
expect(M.parseQueryString("&&&")).toEqual({});
expect(M.parseQueryString("===")).toEqual({});
});
});
describe("layerRender.tiles", function() {
it("creates a tiles layer", function() {
var map = createLeafletMap();
M.layerRender.tiles(map, {src: 'foo', attribution: 'bar'});
var layer = getFirstLayer(map);
expect(layer._url).toEqual('foo');
expect(layer.options.attribution).toEqual('bar');
});
});
describe("layerRender.background", function() {
it("creates an OSM layer", function() {
var map = createLeafletMap();
M.layerRender.background(map, {source: 'osm'});
var layer = getFirstLayer(map);
expect(layer._url).toContain('http://{s}.tile.osm.org/{z}/{x}/{y}.png');
expect(layer.options.attribution).toContain('http://osm.org/copyright');
});
});
describe("layerRender.choropleth", function() {
beforeEach(function() {
jasmine.Ajax.install();
spyOn(Tabletop, 'init');
});
afterEach(function() {
jasmine.Ajax.uninstall();
})
it("creates a layer with blank data", function() {
var dataUrl = 'https://docs.google.com/spreadsheet/ccc?key=' +
'0AlBmcLkxpBOXdEEzSE1HWTdWeGYxTG9ja0l4c2VyRHc&usp=drive_web#gid=0';
var featureUrl = 'url-for-the-feature';
var geojson = JSON.stringify({
type: 'FeatureCollection',
features: [
{
type: 'Feature',
properties: {id: 1},
geometry: {
type: 'Polygon',
coordinates: [[[0, 0], [1, 0], [1, 1], [0, 0]]]
}
}
]
});
var map = createLeafletMap();
M.layerRender.choropleth(map, {data: dataUrl, features: featureUrl});
var initOptions = Tabletop.init.calls.first().args[0];
expect(initOptions.key).toEqual(dataUrl);
initOptions.callback([{id: 1, value: 1}]);
var featureRequest = jasmine.Ajax.requests.first();
expect(featureRequest.url).toEqual(featureUrl);
featureRequest.response({status: '200', responseText: geojson});
var layer = getFirstLayer(map);
var object = layer.getLayers()[0];
expect(object.feature.properties.id).toEqual(1);
});
});
})();