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

Commit da554dc

Browse files
committed
Unit Tests: +directions
1 parent 3847473 commit da554dc

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

tests/moke.google.maps.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,14 @@ var google = (function () {
132132
}());
133133

134134

135+
maps.DirectionsService = function () {
136+
this.route = function (options, callback) {
137+
setTimeout(function () {
138+
callback({options: options}, 'status');
139+
});
140+
}
141+
};
142+
143+
135144
return {maps: maps}
136145
}());

tests/tests/directions.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
describe('gmDirections', function () {
2+
3+
var $compile, $rootScope, $scope, $timeout,
4+
element, scope, googleMaps;
5+
6+
7+
//---------------------------------------------------------------------------
8+
// Load Library
9+
//---------------------------------------------------------------------------
10+
11+
testTools.mokeGMLibrary();
12+
13+
14+
//---------------------------------------------------------------------------
15+
// Inject required
16+
//---------------------------------------------------------------------------
17+
beforeEach(inject(function(_$rootScope_, _$timeout_, _$compile_) {
18+
$rootScope = _$rootScope_;
19+
$timeout = _$timeout_;
20+
$compile = _$compile_;
21+
$scope = $rootScope.$new();
22+
googleMaps = $rootScope.google.maps;
23+
}));
24+
25+
26+
//---------------------------------------------------------------------------
27+
// TESTS
28+
//---------------------------------------------------------------------------
29+
30+
31+
function compile(template) {
32+
element = $compile('<gm-map options="{center: [37, -122], zoom: 8}">' + template + '</gm-map>')($scope);
33+
$scope.$digest();
34+
$timeout.flush();
35+
element = element.find('gm-directions');
36+
scope = element.scope();
37+
}
38+
39+
it('test simple case', function (done) {
40+
compile('<gm-directions destination="destination" options="{origin: \'from\', destination: \'to\', travelMode: \'mode\'}"></gm-directions>');
41+
42+
setTimeout(function() {
43+
expect(scope.directions).not.to.be.an('undefined');
44+
expect(scope.directions.result.options.origin).to.be.equal('from');
45+
expect(scope.directions.result.options.destination).to.be.equal('to');
46+
expect(scope.directions.result.options.travelMode).to.be.equal('mode');
47+
48+
done();
49+
}, 10);
50+
});
51+
52+
it('test mandatory properties', function (done) {
53+
compile('<gm-directions origin="o" destination="d" travelMode="t"></gm-directions>');
54+
55+
setTimeout(function() {
56+
expect(scope.directions).to.be.an('undefined');
57+
$scope.o = 'from';
58+
$scope.$digest();
59+
setTimeout(function() {
60+
expect(scope.directions).to.be.an('undefined');
61+
$scope.d = 'to';
62+
$scope.$digest();
63+
setTimeout(function() {
64+
expect(scope.directions).to.be.an('undefined');
65+
$scope.t = 'mode';
66+
$scope.$digest();
67+
setTimeout(function() {
68+
expect(scope.directions).not.to.be.an('undefined');
69+
expect(scope.directions.result.options.origin).to.be.equal('from');
70+
expect(scope.directions.result.options.destination).to.be.equal('to');
71+
expect(scope.directions.result.options.travelMode).to.be.equal('mode');
72+
done();
73+
}, 10);
74+
}, 10);
75+
}, 10);
76+
}, 10);
77+
});
78+
79+
});

0 commit comments

Comments
 (0)