|
5 | 5 | /* jasmine specs for directives go here */ |
6 | 6 |
|
7 | 7 | describe('Directive: leaflet center', function() { |
8 | | - var $compile, $rootScope, $timeout, leafletData, center, scope; |
| 8 | + var $compile, $rootScope, $timeout, $location, leafletData, center, scope; |
9 | 9 |
|
10 | 10 | beforeEach(module('leaflet-directive')); |
11 | | - beforeEach(inject(function(_$compile_, _$rootScope_, _$timeout_, _leafletData_){ |
| 11 | + beforeEach(inject(function(_$compile_, _$rootScope_, _$timeout_, _$location_, _leafletData_){ |
12 | 12 | $compile = _$compile_; |
13 | 13 | $rootScope = _$rootScope_; |
14 | 14 | $timeout = _$timeout_; |
| 15 | + $location = _$location_; |
15 | 16 | leafletData = _leafletData_; |
16 | 17 | })); |
17 | 18 |
|
@@ -78,4 +79,38 @@ describe('Directive: leaflet center', function() { |
78 | 79 | expect(map.getZoom()).toEqual(8); |
79 | 80 | }); |
80 | 81 |
|
| 82 | + describe('Using url-hash functionality', function() { |
| 83 | + it('should update the center of the map if changes the url', function() { |
| 84 | + var element = angular.element('<leaflet center="center" url-hash-center="yes"></leaflet>'); |
| 85 | + element = $compile(element)(scope); |
| 86 | + var map; |
| 87 | + leafletData.getMap().then(function(leafletMap) { |
| 88 | + map = leafletMap; |
| 89 | + }); |
| 90 | + |
| 91 | + var centerParams = { |
| 92 | + c: "30.1" + ":" + "-9.2" + ":" + "4" |
| 93 | + }; |
| 94 | + |
| 95 | + $location.search(centerParams); |
| 96 | + $rootScope.$digest(); |
| 97 | + |
| 98 | + expect(map.getCenter().lat).toBeCloseTo(30.1); |
| 99 | + expect(map.getCenter().lng).toBeCloseTo(-9.2); |
| 100 | + expect(map.getZoom()).toEqual(4); |
| 101 | + }); |
| 102 | + |
| 103 | + it('should update the url hash if changes the center', function() { |
| 104 | + var element = angular.element('<leaflet center="center" url-hash-center="yes"></leaflet>'); |
| 105 | + element = $compile(element)(scope); |
| 106 | + var map; |
| 107 | + leafletData.getMap().then(function(leafletMap) { |
| 108 | + map = leafletMap; |
| 109 | + }); |
| 110 | + scope.center = { lat: 9.5, lng: -1.8, zoom: 8 }; |
| 111 | + $rootScope.$digest(); |
| 112 | + var location = $location.search(); |
| 113 | + expect(location.c).toEqual('9.5:-1.8:8'); |
| 114 | + }); |
| 115 | + }); |
81 | 116 | }); |
0 commit comments