diff --git a/test/e2e/13-url-hash-center-example.js b/test/e2e/13-url-hash-center-example.js new file mode 100644 index 00000000..737e6caf --- /dev/null +++ b/test/e2e/13-url-hash-center-example.js @@ -0,0 +1,30 @@ +'use strict'; + +describe('Loading center-example.html', function() { + + var ptor, driver; + beforeEach(function() { + ptor = protractor.getInstance(); + browser.get('url-hash-center-example.html'); + driver = ptor.driver; + }, 30000); + + it('should update the url in the center value is changed from the form', function() { + element(by.xpath('//input[1]')).clear(); + element(by.xpath('//input[1]')).sendKeys('9'); + element(by.xpath('//input[2]')).clear(); + element(by.xpath('//input[2]')).sendKeys('7'); + element(by.xpath('//input[3]')).clear(); + element(by.xpath('//input[3]')).sendKeys('4'); + // Wait for zoom animation + ptor.sleep(300); + expect(browser.getCurrentUrl()).toMatch(/c=9.102096738726456:7.03125:14$/); + }); + + it('should update the map center model if the url changes', function() { + browser.get("url-hash-center-example.html#?c=9.102096738726456:7.03125:14"); + expect(element(by.xpath('//input[1]')).getAttribute("value")).toBe("9.102096738726456"); + expect(element(by.xpath('//input[2]')).getAttribute("value")).toBe("7.03125"); + expect(element(by.xpath('//input[3]')).getAttribute("value")).toBe("14"); + }); +}); diff --git a/test/unit/centerDirectiveSpec.js b/test/unit/centerDirectiveSpec.js index 8015ae68..08227e50 100755 --- a/test/unit/centerDirectiveSpec.js +++ b/test/unit/centerDirectiveSpec.js @@ -5,13 +5,14 @@ /* jasmine specs for directives go here */ describe('Directive: leaflet center', function() { - var $compile, $rootScope, $timeout, leafletData, center, scope; + var $compile, $rootScope, $timeout, $location, leafletData, center, scope; beforeEach(module('leaflet-directive')); - beforeEach(inject(function(_$compile_, _$rootScope_, _$timeout_, _leafletData_){ + beforeEach(inject(function(_$compile_, _$rootScope_, _$timeout_, _$location_, _leafletData_){ $compile = _$compile_; $rootScope = _$rootScope_; $timeout = _$timeout_; + $location = _$location_; leafletData = _leafletData_; })); @@ -78,4 +79,38 @@ describe('Directive: leaflet center', function() { expect(map.getZoom()).toEqual(8); }); + describe('Using url-hash functionality', function() { + it('should update the center of the map if changes the url', function() { + var element = angular.element(''); + element = $compile(element)(scope); + var map; + leafletData.getMap().then(function(leafletMap) { + map = leafletMap; + }); + + var centerParams = { + c: "30.1" + ":" + "-9.2" + ":" + "4" + }; + + $location.search(centerParams); + $rootScope.$digest(); + + expect(map.getCenter().lat).toBeCloseTo(30.1); + expect(map.getCenter().lng).toBeCloseTo(-9.2); + expect(map.getZoom()).toEqual(4); + }); + + it('should update the url hash if changes the center', function() { + var element = angular.element(''); + element = $compile(element)(scope); + var map; + leafletData.getMap().then(function(leafletMap) { + map = leafletMap; + }); + scope.center = { lat: 9.5, lng: -1.8, zoom: 8 }; + $rootScope.$digest(); + var location = $location.search(); + expect(location.c).toEqual('9.5:-1.8:8'); + }); + }); });