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

Commit d43ff38

Browse files
committed
feat(test): Added unitary tests and protractor tests for the new url-hash-center property
1 parent 212cb70 commit d43ff38

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
describe('Loading center-example.html', function() {
4+
5+
var ptor, driver;
6+
beforeEach(function() {
7+
ptor = protractor.getInstance();
8+
browser.get('url-hash-center-example.html');
9+
driver = ptor.driver;
10+
}, 30000);
11+
12+
it('should update the url in the center value is changed from the form', function() {
13+
element(by.xpath('//input[1]')).clear();
14+
element(by.xpath('//input[1]')).sendKeys('9');
15+
element(by.xpath('//input[2]')).clear();
16+
element(by.xpath('//input[2]')).sendKeys('7');
17+
element(by.xpath('//input[3]')).clear();
18+
element(by.xpath('//input[3]')).sendKeys('4');
19+
// Wait for zoom animation
20+
ptor.sleep(300);
21+
expect(browser.getCurrentUrl()).toMatch(/c=9.102096738726456:7.03125:14$/);
22+
});
23+
24+
it('should update the map center model if the url changes', function() {
25+
browser.get("url-hash-center-example.html#?c=9.102096738726456:7.03125:14");
26+
expect(element(by.xpath('//input[1]')).getAttribute("value")).toBe("9.102096738726456");
27+
expect(element(by.xpath('//input[2]')).getAttribute("value")).toBe("7.03125");
28+
expect(element(by.xpath('//input[3]')).getAttribute("value")).toBe("14");
29+
});
30+
});

test/unit/centerDirectiveSpec.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
/* jasmine specs for directives go here */
66

77
describe('Directive: leaflet center', function() {
8-
var $compile, $rootScope, $timeout, leafletData, center, scope;
8+
var $compile, $rootScope, $timeout, $location, leafletData, center, scope;
99

1010
beforeEach(module('leaflet-directive'));
11-
beforeEach(inject(function(_$compile_, _$rootScope_, _$timeout_, _leafletData_){
11+
beforeEach(inject(function(_$compile_, _$rootScope_, _$timeout_, _$location_, _leafletData_){
1212
$compile = _$compile_;
1313
$rootScope = _$rootScope_;
1414
$timeout = _$timeout_;
15+
$location = _$location_;
1516
leafletData = _leafletData_;
1617
}));
1718

@@ -78,4 +79,38 @@ describe('Directive: leaflet center', function() {
7879
expect(map.getZoom()).toEqual(8);
7980
});
8081

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+
});
81116
});

0 commit comments

Comments
 (0)