@@ -2,16 +2,35 @@ import {Component} from '@angular/core';
2
2
import { async , TestBed } from '@angular/core/testing' ;
3
3
import { By } from '@angular/platform-browser' ;
4
4
5
- import { DEFAULT_HEIGHT , DEFAULT_OPTIONS , DEFAULT_WIDTH , GoogleMapModule } from './index' ;
5
+ import {
6
+ DEFAULT_HEIGHT ,
7
+ DEFAULT_OPTIONS ,
8
+ DEFAULT_WIDTH ,
9
+ GoogleMap ,
10
+ GoogleMapModule ,
11
+ UpdatedGoogleMap
12
+ } from './index' ;
6
13
import {
7
14
createMapConstructorSpy ,
8
15
createMapSpy ,
9
16
TestingWindow
10
17
} from './testing/fake-google-map-utils' ;
11
18
19
+ const TEST_BOUNDS : google . maps . LatLngBoundsLiteral = {
20
+ east : 12 ,
21
+ north : 13 ,
22
+ south : 14 ,
23
+ west : 15 ,
24
+ } ;
25
+
26
+ const TEST_POSITION : google . maps . LatLngLiteral = {
27
+ lat : 30 ,
28
+ lng : 35 ,
29
+ } ;
30
+
12
31
describe ( 'GoogleMap' , ( ) => {
13
32
let mapConstructorSpy : jasmine . Spy ;
14
- let mapSpy : jasmine . SpyObj < google . maps . Map > ;
33
+ let mapSpy : jasmine . SpyObj < UpdatedGoogleMap > ;
15
34
16
35
beforeEach ( async ( ( ) => {
17
36
TestBed . configureTestingModule ( {
@@ -31,7 +50,7 @@ describe('GoogleMap', () => {
31
50
32
51
it ( 'throws an error is the Google Maps JavaScript API was not loaded' , ( ) => {
33
52
mapSpy = createMapSpy ( DEFAULT_OPTIONS ) ;
34
- mapConstructorSpy = createMapConstructorSpy ( mapSpy , false ) ;
53
+ createMapConstructorSpy ( mapSpy , false ) ;
35
54
36
55
expect ( ( ) => TestBed . createComponent ( TestApp ) )
37
56
. toThrow ( new Error (
@@ -129,6 +148,93 @@ describe('GoogleMap', () => {
129
148
const container = fixture . debugElement . query ( By . css ( 'div' ) ) ;
130
149
expect ( mapConstructorSpy ) . toHaveBeenCalledWith ( container . nativeElement , correctedOptions ) ;
131
150
} ) ;
151
+
152
+ it ( 'exposes methods that change the configuration of the Google Map' , ( ) => {
153
+ mapSpy = createMapSpy ( DEFAULT_OPTIONS ) ;
154
+ createMapConstructorSpy ( mapSpy ) . and . callThrough ( ) ;
155
+
156
+ const fixture = TestBed . createComponent ( TestApp ) ;
157
+ fixture . detectChanges ( ) ;
158
+
159
+ const component = fixture . debugElement . query ( By . directive ( GoogleMap ) ) . componentInstance ;
160
+
161
+ component . fitBounds ( TEST_BOUNDS , 10 ) ;
162
+ expect ( mapSpy . fitBounds ) . toHaveBeenCalledWith ( TEST_BOUNDS , 10 ) ;
163
+
164
+ component . panBy ( 12 , 13 ) ;
165
+ expect ( mapSpy . panBy ) . toHaveBeenCalledWith ( 12 , 13 ) ;
166
+
167
+ component . panTo ( TEST_POSITION ) ;
168
+ expect ( mapSpy . panTo ) . toHaveBeenCalledWith ( TEST_POSITION ) ;
169
+
170
+ component . panToBounds ( TEST_BOUNDS , 10 ) ;
171
+ expect ( mapSpy . panToBounds ) . toHaveBeenCalledWith ( TEST_BOUNDS , 10 ) ;
172
+ } ) ;
173
+
174
+ it ( 'exposes methods that get information about the Google Map' , ( ) => {
175
+ mapSpy = createMapSpy ( DEFAULT_OPTIONS ) ;
176
+ createMapConstructorSpy ( mapSpy ) . and . callThrough ( ) ;
177
+
178
+ const fixture = TestBed . createComponent ( TestApp ) ;
179
+ fixture . detectChanges ( ) ;
180
+
181
+ const component = fixture . debugElement . query ( By . directive ( GoogleMap ) ) . componentInstance ;
182
+
183
+ mapSpy . getBounds . and . returnValue ( null ) ;
184
+ expect ( component . getBounds ( ) ) . toBe ( null ) ;
185
+
186
+ component . getCenter ( ) ;
187
+ expect ( mapSpy . getCenter ) . toHaveBeenCalled ( ) ;
188
+
189
+ mapSpy . getClickableIcons . and . returnValue ( true ) ;
190
+ expect ( component . getClickableIcons ( ) ) . toBe ( true ) ;
191
+
192
+ mapSpy . getHeading . and . returnValue ( 10 ) ;
193
+ expect ( component . getHeading ( ) ) . toBe ( 10 ) ;
194
+
195
+ component . getMapTypeId ( ) ;
196
+ expect ( mapSpy . getMapTypeId ) . toHaveBeenCalled ( ) ;
197
+
198
+ mapSpy . getProjection . and . returnValue ( null ) ;
199
+ expect ( component . getProjection ( ) ) . toBe ( null ) ;
200
+
201
+ component . getStreetView ( ) ;
202
+ expect ( mapSpy . getStreetView ) . toHaveBeenCalled ( ) ;
203
+
204
+ mapSpy . getTilt . and . returnValue ( 7 ) ;
205
+ expect ( component . getTilt ( ) ) . toBe ( 7 ) ;
206
+
207
+ mapSpy . getZoom . and . returnValue ( 5 ) ;
208
+ expect ( component . getZoom ( ) ) . toBe ( 5 ) ;
209
+ } ) ;
210
+
211
+ it ( 'initializes event handlers that are set on the map' , ( ) => {
212
+ mapSpy = createMapSpy ( DEFAULT_OPTIONS ) ;
213
+ createMapConstructorSpy ( mapSpy ) . and . callThrough ( ) ;
214
+
215
+ const fixture = TestBed . createComponent ( TestApp ) ;
216
+ fixture . detectChanges ( ) ;
217
+
218
+ expect ( mapSpy . addListener ) . toHaveBeenCalledWith ( 'click' , jasmine . any ( Function ) ) ;
219
+ expect ( mapSpy . addListener ) . toHaveBeenCalledWith ( 'center_changed' , jasmine . any ( Function ) ) ;
220
+ expect ( mapSpy . addListener ) . toHaveBeenCalledWith ( 'rightclick' , jasmine . any ( Function ) ) ;
221
+ expect ( mapSpy . addListener ) . not . toHaveBeenCalledWith ( 'bounds_changed' , jasmine . any ( Function ) ) ;
222
+ expect ( mapSpy . addListener ) . not . toHaveBeenCalledWith ( 'dblclick' , jasmine . any ( Function ) ) ;
223
+ expect ( mapSpy . addListener ) . not . toHaveBeenCalledWith ( 'drag' , jasmine . any ( Function ) ) ;
224
+ expect ( mapSpy . addListener ) . not . toHaveBeenCalledWith ( 'dragend' , jasmine . any ( Function ) ) ;
225
+ expect ( mapSpy . addListener ) . not . toHaveBeenCalledWith ( 'dragstart' , jasmine . any ( Function ) ) ;
226
+ expect ( mapSpy . addListener ) . not . toHaveBeenCalledWith ( 'heading_changed' , jasmine . any ( Function ) ) ;
227
+ expect ( mapSpy . addListener ) . not . toHaveBeenCalledWith ( 'idle' , jasmine . any ( Function ) ) ;
228
+ expect ( mapSpy . addListener ) . not . toHaveBeenCalledWith ( 'maptypeid_changed' , jasmine . any ( Function ) ) ;
229
+ expect ( mapSpy . addListener ) . not . toHaveBeenCalledWith ( 'mousemove' , jasmine . any ( Function ) ) ;
230
+ expect ( mapSpy . addListener ) . not . toHaveBeenCalledWith ( 'mouseout' , jasmine . any ( Function ) ) ;
231
+ expect ( mapSpy . addListener ) . not . toHaveBeenCalledWith ( 'mouseover' , jasmine . any ( Function ) ) ;
232
+ expect ( mapSpy . addListener )
233
+ . not . toHaveBeenCalledWith ( 'projection_changed' , jasmine . any ( Function ) ) ;
234
+ expect ( mapSpy . addListener ) . not . toHaveBeenCalledWith ( 'tilesloaded' , jasmine . any ( Function ) ) ;
235
+ expect ( mapSpy . addListener ) . not . toHaveBeenCalledWith ( 'tilt_changed' , jasmine . any ( Function ) ) ;
236
+ expect ( mapSpy . addListener ) . not . toHaveBeenCalledWith ( 'zoom_changed' , jasmine . any ( Function ) ) ;
237
+ } ) ;
132
238
} ) ;
133
239
134
240
@Component ( {
@@ -137,12 +243,21 @@ describe('GoogleMap', () => {
137
243
[width]="width"
138
244
[center]="center"
139
245
[zoom]="zoom"
140
- [options]="options"></google-map>` ,
246
+ [options]="options"
247
+ (click)="handleClick"
248
+ (centerChanged)="handleCenterChanged"
249
+ (rightclick)="handleRightclick"></google-map>` ,
141
250
} )
142
251
class TestApp {
143
252
height ?: string ;
144
253
width ?: string ;
145
254
center ?: google . maps . LatLngLiteral ;
146
255
zoom ?: number ;
147
256
options ?: google . maps . MapOptions ;
257
+
258
+ handleClick ( event : google . maps . MouseEvent ) { }
259
+
260
+ handleCenterChanged ( ) { }
261
+
262
+ handleRightclick ( event : google . maps . MouseEvent ) { }
148
263
}
0 commit comments