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 (
33+ '<gm-map options="{center: [37, -122], zoom: 8}">' +
34+ '<gm-directions origin="origin" destination="destination" travelMode="travelMode" options="{origin: \'from\', destination: \'to\', travelMode: \'mode\'}">' +
35+ template +
36+ '</gm-directions>' +
37+ '</gm-map>' ) ( $scope ) ;
38+ $scope . $digest ( ) ;
39+ $timeout . flush ( ) ;
40+ element = element . find ( 'gm-renderer' ) ;
41+ scope = element . scope ( ) ;
42+ }
43+
44+ it ( 'test rendering with update' , function ( done ) {
45+ compile ( '<gm-renderer></gm-renderer>' ) ;
46+
47+ setTimeout ( function ( ) {
48+ $rootScope . $digest ( ) ; // required to get the directions promise run
49+ expect ( scope . map instanceof googleMaps . Map ) . to . be . equal ( true ) ;
50+ expect ( scope . renderer instanceof googleMaps . DirectionsRenderer ) . to . be . equal ( true ) ;
51+
52+ expect ( scope . renderer . getDirections ( ) . options . origin ) . to . be . equal ( 'from' ) ;
53+ expect ( scope . renderer . getDirections ( ) . options . destination ) . to . be . equal ( 'to' ) ;
54+ expect ( scope . renderer . getDirections ( ) . options . travelMode ) . to . be . equal ( 'mode' ) ;
55+
56+ $scope . origin = 'from2' ;
57+ $scope . destination = 'to2' ;
58+ $scope . travelMode = 'mode2' ;
59+ $rootScope . $digest ( ) ; // required to get the directions promise run
60+
61+ setTimeout ( function ( ) {
62+ expect ( scope . renderer . getDirections ( ) . options . origin ) . to . be . equal ( 'from2' ) ;
63+ expect ( scope . renderer . getDirections ( ) . options . destination ) . to . be . equal ( 'to2' ) ;
64+ expect ( scope . renderer . getDirections ( ) . options . travelMode ) . to . be . equal ( 'mode2' ) ;
65+
66+ $scope . origin = 'from2' ;
67+ $rootScope . $digest ( ) ; // required to get the directions promise run
68+
69+ done ( ) ;
70+ } , 10 ) ;
71+
72+ } , 10 ) ;
73+ } ) ;
74+
75+ } ) ;
0 commit comments