@@ -2,7 +2,10 @@ 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_OPTIONS , UpdatedGoogleMap } from '../google-map/google-map' ;
5
6
import {
7
+ createMapConstructorSpy ,
8
+ createMapSpy ,
6
9
createMarkerConstructorSpy ,
7
10
createMarkerSpy ,
8
11
TestingWindow
@@ -12,6 +15,8 @@ import {GoogleMapsModule} from '../google-maps-module';
12
15
import { DEFAULT_MARKER_OPTIONS , MapMarker } from './map-marker' ;
13
16
14
17
describe ( 'MapMarker' , ( ) => {
18
+ let mapSpy : jasmine . SpyObj < UpdatedGoogleMap > ;
19
+
15
20
beforeEach ( async ( ( ) => {
16
21
TestBed . configureTestingModule ( {
17
22
imports : [ GoogleMapsModule ] ,
@@ -21,6 +26,9 @@ describe('MapMarker', () => {
21
26
22
27
beforeEach ( ( ) => {
23
28
TestBed . compileComponents ( ) ;
29
+
30
+ mapSpy = createMapSpy ( DEFAULT_OPTIONS ) ;
31
+ createMapConstructorSpy ( mapSpy ) . and . callThrough ( ) ;
24
32
} ) ;
25
33
26
34
afterEach ( ( ) => {
@@ -33,28 +41,24 @@ describe('MapMarker', () => {
33
41
const markerConstructorSpy = createMarkerConstructorSpy ( markerSpy ) . and . callThrough ( ) ;
34
42
35
43
const fixture = TestBed . createComponent ( TestApp ) ;
36
- const fakeMap = { } as unknown as google . maps . Map ;
37
- const markerComponent = fixture . debugElement . query ( By . directive ( MapMarker ) ) . componentInstance ;
38
- markerComponent . _setMap ( fakeMap ) ;
39
44
fixture . detectChanges ( ) ;
40
45
41
46
expect ( markerConstructorSpy ) . toHaveBeenCalledWith ( {
42
47
...DEFAULT_MARKER_OPTIONS ,
43
48
title : undefined ,
44
49
label : undefined ,
45
50
clickable : undefined ,
46
- map : fakeMap
51
+ map : mapSpy ,
47
52
} ) ;
48
53
} ) ;
49
54
50
55
it ( 'sets marker inputs' , ( ) => {
51
- const fakeMap = { } as unknown as google . maps . Map ;
52
56
const options : google . maps . MarkerOptions = {
53
57
position : { lat : 3 , lng : 5 } ,
54
58
title : 'marker title' ,
55
59
label : 'marker label' ,
56
60
clickable : false ,
57
- map : fakeMap ,
61
+ map : mapSpy ,
58
62
} ;
59
63
const markerSpy = createMarkerSpy ( options ) ;
60
64
const markerConstructorSpy = createMarkerConstructorSpy ( markerSpy ) . and . callThrough ( ) ;
@@ -64,15 +68,12 @@ describe('MapMarker', () => {
64
68
fixture . componentInstance . title = options . title ;
65
69
fixture . componentInstance . label = options . label ;
66
70
fixture . componentInstance . clickable = options . clickable ;
67
- const markerComponent = fixture . debugElement . query ( By . directive ( MapMarker ) ) . componentInstance ;
68
- markerComponent . _setMap ( fakeMap ) ;
69
71
fixture . detectChanges ( ) ;
70
72
71
73
expect ( markerConstructorSpy ) . toHaveBeenCalledWith ( options ) ;
72
74
} ) ;
73
75
74
76
it ( 'sets marker options, ignoring map' , ( ) => {
75
- const fakeMap = { } as unknown as google . maps . Map ;
76
77
const options : google . maps . MarkerOptions = {
77
78
position : { lat : 3 , lng : 5 } ,
78
79
title : 'marker title' ,
@@ -85,15 +86,12 @@ describe('MapMarker', () => {
85
86
86
87
const fixture = TestBed . createComponent ( TestApp ) ;
87
88
fixture . componentInstance . options = options ;
88
- const markerComponent = fixture . debugElement . query ( By . directive ( MapMarker ) ) . componentInstance ;
89
- markerComponent . _setMap ( fakeMap ) ;
90
89
fixture . detectChanges ( ) ;
91
90
92
- expect ( markerConstructorSpy ) . toHaveBeenCalledWith ( { ...options , map : fakeMap } ) ;
91
+ expect ( markerConstructorSpy ) . toHaveBeenCalledWith ( { ...options , map : mapSpy } ) ;
93
92
} ) ;
94
93
95
94
it ( 'gives precedence to specific inputs over options' , ( ) => {
96
- const fakeMap = { } as unknown as google . maps . Map ;
97
95
const options : google . maps . MarkerOptions = {
98
96
position : { lat : 3 , lng : 5 } ,
99
97
title : 'marker title' ,
@@ -107,7 +105,7 @@ describe('MapMarker', () => {
107
105
label : 'updated label' ,
108
106
clickable : true ,
109
107
icon : 'icon name' ,
110
- map : fakeMap ,
108
+ map : mapSpy ,
111
109
} ;
112
110
const markerSpy = createMarkerSpy ( options ) ;
113
111
const markerConstructorSpy = createMarkerConstructorSpy ( markerSpy ) . and . callThrough ( ) ;
@@ -118,43 +116,17 @@ describe('MapMarker', () => {
118
116
fixture . componentInstance . label = expectedOptions . label ;
119
117
fixture . componentInstance . clickable = expectedOptions . clickable ;
120
118
fixture . componentInstance . options = options ;
121
- const markerComponent = fixture . debugElement . query ( By . directive ( MapMarker ) ) . componentInstance ;
122
- markerComponent . _setMap ( fakeMap ) ;
123
119
fixture . detectChanges ( ) ;
124
120
125
121
expect ( markerConstructorSpy ) . toHaveBeenCalledWith ( expectedOptions ) ;
126
122
} ) ;
127
123
128
- it ( 'sets the map on the marker only once' , ( ) => {
129
- const markerSpy = createMarkerSpy ( DEFAULT_MARKER_OPTIONS ) ;
130
- const markerConstructorSpy = createMarkerConstructorSpy ( markerSpy ) . and . callThrough ( ) ;
131
-
132
- const fixture = TestBed . createComponent ( TestApp ) ;
133
- const fakeMap = { } as unknown as google . maps . Map ;
134
- const fakeMap2 = { testValue : 'test' } as unknown as google . maps . Map ;
135
- const markerComponent = fixture . debugElement . query ( By . directive ( MapMarker ) ) . componentInstance ;
136
- markerComponent . _setMap ( fakeMap ) ;
137
- markerComponent . _setMap ( fakeMap2 ) ;
138
- fixture . detectChanges ( ) ;
139
-
140
- expect ( markerConstructorSpy ) . toHaveBeenCalledWith ( {
141
- ...DEFAULT_MARKER_OPTIONS ,
142
- title : undefined ,
143
- label : undefined ,
144
- clickable : undefined ,
145
- map : fakeMap
146
- } ) ;
147
- expect ( markerSpy . setOptions ) . not . toHaveBeenCalled ( ) ;
148
- } ) ;
149
-
150
124
it ( 'exposes methods that provide information about the marker' , ( ) => {
151
125
const markerSpy = createMarkerSpy ( DEFAULT_MARKER_OPTIONS ) ;
152
126
createMarkerConstructorSpy ( markerSpy ) . and . callThrough ( ) ;
153
127
154
128
const fixture = TestBed . createComponent ( TestApp ) ;
155
- const fakeMap = { } as unknown as google . maps . Map ;
156
129
const markerComponent = fixture . debugElement . query ( By . directive ( MapMarker ) ) . componentInstance ;
157
- markerComponent . _setMap ( fakeMap ) ;
158
130
fixture . detectChanges ( ) ;
159
131
160
132
markerSpy . getAnimation . and . returnValue ( null ) ;
@@ -199,9 +171,6 @@ describe('MapMarker', () => {
199
171
createMarkerConstructorSpy ( markerSpy ) . and . callThrough ( ) ;
200
172
201
173
const fixture = TestBed . createComponent ( TestApp ) ;
202
- const fakeMap = { } as unknown as google . maps . Map ;
203
- const markerComponent = fixture . debugElement . query ( By . directive ( MapMarker ) ) . componentInstance ;
204
- markerComponent . _setMap ( fakeMap ) ;
205
174
fixture . detectChanges ( ) ;
206
175
207
176
expect ( markerSpy . addListener )
@@ -234,13 +203,16 @@ describe('MapMarker', () => {
234
203
235
204
@Component ( {
236
205
selector : 'test-app' ,
237
- template : `<map-marker [title]="title"
238
- [position]="position"
239
- [label]="label"
240
- [clickable]="clickable"
241
- [options]="options"
242
- (mapClick)="handleClick()"
243
- (positionChanged)="handlePositionChanged()"></map-marker>` ,
206
+ template : `<google-map>
207
+ <map-marker [title]="title"
208
+ [position]="position"
209
+ [label]="label"
210
+ [clickable]="clickable"
211
+ [options]="options"
212
+ (mapClick)="handleClick()"
213
+ (positionChanged)="handlePositionChanged()">
214
+ </map-marker>
215
+ </google-map>` ,
244
216
} )
245
217
class TestApp {
246
218
title ?: string ;
0 commit comments