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