1
- import { Component } from '@angular/core' ;
2
- import { async , TestBed } from '@angular/core/testing' ;
3
- import { By } from '@angular/platform-browser' ;
1
+ import { Component } from '@angular/core' ;
2
+ import { async , TestBed } from '@angular/core/testing' ;
3
+ import { By } from '@angular/platform-browser' ;
4
4
5
- import { DEFAULT_OPTIONS , GoogleMapMarkerModule } from './index' ;
5
+ import {
6
+ createMarkerConstructorSpy ,
7
+ createMarkerSpy ,
8
+ TestingWindow
9
+ } from '../testing/fake-google-map-utils' ;
6
10
7
- import { createMarkerSpy , createMarkerConstructorSpy , TestingWindow } from '../testing/fake-google-map-utils ' ;
11
+ import { DEFAULT_MARKER_OPTIONS , GoogleMapMarker , GoogleMapMarkerModule } from './index ' ;
8
12
9
13
describe ( 'GoogleMapMarker' , ( ) => {
10
14
beforeEach ( async ( ( ) => {
@@ -24,26 +28,214 @@ describe('GoogleMapMarker', () => {
24
28
} ) ;
25
29
26
30
it ( 'initializes a Google Map marker' , ( ) => {
27
- let markerSpy = createMarkerSpy ( DEFAULT_OPTIONS ) ;
28
- let markerConstructorSpy = createMarkerConstructorSpy ( markerSpy ) ;
31
+ let markerSpy = createMarkerSpy ( DEFAULT_MARKER_OPTIONS ) ;
32
+ let markerConstructorSpy = createMarkerConstructorSpy ( markerSpy ) . and . callThrough ( ) ;
29
33
30
34
const fixture = TestBed . createComponent ( TestApp ) ;
35
+ const fakeMap = { } as unknown as google . maps . Map ;
36
+ const markerComponent =
37
+ fixture . debugElement . query ( By . directive ( GoogleMapMarker ) ) . componentInstance ;
38
+ markerComponent . setMap ( fakeMap ) ;
31
39
fixture . detectChanges ( ) ;
32
40
33
- expect ( markerConstructorSpy ) . toHaveBeenCalledWith ( DEFAULT_OPTIONS ) ;
41
+ expect ( markerConstructorSpy ) . toHaveBeenCalledWith ( {
42
+ ...DEFAULT_MARKER_OPTIONS ,
43
+ title : undefined ,
44
+ label : undefined ,
45
+ clickable : undefined ,
46
+ map : fakeMap
47
+ } ) ;
48
+ } ) ;
49
+
50
+ it ( 'sets marker inputs' , ( ) => {
51
+ const fakeMap = { } as unknown as google . maps . Map ;
52
+ const options : google . maps . MarkerOptions = {
53
+ position : { lat : 3 , lng : 5 } ,
54
+ title : 'marker title' ,
55
+ label : 'marker label' ,
56
+ clickable : false ,
57
+ map : fakeMap ,
58
+ } ;
59
+ let markerSpy = createMarkerSpy ( options ) ;
60
+ let markerConstructorSpy = createMarkerConstructorSpy ( markerSpy ) . and . callThrough ( ) ;
61
+
62
+ const fixture = TestBed . createComponent ( TestApp ) ;
63
+ fixture . componentInstance . position = options . position ;
64
+ fixture . componentInstance . title = options . title ;
65
+ fixture . componentInstance . label = options . label ;
66
+ fixture . componentInstance . clickable = options . clickable ;
67
+ const markerComponent =
68
+ fixture . debugElement . query ( By . directive ( GoogleMapMarker ) ) . componentInstance ;
69
+ markerComponent . setMap ( fakeMap ) ;
70
+ fixture . detectChanges ( ) ;
71
+
72
+ expect ( markerConstructorSpy ) . toHaveBeenCalledWith ( options ) ;
73
+ } ) ;
74
+
75
+ it ( 'sets marker options, ignoring map' , ( ) => {
76
+ const fakeMap = { } as unknown as google . maps . Map ;
77
+ const options : google . maps . MarkerOptions = {
78
+ position : { lat : 3 , lng : 5 } ,
79
+ title : 'marker title' ,
80
+ label : 'marker label' ,
81
+ clickable : false ,
82
+ icon : 'icon name' ,
83
+ } ;
84
+ let markerSpy = createMarkerSpy ( options ) ;
85
+ let markerConstructorSpy = createMarkerConstructorSpy ( markerSpy ) . and . callThrough ( ) ;
86
+
87
+ const fixture = TestBed . createComponent ( TestApp ) ;
88
+ fixture . componentInstance . options = options ;
89
+ const markerComponent =
90
+ fixture . debugElement . query ( By . directive ( GoogleMapMarker ) ) . componentInstance ;
91
+ markerComponent . setMap ( fakeMap ) ;
92
+ fixture . detectChanges ( ) ;
93
+
94
+ expect ( markerConstructorSpy ) . toHaveBeenCalledWith ( { ...options , map : fakeMap } ) ;
34
95
} ) ;
35
96
36
- it ( 'sets marker inputs' , ( ) => { } ) ;
97
+ it ( 'gives precedence to specific inputs over options' , ( ) => {
98
+ const fakeMap = { } as unknown as google . maps . Map ;
99
+ const options : google . maps . MarkerOptions = {
100
+ position : { lat : 3 , lng : 5 } ,
101
+ title : 'marker title' ,
102
+ label : 'marker label' ,
103
+ clickable : false ,
104
+ icon : 'icon name' ,
105
+ } ;
106
+ const expectedOptions : google . maps . MarkerOptions = {
107
+ position : { lat : 5 , lng : 12 } ,
108
+ title : 'updated title' ,
109
+ label : 'updated label' ,
110
+ clickable : true ,
111
+ icon : 'icon name' ,
112
+ map : fakeMap ,
113
+ } ;
114
+ let markerSpy = createMarkerSpy ( options ) ;
115
+ let markerConstructorSpy = createMarkerConstructorSpy ( markerSpy ) . and . callThrough ( ) ;
116
+
117
+ const fixture = TestBed . createComponent ( TestApp ) ;
118
+ fixture . componentInstance . position = expectedOptions . position ;
119
+ fixture . componentInstance . title = expectedOptions . title ;
120
+ fixture . componentInstance . label = expectedOptions . label ;
121
+ fixture . componentInstance . clickable = expectedOptions . clickable ;
122
+ fixture . componentInstance . options = options ;
123
+ const markerComponent =
124
+ fixture . debugElement . query ( By . directive ( GoogleMapMarker ) ) . componentInstance ;
125
+ markerComponent . setMap ( fakeMap ) ;
126
+ fixture . detectChanges ( ) ;
37
127
38
- it ( 'sets marker options, ignoring map' , ( ) => { } ) ;
128
+ expect ( markerConstructorSpy ) . toHaveBeenCalledWith ( expectedOptions ) ;
129
+ } ) ;
39
130
40
- it ( 'gives precedence to specific inputs over options' , ( ) => { } ) ;
131
+ it ( 'sets the map on the marker only once' , ( ) => {
132
+ let markerSpy = createMarkerSpy ( DEFAULT_MARKER_OPTIONS ) ;
133
+ let markerConstructorSpy = createMarkerConstructorSpy ( markerSpy ) . and . callThrough ( ) ;
41
134
42
- it ( 'sets the map on the marker only once' , ( ) => { } ) ;
135
+ const fixture = TestBed . createComponent ( TestApp ) ;
136
+ const fakeMap = { } as unknown as google . maps . Map ;
137
+ const fakeMap2 = { testValue : 'test' } as unknown as google . maps . Map ;
138
+ const markerComponent =
139
+ fixture . debugElement . query ( By . directive ( GoogleMapMarker ) ) . componentInstance ;
140
+ markerComponent . setMap ( fakeMap ) ;
141
+ markerComponent . setMap ( fakeMap2 ) ;
142
+ fixture . detectChanges ( ) ;
143
+
144
+ expect ( markerConstructorSpy ) . toHaveBeenCalledWith ( {
145
+ ...DEFAULT_MARKER_OPTIONS ,
146
+ title : undefined ,
147
+ label : undefined ,
148
+ clickable : undefined ,
149
+ map : fakeMap
150
+ } ) ;
151
+ expect ( markerSpy . setOptions ) . not . toHaveBeenCalled ( ) ;
152
+ } ) ;
43
153
44
- it ( 'exposes methods that provide information about the marker' , ( ) => { } ) ;
154
+ it ( 'exposes methods that provide information about the marker' , ( ) => {
155
+ let markerSpy = createMarkerSpy ( DEFAULT_MARKER_OPTIONS ) ;
156
+ createMarkerConstructorSpy ( markerSpy ) . and . callThrough ( ) ;
45
157
46
- it ( 'initializes marker event handlers' , ( ) => { } ) ;
158
+ const fixture = TestBed . createComponent ( TestApp ) ;
159
+ const fakeMap = { } as unknown as google . maps . Map ;
160
+ const markerComponent =
161
+ fixture . debugElement . query ( By . directive ( GoogleMapMarker ) ) . componentInstance ;
162
+ markerComponent . setMap ( fakeMap ) ;
163
+ fixture . detectChanges ( ) ;
164
+
165
+ markerSpy . getAnimation . and . returnValue ( null ) ;
166
+ expect ( markerComponent . getAnimation ( ) ) . toBe ( null ) ;
167
+
168
+ markerSpy . getClickable . and . returnValue ( true ) ;
169
+ expect ( markerComponent . getClickable ( ) ) . toBe ( true ) ;
170
+
171
+ markerSpy . getCursor . and . returnValue ( 'cursor' ) ;
172
+ expect ( markerComponent . getCursor ( ) ) . toBe ( 'cursor' ) ;
173
+
174
+ markerSpy . getDraggable . and . returnValue ( true ) ;
175
+ expect ( markerComponent . getDraggable ( ) ) . toBe ( true ) ;
176
+
177
+ markerSpy . getIcon . and . returnValue ( 'icon' ) ;
178
+ expect ( markerComponent . getIcon ( ) ) . toBe ( 'icon' ) ;
179
+
180
+ markerSpy . getLabel . and . returnValue ( 'label' ) ;
181
+ expect ( markerComponent . getLabel ( ) ) . toBe ( 'label' ) ;
182
+
183
+ markerSpy . getOpacity . and . returnValue ( 5 ) ;
184
+ expect ( markerComponent . getOpacity ( ) ) . toBe ( 5 ) ;
185
+
186
+ markerSpy . getPosition . and . returnValue ( { lat : 1 , lng : 2 } ) ;
187
+ expect ( markerComponent . getPosition ( ) ) . toEqual ( { lat : 1 , lng : 2 } ) ;
188
+
189
+ markerSpy . getShape . and . returnValue ( null ) ;
190
+ expect ( markerComponent . getShape ( ) ) . toBe ( null ) ;
191
+
192
+ markerSpy . getTitle . and . returnValue ( 'title' ) ;
193
+ expect ( markerComponent . getTitle ( ) ) . toBe ( 'title' ) ;
194
+
195
+ markerSpy . getVisible . and . returnValue ( true ) ;
196
+ expect ( markerComponent . getVisible ( ) ) . toBe ( true ) ;
197
+
198
+ markerSpy . getZIndex . and . returnValue ( 2 ) ;
199
+ expect ( markerComponent . getZIndex ( ) ) . toBe ( 2 ) ;
200
+ } ) ;
201
+
202
+ it ( 'initializes marker event handlers' , ( ) => {
203
+ let markerSpy = createMarkerSpy ( DEFAULT_MARKER_OPTIONS ) ;
204
+ createMarkerConstructorSpy ( markerSpy ) . and . callThrough ( ) ;
205
+
206
+ const fixture = TestBed . createComponent ( TestApp ) ;
207
+ const fakeMap = { } as unknown as google . maps . Map ;
208
+ const markerComponent =
209
+ fixture . debugElement . query ( By . directive ( GoogleMapMarker ) ) . componentInstance ;
210
+ markerComponent . setMap ( fakeMap ) ;
211
+ fixture . detectChanges ( ) ;
212
+
213
+ expect ( markerSpy . addListener )
214
+ . not . toHaveBeenCalledWith ( 'animation_changed' , jasmine . any ( Function ) ) ;
215
+ expect ( markerSpy . addListener ) . toHaveBeenCalledWith ( 'click' , jasmine . any ( Function ) ) ;
216
+ expect ( markerSpy . addListener )
217
+ . not . toHaveBeenCalledWith ( 'clickable_changed' , jasmine . any ( Function ) ) ;
218
+ expect ( markerSpy . addListener ) . not . toHaveBeenCalledWith ( 'cursor_changed' , jasmine . any ( Function ) ) ;
219
+ expect ( markerSpy . addListener ) . not . toHaveBeenCalledWith ( 'dblclick' , jasmine . any ( Function ) ) ;
220
+ expect ( markerSpy . addListener ) . not . toHaveBeenCalledWith ( 'drag' , jasmine . any ( Function ) ) ;
221
+ expect ( markerSpy . addListener ) . not . toHaveBeenCalledWith ( 'dragend' , jasmine . any ( Function ) ) ;
222
+ expect ( markerSpy . addListener )
223
+ . not . toHaveBeenCalledWith ( 'draggable_changed' , jasmine . any ( Function ) ) ;
224
+ expect ( markerSpy . addListener ) . not . toHaveBeenCalledWith ( 'dragstart' , jasmine . any ( Function ) ) ;
225
+ expect ( markerSpy . addListener ) . not . toHaveBeenCalledWith ( 'flat_changed' , jasmine . any ( Function ) ) ;
226
+ expect ( markerSpy . addListener ) . not . toHaveBeenCalledWith ( 'icon_changed' , jasmine . any ( Function ) ) ;
227
+ expect ( markerSpy . addListener ) . not . toHaveBeenCalledWith ( 'mousedown' , jasmine . any ( Function ) ) ;
228
+ expect ( markerSpy . addListener ) . not . toHaveBeenCalledWith ( 'mouseout' , jasmine . any ( Function ) ) ;
229
+ expect ( markerSpy . addListener ) . not . toHaveBeenCalledWith ( 'mouseover' , jasmine . any ( Function ) ) ;
230
+ expect ( markerSpy . addListener ) . not . toHaveBeenCalledWith ( 'mouseup' , jasmine . any ( Function ) ) ;
231
+ expect ( markerSpy . addListener ) . toHaveBeenCalledWith ( 'position_changed' , jasmine . any ( Function ) ) ;
232
+ expect ( markerSpy . addListener ) . not . toHaveBeenCalledWith ( 'rightclick' , jasmine . any ( Function ) ) ;
233
+ expect ( markerSpy . addListener ) . not . toHaveBeenCalledWith ( 'shape_changed' , jasmine . any ( Function ) ) ;
234
+ expect ( markerSpy . addListener ) . not . toHaveBeenCalledWith ( 'title_changed' , jasmine . any ( Function ) ) ;
235
+ expect ( markerSpy . addListener )
236
+ . not . toHaveBeenCalledWith ( 'visible_changed' , jasmine . any ( Function ) ) ;
237
+ expect ( markerSpy . addListener ) . not . toHaveBeenCalledWith ( 'zindex_changed' , jasmine . any ( Function ) ) ;
238
+ } ) ;
47
239
} ) ;
48
240
49
241
@Component ( {
@@ -58,8 +250,8 @@ describe('GoogleMapMarker', () => {
58
250
} )
59
251
class TestApp {
60
252
title ?: string ;
61
- position ?: google . maps . LatLngLiteral ;
62
- label ?: string ;
253
+ position ?: google . maps . LatLng | google . maps . LatLngLiteral ;
254
+ label ?: string | google . maps . MarkerLabel ;
63
255
clickable ?: boolean ;
64
256
options ?: google . maps . MarkerOptions ;
65
257
0 commit comments