Skip to content

Commit 6b62d5b

Browse files
committed
better tests
1 parent 674594c commit 6b62d5b

17 files changed

+174
-180
lines changed

src/directives/watchOptions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@
3434
});
3535
},
3636
};
37-
},]);
37+
}, ]);
3838
});

src/services/leafletData.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ angular.module('leaflet-directive').service('leafletData', function($log, $q, le
1919
'geoJSON',
2020
'UTFGrid', //odd ball on naming convention keeping to not break
2121
'decorations',
22-
'directiveControls',];
22+
'directiveControls', ];
2323

2424
//init
2525
_privateItems.forEach(function(itemName) {

test/karma-unit.conf.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ module.exports = function(karma) {
1010
'bower_components/angular-mocks/angular-mocks.js',
1111
'bower_components/leaflet.markercluster/dist/leaflet.markercluster.js',
1212
'bower_components/leaflet.vector-markers/dist/Leaflet.vector-markers.js',
13+
'bower_components/Leaflet.PolylineDecorator/leaflet.polylineDecorator.js',
1314
'dist/angular-leaflet-directive.js',
1415
'test/unit/*.js',
15-
'test/unit/**/*.js',
16-
'bower_components/Leaflet.PolylineDecorator/leaflet.polylineDecorator.js',
16+
'test/unit/**/marker*.js',
1717
],
1818

1919
// Frameworks

test/unit/000-leafletDirectiveSpec.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
/* jasmine specs for directives go here */
66

77
describe('Directive: leaflet', function() {
8-
var $compile, $rootScope, $timeout, leafletData, leafletMapDefaults, scope;
8+
var $compile;
9+
var $rootScope;
10+
var $timeout;
11+
var leafletData;
12+
var leafletMapDefaults;
13+
var scope;
914

1015
beforeEach(module('leaflet-directive'));
1116
beforeEach(inject(function(_$compile_, _$rootScope_, _$timeout_, _leafletData_, _leafletMapDefaults_) {
Lines changed: 113 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -1,171 +1,121 @@
11
'use strict';
22

3+
/*jshint -W117 */
4+
/*jshint globalstrict: true*/
5+
/* jasmine specs for directives go here */
6+
37
describe('Directive: leaflet center', function() {
4-
var $compile;
5-
var $location;
6-
var $rootScope;
7-
var $timeout;
8-
var center;
9-
var directiveName;
10-
var key;
11-
var leafletData;
12-
var ref;
13-
var results;
14-
var scope;
15-
scope = center = leafletData = $location = $timeout = $compile = $rootScope = void 0;
16-
17-
beforeEach(module('leaflet-directive'));
18-
beforeEach(inject(function(_$compile_, _$rootScope_, _$timeout_, _$location_, _leafletData_) {
19-
$compile = _$compile_;
20-
$rootScope = _$rootScope_;
21-
$timeout = _$timeout_;
22-
window.ngLeafLetTestGlobals.$timeout = $timeout;
23-
$location = _$location_;
24-
leafletData = _leafletData_;
25-
center = {
26-
lat: 0.96658,
27-
lng: 2.02,
28-
zoom: 4,
8+
var $compile;
9+
var $rootScope;
10+
var $timeout;
11+
var $location;
12+
var leafletData;
13+
var center;
14+
var scope;
15+
16+
beforeEach(module('leaflet-directive'));
17+
beforeEach(inject(function(_$compile_, _$rootScope_, _$timeout_, _$location_, _leafletData_) {
18+
$compile = _$compile_;
19+
$rootScope = _$rootScope_;
20+
$timeout = _$timeout_;
21+
$location = _$location_;
22+
leafletData = _leafletData_;
23+
24+
center = {
25+
lat: 0.96658,
26+
lng: 2.02,
27+
zoom: 4,
28+
};
29+
30+
scope = $rootScope.$new();
31+
scope.center = center;
32+
}));
33+
34+
afterEach(inject(function($rootScope) {
35+
$rootScope.$apply();
36+
}));
37+
38+
it('should have default {[0, 0], 1} parameters on the map if not correctly defined', function() {
39+
scope.center = {};
40+
var element = angular.element('<leaflet center="center"></leaflet>');
41+
element = $compile(element)(scope);
42+
scope.$digest();
43+
44+
leafletData.getMap().then(function(map) {
45+
expect(map.getZoom()).toEqual(1);
46+
expect(map.getCenter().lat).toEqual(0);
47+
expect(map.getCenter().lng).toEqual(0);
48+
});
49+
});
50+
51+
it('should update the map center if the initial center scope properties are set', function() {
52+
var element = angular.element('<leaflet center="center"></leaflet>');
53+
element = $compile(element)(scope);
54+
scope.$digest();
55+
56+
leafletData.getMap().then(function(map) {
57+
expect(map.getZoom()).toEqual(center.zoom);
58+
expect(map.getCenter().lat).toBeCloseTo(0.96658, 4);
59+
expect(map.getCenter().lng).toBeCloseTo(2.02, 4);
60+
});
61+
});
62+
63+
it('should update the map center if the scope center properties changes', function() {
64+
var element = angular.element('<leaflet center="center"></leaflet>');
65+
element = $compile(element)(scope);
66+
var map;
67+
leafletData.getMap().then(function(leafletMap) {
68+
map = leafletMap;
69+
});
70+
71+
scope.$apply();
72+
73+
expect(map.getCenter().lat).toBeCloseTo(0.96658, 4);
74+
expect(map.getCenter().lng).toBeCloseTo(2.02, 4);
75+
expect(map.getZoom()).toEqual(4);
76+
77+
center.lat = 2.02999;
78+
center.lng = 4.04;
79+
center.zoom = 8;
80+
scope.$digest();
81+
82+
expect(map.getCenter().lat).toBeCloseTo(2.02999, 4);
83+
expect(map.getCenter().lng).toBeCloseTo(4.04, 4);
84+
expect(map.getZoom()).toEqual(8);
85+
});
86+
87+
describe('Using url-hash functionality', function() {
88+
it('should update the center of the map if changes the url', function() {
89+
var element = angular.element('<leaflet center="center" url-hash-center="yes"></leaflet>');
90+
element = $compile(element)(scope);
91+
var map;
92+
leafletData.getMap().then(function(leafletMap) {
93+
map = leafletMap;
94+
});
95+
96+
var centerParams = {
97+
c: '30.1' + ':' + '-9.2' + ':' + '4',
2998
};
30-
}));
3199

32-
beforeEach(function() {
33-
scope = $rootScope.$new();
34-
scope.center = center;
100+
$location.search(centerParams);
101+
scope.$digest();
102+
103+
expect(map.getCenter().lat).toBeCloseTo(30.1, 4);
104+
expect(map.getCenter().lng).toBeCloseTo(-9.2, 4);
105+
expect(map.getZoom()).toEqual(4);
35106
});
36107

37-
afterEach(inject(function($rootScope) {
38-
if (!$rootScope.$$phase) {
39-
return $rootScope.$apply();
40-
}
41-
}));
42-
43-
ref = ['center', 'lf-center'];
44-
results = [];
45-
for (key in ref) {
46-
directiveName = ref[key];
47-
results.push(describe(directiveName, function() {
48-
describe('sets leaflet from scope', function() {
49-
it('should have default {[0, 0], 1} parameters on the map if not correctly defined', function() {
50-
var element;
51-
scope.center = {};
52-
element = angular.element('<leaflet ' + directiveName + '=\'center\'></leaflet>');
53-
element = $compile(element)(scope);
54-
scope.$digest();
55-
return leafletData.getMap().then(function(map) {
56-
expect(map.getZoom()).toEqual(1);
57-
expect(map.getCenter().lat).toEqual(0);
58-
return expect(map.getCenter().lng).toEqual(0);
59-
});
60-
});
61-
62-
it('should update the map center if the initial center scope properties are set', function() {
63-
var element;
64-
element = angular.element('<leaflet ' + directiveName + '=\'center\'></leaflet>');
65-
element = $compile(element)(scope);
66-
scope.$digest();
67-
return leafletData.getMap().then(function(map) {
68-
expect(map.getZoom()).toEqual(center.zoom);
69-
expect(map.getCenter().lat).toBeCloseTo(0.96658, 4);
70-
return expect(map.getCenter().lng).toBeCloseTo(2.02, 4);
71-
});
72-
});
73-
74-
it('should update the map center if the scope center properties changes', function() {
75-
var element, map;
76-
element = angular.element('<leaflet ' + directiveName + '=\'center\'></leaflet>');
77-
element = $compile(element)(scope);
78-
map = void 0;
79-
leafletData.getMap().then(function(leafletMap) {
80-
return map = leafletMap;
81-
});
82-
83-
scope.$apply();
84-
expect(map.getCenter().lat).toBeCloseTo(0.96658, 4);
85-
expect(map.getCenter().lng).toBeCloseTo(2.02, 4);
86-
expect(map.getZoom()).toEqual(4);
87-
center.lat = 2.02999;
88-
center.lng = 4.04;
89-
center.zoom = 8;
90-
scope.$digest();
91-
expect(map.getCenter().lat).toBeCloseTo(2.02999, 4);
92-
expect(map.getCenter().lng).toBeCloseTo(4.04, 4);
93-
return expect(map.getZoom()).toEqual(8);
94-
});
95-
96-
return describe('Using url-hash functionality', function() {
97-
return it('should update the center of the map if changes the url', function() {
98-
var centerParams, element, map;
99-
element = angular.element('<leaflet ' + directiveName + '=\'center\' url-hash-center=\'yes\'></leaflet>');
100-
element = $compile(element)(scope);
101-
map = void 0;
102-
leafletData.getMap().then(function(leafletMap) {
103-
return map = leafletMap;
104-
});
105-
106-
centerParams = {
107-
c: '30.1' + ':' + '-9.2' + ':' + '4',
108-
};
109-
$location.search(centerParams);
110-
scope.$digest();
111-
expect(map.getCenter().lat).toBeCloseTo(30.1, 4);
112-
expect(map.getCenter().lng).toBeCloseTo(-9.2, 4);
113-
return expect(map.getZoom()).toEqual(4);
114-
});
115-
});
116-
});
117-
118-
return describe('sets scope from leaflet', function() {
119-
it('should update the url hash if changes the center', function() {
120-
var centerUrlHash, element;
121-
element = angular.element('<leaflet ' + directiveName + '=\'center\' url-hash-center=\'yes\'></leaflet>');
122-
element = $compile(element)(scope);
123-
scope.center = {
124-
lat: 9.52478,
125-
lng: -1.8,
126-
zoom: 8,
127-
};
128-
centerUrlHash = void 0;
129-
scope.$on('centerUrlHash', function(event, u) {
130-
return centerUrlHash = u;
131-
});
132-
133-
scope.$digest();
134-
return expect(centerUrlHash).toBe('9.5248:-1.8000:8');
135-
});
136-
137-
return it('should update the scope.center if leaflet map is moved', function(done) {
138-
var element;
139-
element = angular.element('<leaflet ' + directiveName + '=\'center\'></leaflet>');
140-
element = $compile(element)(scope);
141-
this.digest(scope, function() {
142-
return leafletData.getMap().then(function(map) {
143-
expect(map.getZoom()).toEqual(center.zoom);
144-
expect(map.getCenter().lat).toBeCloseTo(0.96658, 4);
145-
expect(map.getCenter().lng).toBeCloseTo(2.02, 4);
146-
return map.setView(L.latLng(50.5, 30.5));
147-
});
148-
});
149-
150-
this.digest(scope, function() {
151-
return leafletData.getMap().then(function(map) {
152-
expect(scope.center.lat).toBe(50.5);
153-
expect(scope.center.lng).toBe(30.5);
154-
return map.setView(L.latLng(51.5, 31.5));
155-
});
156-
});
157-
158-
return this.digest(scope, function() {
159-
return leafletData.getMap().then(function(map) {
160-
expect(scope.center.lat).toBe(51.5);
161-
expect(scope.center.lng).toBe(31.5);
162-
return done();
163-
});
164-
});
165-
});
166-
});
167-
}));
168-
}
169-
170-
return results;
108+
it('should update the url hash if changes the center', function() {
109+
var element = angular.element('<leaflet center="center" url-hash-center="yes"></leaflet>');
110+
element = $compile(element)(scope);
111+
scope.center = { lat: 9.52478, lng: -1.8, zoom: 8 };
112+
var centerUrlHash;
113+
scope.$on('centerUrlHash', function(event, u) {
114+
centerUrlHash = u;
115+
});
116+
117+
scope.$digest();
118+
expect(centerUrlHash).toBe('9.5248:-1.8000:8');
119+
});
171120
});
121+
});

test/unit/030-tilesDirectiveSpec.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
/* jasmine specs for directives go here */
66

77
describe('Directive: leaflet', function() {
8-
var $compile, $rootScope, leafletData, leafletMapDefaults, scope;
8+
var $compile;
9+
var $rootScope;
10+
var leafletData;
11+
var leafletMapDefaults;
12+
var scope;
913

1014
beforeEach(module('leaflet-directive'));
1115
beforeEach(inject(function(_$compile_, _$rootScope_, _leafletData_, _leafletMapDefaults_) {

test/unit/040-maxboundsDirectiveSpec.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
/* jasmine specs for directives go here */
66

77
describe('Directive: leaflet', function() {
8-
var $compile = null, $rootScope = null, $timeout, leafletData = null, leafletMapDefaults = null;
8+
var $compile = null;
9+
var $rootScope = null;
10+
var $timeout;
11+
var leafletData = null;
12+
var leafletMapDefaults = null;
913

1014
beforeEach(module('leaflet-directive'));
1115
beforeEach(inject(function(_$compile_, _$rootScope_, _$timeout_, _leafletData_, _leafletMapDefaults_) {

test/unit/050-pathsDirectiveSpec.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
/* jasmine specs for directives go here */
66

77
describe('Directive: leaflet', function() {
8-
var $compile, $rootScope, leafletData, scope;
8+
var $compile;
9+
var $rootScope;
10+
var leafletData;
11+
var scope;
912

1013
beforeEach(function() {
1114
module('leaflet-directive');

test/unit/060-decorationsDirectiveSpec.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
/* jasmine specs for directives go here */
66

77
describe('Directive: decorations', function() {
8-
var $compile, $rootScope, leafletData, leafletHelpers, mainCoordinates, mainDecorations;
8+
var $compile;
9+
var $rootScope;
10+
var leafletData;
11+
var leafletHelpers;
12+
var mainCoordinates;
13+
var mainDecorations;
914

1015
beforeEach(module('leaflet-directive'));
1116
beforeEach(inject(function(_$compile_, _$rootScope_, _leafletData_, _leafletHelpers_) {

test/unit/090-eventsDirectiveSpec.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
/* jasmine specs for directives go here */
66

77
describe('Directive: leaflet', function() {
8-
var $compile = null, $rootScope = null, leafletData = null, leafletHelpers = null, $log = null;
8+
var $compile = null;
9+
var $rootScope = null;
10+
var leafletData = null;
11+
var leafletHelpers = null;
12+
var $log = null;
913

1014
beforeEach(module('leaflet-directive'));
1115
beforeEach(inject(function(_$compile_, _$rootScope_, _leafletData_, _leafletHelpers_, _$log_) {

0 commit comments

Comments
 (0)