diff --git a/app/main/posts/modify/location.directive.js b/app/main/posts/modify/location.directive.js
index 3204db6c14..703cf70b70 100644
--- a/app/main/posts/modify/location.directive.js
+++ b/app/main/posts/modify/location.directive.js
@@ -122,7 +122,10 @@ function PostLocationDirective($http, L, Geocoding, Maps, _, Notify, $window) {
function clear() {
$scope.model = null;
- marker.remove();
+ if (marker) {
+ map.removeLayer(marker);
+ marker = null;
+ }
}
}
}
diff --git a/test/unit/main/post/modify/post-location.directive.spec.js b/test/unit/main/post/modify/location.directive.spec.js
similarity index 56%
rename from test/unit/main/post/modify/post-location.directive.spec.js
rename to test/unit/main/post/modify/location.directive.spec.js
index 700ab0614f..61dfe7d5ad 100644
--- a/test/unit/main/post/modify/post-location.directive.spec.js
+++ b/test/unit/main/post/modify/location.directive.spec.js
@@ -1,3 +1,8 @@
+var L = require('leaflet');
+// Load leaflet plugins here too
+require('imports?L=leaflet!leaflet.markercluster');
+require('imports?L=leaflet!leaflet.locatecontrol/src/L.Control.Locate');
+
describe('post location directive', function () {
var $rootScope,
@@ -5,67 +10,67 @@ describe('post location directive', function () {
isolateScope,
Notify,
element,
- Geocoding;
+ Geocoding,
+ Maps,
+ map,
+ marker;
beforeEach(function () {
fixture.setBase('mocked_backend/api/v3');
+ Maps = {
+ createMap: function () {}
+ };
var testApp = makeTestApp();
- testApp.directive('postLocation', require('app/main/posts/modify/post-location.directive'));
+ testApp.directive('postLocation', require('app/main/posts/modify/location.directive'))
+ .service('Leaflet', () => {
+ return L;
+ })
+ .service('Maps', () => {
+ return Maps;
+ })
+ .value('Geocoding', {
+ search: function (searchLocationTerm) {}
+ })
+ ;
angular.mock.module('testApp');
});
-
-
- beforeEach(function () {
- angular.mock.module(function ($provide) {
-
- $provide.value('Geocoding', {
- search: function (searchLocationTerm) {}
- });
-
- $provide.value('leafletData', {
- getMap: function (mapName) {
- return {
- then: function (callback) {
- return angular.element();
- }
- };
- }
- });
-
- $provide.value('Leaflet', {
- control: {
- locate: function (opts) {
- return {
- addTo: function (m) {}
- };
- }
- }
- });
- });
- });
-
- beforeEach(angular.mock.inject(function (_$rootScope_, $compile, _Notify_, _Geocoding_) {
+ beforeEach(angular.mock.inject(function (_$rootScope_, $compile, _Notify_, _Geocoding_, _Maps_, $q) {
$rootScope = _$rootScope_;
- $scope = _$rootScope_.$new();
-
Notify = _Notify_;
Geocoding = _Geocoding_;
- $scope.post = {};
- $scope.model = {};
- element = '';
+ map = L.map(document.createElement('div'));
+ marker = L.marker([7,7]);
+ spyOn(Maps, 'createMap').and.returnValue($q.when(map));
+ spyOn(map, 'setView').and.callThrough();
+ spyOn(L, 'marker').and.returnValue(marker);
+ spyOn(marker, 'setLatLng').and.callThrough();
+ spyOn(marker, 'addTo').and.callThrough();
+
+ $scope = _$rootScope_.$new();
+ $scope.model = {
+ lat: 3,
+ lon: 4
+ };
+
+ element = '';
element = $compile(element)($scope);
$scope.$digest();
isolateScope = element.children().scope();
-
}));
describe('test directive functions', function () {
+ it('should init map', function () {
+ expect(Maps.createMap).toHaveBeenCalled();
+ expect(L.marker).toHaveBeenCalled();
+ expect(marker.addTo).toHaveBeenCalledWith(map);
+ });
+
it('should not clear search location term for failed searches', function () {
isolateScope.$apply(function () {
isolateScope.searchLocationTerm = 'Lorem';
@@ -101,11 +106,7 @@ describe('post location directive', function () {
expect(isolateScope.searchLocationTerm).toEqual('');
});
- it('should call updateLatLon, updateMarkerPosition and centerMapTo on successful search', function () {
- spyOn(isolateScope, 'updateLatLon');
- spyOn(isolateScope, 'updateMarkerPosition');
- spyOn(isolateScope, 'centerMapTo');
-
+ it('should call update model, marker position and map center', function () {
spyOn(Geocoding, 'search').and.callFake(function (kupi) {
return {
then: function (callback) {
@@ -116,28 +117,22 @@ describe('post location directive', function () {
isolateScope.searchLocation();
- expect(isolateScope.updateLatLon).toHaveBeenCalledWith(1, 2);
- expect(isolateScope.updateMarkerPosition).toHaveBeenCalledWith(1, 2);
- expect(isolateScope.centerMapTo).toHaveBeenCalledWith(1, 2);
+ expect(isolateScope.model.lat).toEqual(1);
+ expect(isolateScope.model.lon).toEqual(2);
+ expect(marker.setLatLng).toHaveBeenCalledWith([1, 2]);
+ expect(map.setView).toHaveBeenCalledWith([1, 2], 8);
});
- it('should clear scope model, center and markers when Clear button is pressed', function () {
+ it('should clear scope model, and remove the marker', function () {
isolateScope.$apply(function () {
isolateScope.model = { lat: 100, lng: 200 };
- isolateScope.initialCenter = { lat: 100, lng: 200 };
- isolateScope.center = { lat: 20, lng: 30 };
-
- isolateScope.markers = {
- m1 : { lat: 40, lng: 50 }
- };
});
isolateScope.clear();
expect(isolateScope.model).toBeNull();
- expect(isolateScope.center).toEqual(isolateScope.initialCenter);
- expect(isolateScope.markers).toEqual({});
+ expect(marker.remove).toBeCalled;
});
});
diff --git a/test/unit/main/post/views/post-view-map.directive.spec.js b/test/unit/main/post/views/post-view-map.directive.spec.js
index 5bbb1cf1b6..462f036445 100644
--- a/test/unit/main/post/views/post-view-map.directive.spec.js
+++ b/test/unit/main/post/views/post-view-map.directive.spec.js
@@ -1,9 +1,16 @@
+var L = require('leaflet');
describe('post view map directive', function () {
var $rootScope,
$scope,
+ $compile,
isolateScope,
Notify,
+ Maps,
+ PostEndpoint,
+ map,
+ geojson,
+ markers,
element;
beforeEach(function () {
@@ -13,31 +20,94 @@ describe('post view map directive', function () {
var testApp = makeTestApp();
testApp.directive('postViewMap', require('app/main/posts/views/post-view-map.directive'))
- .value('$filter', function () {
- return function () {};
- })
- .value('PostEntity', {});
+ .value('Leaflet', L)
+ ;
angular.mock.module('testApp');
});
+ beforeEach(angular.mock.inject(function (_$rootScope_, _$compile_, _Notify_, _Maps_, _PostEndpoint_, $q) {
+ $rootScope = _$rootScope_;
+ $compile = _$compile_;
+ Notify = _Notify_;
+ Maps = _Maps_;
+ PostEndpoint = _PostEndpoint_;
+ map = L.map(document.createElement('div'), {
+ center: [0,1],
+ zoom: 5,
+ layers: [L.tileLayer('http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png')]
+ });
+ spyOn(Maps, 'createMap').and.returnValue($q.when(map));
+ var lgeoJson = L.geoJson;
+ spyOn(L, 'geoJson').and.callFake(function (args) {
+ geojson = lgeoJson(args);
+ spyOn(geojson, 'addTo').and.callThrough();
- beforeEach(angular.mock.inject(function (_$rootScope_, $compile, _Notify_) {
- $rootScope = _$rootScope_;
- $scope = _$rootScope_.$new();
+ return geojson;
+ });
+ var markerClusterGroup = L.markerClusterGroup;
+ spyOn(L, 'markerClusterGroup').and.callFake(function (args) {
+ markers = markerClusterGroup(args);
+ spyOn(markers, 'addTo').and.callThrough();
- Notify = _Notify_;
+ return markers;
+ });
+ spyOn(PostEndpoint, 'geojson').and.callThrough();
+
+ $scope = _$rootScope_.$new();
$scope.isLoading = true;
$scope.filters = {};
+
element = '';
+ }));
+ it('should create a map', function () {
element = $compile(element)($scope);
$rootScope.$digest();
isolateScope = element.isolateScope();
- }));
- it('should load initial values', function () {
- expect(isolateScope.isLoading).toBe(false);
+ expect(Maps.createMap).toHaveBeenCalled();
+ });
+
+ it('should load geojson data and add it to the map', function () {
+ map.options.clustering = false;
+
+ element = $compile(element)($scope);
+ $rootScope.$digest();
+ isolateScope = element.isolateScope();
+
+ expect(PostEndpoint.geojson).toHaveBeenCalled();
+ expect(L.geoJson).toHaveBeenCalled();
+ expect(geojson.addTo).toHaveBeenCalledWith(map);
+ });
+
+ it('should load geojson data and add clusters to the map', function () {
+ map.options.clustering = true;
+
+ element = $compile(element)($scope);
+ $rootScope.$digest();
+ isolateScope = element.isolateScope();
+
+ expect(PostEndpoint.geojson).toHaveBeenCalled();
+ expect(L.geoJson).toHaveBeenCalled();
+ expect(L.markerClusterGroup).toHaveBeenCalled();
+ expect(markers.addTo).toHaveBeenCalledWith(map);
+ });
+
+ it('reload geojson when filters change', function () {
+ element = $compile(element)($scope);
+ $rootScope.$digest();
+ isolateScope = element.isolateScope();
+
+ isolateScope.$apply(function () {
+ isolateScope.filters = {
+ status : 'published'
+ };
+ });
+
+ expect(L.geoJson).toHaveBeenCalled();
+ expect(L.geoJson.calls.count()).toEqual(2);
+ expect(geojson.addTo).toHaveBeenCalledWith(map);
});
});
diff --git a/test/unit/mock/mock-modules.js b/test/unit/mock/mock-modules.js
index f6af89db63..aa7997742e 100644
--- a/test/unit/mock/mock-modules.js
+++ b/test/unit/mock/mock-modules.js
@@ -1,6 +1,6 @@
angular.module('ushahidi.mock', [])
.provider('$translate', require('./services/translate.js'))
-.service('leafletData', require('./services/third_party/leaflet-data.js'))
+.service('Leaflet', require('./services/third_party/leaflet.js'))
.service('d3', require('./services/third_party/d3.js'))
.service('moment', require('./services/third_party/moment.js'))
diff --git a/test/unit/mock/services/maps.js b/test/unit/mock/services/maps.js
index 0f918772f5..f1e477f7a4 100644
--- a/test/unit/mock/services/maps.js
+++ b/test/unit/mock/services/maps.js
@@ -1,59 +1,11 @@
-module.exports = [function () {
+module.exports = ['$q', function ($q) {
return {
- getMap: function () {
- return {
- reloadPosts: function (posts) {},
- getMinZoom: function () {
- return 0;
- },
- getMaxZoom: function () {
- return 0;
- },
- init: function () {
-
- }
- };
- },
- destroyMap: function () {
-
- },
- getInitialScope: function () {
- return {
- layers : {
- baselayers : {
- mapQuest : {
- name: 'Map',
- url: 'http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.png',
- type: 'xyz',
- layerOptions: {
- subdomains: '1234',
- attribution: 'Map data © OpenStreetMap contributors, Imagery © MapQuest'
- }
- }
- }
- },
- center: {
- lat: 0,
- lon: 0,
- zoom: 3
- }
- };
- },
- getAngularScopeParams : function () {
- return {
- then: function (successCallback) {
- successCallback({
- centre: {
- lat: -1.3048035,
- lng: 36.8473969,
- zoom: 3
- },
- layers: {
- baselayers: {}
+ createMap: function () {
+ return $q.when({
+ options: {
+ clustering: false
}
});
- }
- };
},
getConfig: function () {
return {
@@ -74,6 +26,35 @@ module.exports = [function () {
});
}
};
+ },
+ getBaseLayers: function () {
+ return {
+ satellite: {
+ name: 'Satellite',
+ url: 'https://api.tiles.mapbox.com/v4/{mapid}/{z}/{x}/{y}.png?access_token={apikey}',
+ layerOptions: {
+ apikey: 'abc123',
+ mapid: 'mapbox.satellite',
+ attribution: '© OpenStreetMap, © Mapbox'
+ }
+ },
+ streets: {
+ name: 'Streets',
+ url: 'https://api.tiles.mapbox.com/v4/{mapid}/{z}/{x}/{y}.png?access_token={apikey}',
+ layerOptions: {
+ apikey: 'abc123',
+ mapid: 'mapbox.streets',
+ attribution: '© OpenStreetMap, © Mapbox'
+ }
+ },
+ hOSM: {
+ name: 'Humanitarian',
+ url: 'http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png',
+ layerOptions: {
+ attribution: 'Map data © OpenStreetMap, Tiles Humanitarian OpenStreetMap Team'
+ }
+ }
+ };
}
};
}];
diff --git a/test/unit/mock/services/post.js b/test/unit/mock/services/post.js
index 5c1258a33d..6307f75074 100644
--- a/test/unit/mock/services/post.js
+++ b/test/unit/mock/services/post.js
@@ -1,4 +1,4 @@
-module.exports = [function () {
+module.exports = ['$q', function ($q) {
return {
query: function () {
return {$promise: {
@@ -38,18 +38,11 @@ module.exports = [function () {
}};
},
geojson: function () {
- return {$promise: {
- then: function (successCallback, failCallback) {
- successCallback({
- features: [
- {
- 'type': 'Feature',
- 'properties': {}
- }
- ]
- });
- }
- }};
+ return {
+ /* jshint ignore:start */
+ $promise: $q.when({"type": "FeatureCollection","features": [{"type": "Feature","geometry": {"type": "GeometryCollection","geometries": [{"type": "Point","coordinates": [-122.330062,47.603832]}]},"properties": {"title": "Testing our qa twitter account","description": "Testing our qa twitter account\n\n#ushahidiqatest","marker-color": "#E69327","id": 2600,"url": "http:\/\/qa.api.ushahididev.com\/api\/v3\/posts\/2600"}},{"type": "Feature","geometry": {"type": "GeometryCollection","geometries": [{"type": "Point","coordinates": [-81.707703,30.063236]}]},"properties": {"title": "Masonry","description": "785275","marker-color": "#E69327","id": 2573,"url": "http:\/\/qa.api.ushahididev.com\/api\/v3\/posts\/2573"}},{"type": "Feature","geometry": {"type": "GeometryCollection","geometries": [{"type": "Point","coordinates": [-81.707146,30.102217]}]},"properties": {"title": "Wood","description": "223488","marker-color": "#E69327","id": 2575,"url": "http:\/\/qa.api.ushahididev.com\/api\/v3\/posts\/2575"}},{"type": "Feature","geometry": {"type": "GeometryCollection","geometries": [{"type": "Point","coordinates": [-81.704613,30.118774]}]},"properties": {"title": "Edited","description": "433512","marker-color": "#E69327","id": 2576,"url": "http:\/\/qa.api.ushahididev.com\/api\/v3\/posts\/2576"}},{"type": "Feature","geometry": {"type": "GeometryCollection","geometries": [{"type": "Point","coordinates": [-81.700455,30.089579]}]},"properties": {"title": "Wood","description": "206893","marker-color": "#E69327","id": 2570,"url": "http:\/\/qa.api.ushahididev.com\/api\/v3\/posts\/2570"}},{"type": "Feature","geometry": {"type": "GeometryCollection","geometries": [{"type": "Point","coordinates": [77.531287,13.075209]},{"type": "Point","coordinates": [77.531287,13.075209]}]},"properties": {"title": "post via twitter","description": "#publicpolicy making in the #digital age https:\/\/t.co\/maAwmik3Zz #PolicyMakers #policymaking #ICT #ICT4D #ICT4D2016 #ICT4Dev #techforgood","marker-color": "#E69327","id": 2527,"url": "http:\/\/qa.api.ushahididev.com\/api\/v3\/posts\/2527"}},{"type": "Feature","geometry": {"type": "GeometryCollection","geometries": [{"type": "Point","coordinates": [-81.711777,30.102261]}]},"properties": {"title": "119736","description": "Masonry","marker-color": "#E69327","id": 2508,"url": "http:\/\/qa.api.ushahididev.com\/api\/v3\/posts\/2508"}},{"type": "Feature","geometry": {"type": "GeometryCollection","geometries": [{"type": "Point","coordinates": [-81.702675,30.060614]}]},"properties": {"title": "172534","description": "Wood","marker-color": "#E69327","id": 2512,"url": "http:\/\/qa.api.ushahididev.com\/api\/v3\/posts\/2512"}},{"type": "Feature","geometry": {"type": "GeometryCollection","geometries": [{"type": "Point","coordinates": [-81.707703,30.063236]}]},"properties": {"title": "785275","description": "Masonry","marker-color": "#E69327","id": 2513,"url": "http:\/\/qa.api.ushahididev.com\/api\/v3\/posts\/2513"}},{"type": "Feature","geometry": {"type": "GeometryCollection","geometries": [{"type": "Point","coordinates": [-81.713882,30.102226]}]},"properties": {"title": "995932","description": "Reinforced Concrete","marker-color": "#E69327","id": 2514,"url": "http:\/\/qa.api.ushahididev.com\/api\/v3\/posts\/2514"}},{"type": "Feature","geometry": {"type": "GeometryCollection","geometries": [{"type": "Point","coordinates": [-81.707664,30.063936]}]},"properties": {"title": "Masonry","description": "448094","marker-color": "#E69327","id": 2446,"url": "http:\/\/qa.api.ushahididev.com\/api\/v3\/posts\/2446"}},{"type": "Feature","geometry": {"type": "GeometryCollection","geometries": [{"type": "Point","coordinates": [-81.700455,30.089579]}]},"properties": {"title": "Wood","description": "206893","marker-color": "#E69327","id": 2447,"url": "http:\/\/qa.api.ushahididev.com\/api\/v3\/posts\/2447"}},{"type": "Feature","geometry": {"type": "GeometryCollection","geometries": [{"type": "Point","coordinates": [-81.707703,30.063236]}]},"properties": {"title": "Wood","description": "333743","marker-color": "#E69327","id": 2448,"url": "http:\/\/qa.api.ushahididev.com\/api\/v3\/posts\/2448"}},{"type": "Feature","geometry": {"type": "GeometryCollection","geometries": [{"type": "Point","coordinates": [-81.702675,30.060614]}]},"properties": {"title": "Wood","description": "172534","marker-color": "#E69327","id": 2449,"url": "http:\/\/qa.api.ushahididev.com\/api\/v3\/posts\/2449"}},{"type": "Feature","geometry": {"type": "GeometryCollection","geometries": [{"type": "Point","coordinates": [-81.707703,30.063236]}]},"properties": {"title": "Masonry","description": "785275","marker-color": "#E69327","id": 2450,"url": "http:\/\/qa.api.ushahididev.com\/api\/v3\/posts\/2450"}},{"type": "Feature","geometry": {"type": "GeometryCollection","geometries": [{"type": "Point","coordinates": [-81.713882,30.102226]}]},"properties": {"title": "Reinforced Concrete","description": "995932","marker-color": "#E69327","id": 2451,"url": "http:\/\/qa.api.ushahididev.com\/api\/v3\/posts\/2451"}},{"type": "Feature","geometry": {"type": "GeometryCollection","geometries": [{"type": "Point","coordinates": [-81.711777,30.102261]}]},"properties": {"title": "Masonry","description": "119736","marker-color": "#E69327","id": 2427,"url": "http:\/\/qa.api.ushahididev.com\/api\/v3\/posts\/2427"}},{"type": "Feature","geometry": {"type": "GeometryCollection","geometries": [{"type": "Point","coordinates": [-81.702675,30.060614]}]},"properties": {"title": "Wood","description": "172534","marker-color": "#E69327","id": 2431,"url": "http:\/\/qa.api.ushahididev.com\/api\/v3\/posts\/2431"}},{"type": "Feature","geometry": {"type": "GeometryCollection","geometries": [{"type": "Point","coordinates": [-81.707703,30.063236]}]},"properties": {"title": "Masonry","description": "785275","marker-color": "#E69327","id": 2432,"url": "http:\/\/qa.api.ushahididev.com\/api\/v3\/posts\/2432"}},{"type": "Feature","geometry": {"type": "GeometryCollection","geometries": [{"type": "Point","coordinates": [-81.713882,30.102226]}]},"properties": {"title": "Reinforced Concrete","description": "995932","marker-color": "#E69327","id": 2433,"url": "http:\/\/qa.api.ushahididev.com\/api\/v3\/posts\/2433"}},{"type": "Feature","geometry": {"type": "GeometryCollection","geometries": [{"type": "Point","coordinates": [-122.330062,47.603832]}]},"properties": {"title": "jess testing radio button fix","description": "radio button pattern should match pattern library","marker-color": "#A51A1A","id": 2287,"url": "http:\/\/qa.api.ushahididev.com\/api\/v3\/posts\/2287"}},{"type": "Feature","geometry": {"type": "GeometryCollection","geometries": [{"type": "Point","coordinates": [36.817245,-1.283253]}]},"properties": {"title": "Sample post type from Angie","description": "This is my sample image post","marker-color": "#2274B4","id": 24,"url": "http:\/\/qa.api.ushahididev.com\/api\/v3\/posts\/24"}}]})
+ /* jshint ignore:end */
+ };
},
get: function () {
return {$promise: {
diff --git a/test/unit/mock/services/third_party/leaflet-data.js b/test/unit/mock/services/third_party/leaflet-data.js
deleted file mode 100644
index e78f2f9c48..0000000000
--- a/test/unit/mock/services/third_party/leaflet-data.js
+++ /dev/null
@@ -1,37 +0,0 @@
-module.exports = [function () {
- return {
- getMap: function () {
- return {
- then: function (successCallback, failCallback) {
- successCallback({
- setZoom: function () {},
- getMinZoom: function () {
- return 0;
- },
- getMaxZoom: function () {
- return 0;
- },
- getZoom: function () {
- return 0;
- },
- fitBounds: function () {},
- attributionControl: {
- setPrefix: function () {}
- }
- });
- }
- };
- },
- getGeoJSON : function () {
- return {
- then: function (successCallback, failCallback) {
- successCallback({
- getBounds: function () {
- return [];
- }
- });
- }
- };
- }
- };
-}];
diff --git a/test/unit/mock/services/third_party/leaflet.js b/test/unit/mock/services/third_party/leaflet.js
new file mode 100644
index 0000000000..d196ae0bb6
--- /dev/null
+++ b/test/unit/mock/services/third_party/leaflet.js
@@ -0,0 +1,10 @@
+module.exports = [function () {
+ return {
+ geoJson : function () {
+
+ },
+ markerClusterGroup : function () {
+
+ }
+ };
+}];
diff --git a/test/unit/settings/site/setting-map-directive-spec.js b/test/unit/settings/site/setting-map-directive-spec.js
index e31cf0980c..39832d22c7 100644
--- a/test/unit/settings/site/setting-map-directive-spec.js
+++ b/test/unit/settings/site/setting-map-directive-spec.js
@@ -1,53 +1,105 @@
+var L = require('leaflet');
describe('setting map directive', function () {
var $rootScope,
$scope,
isolateScope,
- element;
+ element,
+ Leaflet,
+ Maps,
+ map,
+ marker;
beforeEach(function () {
fixture.setBase('mocked_backend/api/v3');
-
var testApp = makeTestApp();
testApp.directive('settingsMap', require('app/settings/site/map.directive'))
.value('$filter', function () {
return function () {};
})
- .value('PostEntity', {});
+ .value('PostEntity', {})
+ .value('Leaflet', L);
angular.mock.module('testApp');
});
- beforeEach(angular.mock.inject(function (_$rootScope_, $compile) {
+ beforeEach(angular.mock.inject(function (_$rootScope_, $compile, _Maps_, _Leaflet_, $q) {
$rootScope = _$rootScope_;
+ Leaflet = _Leaflet_;
$scope = _$rootScope_.$new();
+ $scope.map = {};
+
+ Maps = _Maps_;
+ spyOn(Maps, 'createMap').and.returnValue({
+ then: (cb) => {
+ cb(map);
+ }
+ });
+ spyOn(Maps, 'getConfig').and.returnValue($q.when({
+ default_view: {
+ lat: 3,
+ lon: 4,
+ zoom: 10
+ },
+ clustering: false
+ }));
+ map = L.map(document.createElement('div'), {
+ center: [0,1],
+ zoom: 5,
+ layers: [L.tileLayer('http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png')]
+ });
+ marker = L.marker([7,7]);
+ spyOn(map, 'setView').and.callThrough();
+ spyOn(L, 'marker').and.returnValue(marker);
+ spyOn(marker, 'setLatLng').and.callThrough();
+ spyOn(marker, 'addTo').and.callThrough();
- element = '';
+ element = '';
element = $compile(element)($scope);
$scope.$digest();
isolateScope = element.isolateScope();
}));
- it('should have template markup', function () {
- var baseLayerSelect = element.find('#map-settings-base-layer');
- expect(baseLayerSelect).toBeDefined();
+ it('should create a map', function () {
+ expect(Maps.createMap).toHaveBeenCalled();
+ expect(L.marker).toHaveBeenCalled();
+ expect(marker.addTo).toHaveBeenCalledWith(map);
+ });
+
+ it('should set scope.config to map config', function () {
+ expect(isolateScope.config).toEqual({
+ default_view: {
+ lat: 3,
+ lon: 4,
+ zoom: 10
+ },
+ clustering: false
+ });
+ });
+
+ it('should update config when zoom changes', function () {
+ map.setZoom(7);
+ expect(isolateScope.config.default_view.zoom).toEqual(7);
});
- it('should set markers', function () {
- expect(isolateScope.markers.dragger.lat).toEqual(-1.3048035);
+ it('should update map when zoom changes', function () {
+ isolateScope.config.default_view.zoom = 9;
+ isolateScope.updateMapPreview();
+ expect(map.setView).toHaveBeenCalledWith([3, 4], 9);
});
- it('should set min and max zoom level', function () {
- expect(isolateScope.minZoom).toEqual(0);
- expect(isolateScope.maxZoom).toEqual(0);
+ it('should update marker when lat/lon changes', function () {
+ isolateScope.config.default_view.lat = 48;
+ isolateScope.config.default_view.lon = 36;
+ isolateScope.updateMapPreview();
+ expect(marker.setLatLng).toHaveBeenCalledWith([48, 36]);
});
- it('should set centre', function () {
- expect(isolateScope.center.lat).toEqual(-1.3048035);
+ it('should save position when marker dragged', function () {
});
});