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