Skip to content
This repository has been archived by the owner on Sep 20, 2019. It is now read-only.

Commit

Permalink
feat(test): Added unitary tests and protractor tests for the new url-…
Browse files Browse the repository at this point in the history
…hash-center property
  • Loading branch information
tombatossals committed Mar 8, 2014
1 parent 212cb70 commit d43ff38
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
30 changes: 30 additions & 0 deletions test/e2e/13-url-hash-center-example.js
Original file line number Diff line number Diff line change
@@ -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");
});
});
39 changes: 37 additions & 2 deletions test/unit/centerDirectiveSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
}));

Expand Down Expand Up @@ -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('<leaflet center="center" url-hash-center="yes"></leaflet>');
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('<leaflet center="center" url-hash-center="yes"></leaflet>');
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');
});
});
});

0 comments on commit d43ff38

Please sign in to comment.