@@ -42,7 +42,6 @@ const FAKE_PLACE_FROM_QUERY = makeFakePlace({
42
42
43
43
describe ( 'PlacePicker' , ( ) => {
44
44
const env = new Environment ( ) ;
45
- let fakeAutocomplete : jasmine . SpyObj < google . maps . places . Autocomplete > ;
46
45
47
46
beforeAll ( ( ) => {
48
47
env . defineFakeMapElement ( ) ;
@@ -57,13 +56,6 @@ describe('PlacePicker', () => {
57
56
const fakeCircle = jasmine . createSpyObj ( 'Circle' , [ 'getBounds' ] ) ;
58
57
env . fakeGoogleMapsHarness ! . libraries [ 'maps' ] . Circle =
59
58
jasmine . createSpy ( ) . and . returnValue ( fakeCircle ) ;
60
-
61
- // Create a fake Autocomplete class with test-specific logic.
62
- fakeAutocomplete = jasmine . createSpyObj < google . maps . places . Autocomplete > (
63
- 'Autocomplete' ,
64
- [ 'addListener' , 'bindTo' , 'getBounds' , 'getPlace' , 'setOptions' ] ) ;
65
- spyOn ( env . fakeGoogleMapsHarness ! , 'autocompleteConstructor' )
66
- . and . returnValue ( fakeAutocomplete ) ;
67
59
} ) ;
68
60
69
61
async function prepareState ( template ?: TemplateResult ) {
@@ -101,6 +93,8 @@ describe('PlacePicker', () => {
101
93
} ) ;
102
94
103
95
it ( 'initializes Autocomplete widget with minimum configs' , async ( ) => {
96
+ spyOn ( env . fakeGoogleMapsHarness ! , 'autocompleteConstructor' )
97
+ . and . callThrough ( ) ;
104
98
const { picker, input, searchButton, clearButton} = await prepareState ( ) ;
105
99
106
100
expect ( env . fakeGoogleMapsHarness ! . autocompleteConstructor )
@@ -117,6 +111,9 @@ describe('PlacePicker', () => {
117
111
} ) ;
118
112
119
113
it ( `initializes Autocomplete widget based on attributes` , async ( ) => {
114
+ spyOn ( env . fakeGoogleMapsHarness ! , 'autocompleteConstructor' )
115
+ . and . callThrough ( ) ;
116
+
120
117
// The call to `.Circle.and.exec()` grabs a reference to the Circle
121
118
// spy object without recording a call to the constructor spy (e.g.
122
119
// `.Circle()`)
@@ -160,13 +157,14 @@ describe('PlacePicker', () => {
160
157
picker . type = 'restaurant' ;
161
158
await env . waitForStability ( ) ;
162
159
163
- expect ( fakeAutocomplete . setOptions ) . toHaveBeenCalledOnceWith ( {
164
- bounds : FAKE_BOUNDS ,
165
- componentRestrictions : { country : [ 'uk' ] } ,
166
- fields : [ ...PLACE_RESULT_DATA_FIELDS ] ,
167
- strictBounds : true ,
168
- types : [ 'restaurant' ] ,
169
- } ) ;
160
+ expect ( env . fakeGoogleMapsHarness ! . autocompleteSpy . setOptions )
161
+ . toHaveBeenCalledOnceWith ( {
162
+ bounds : FAKE_BOUNDS ,
163
+ componentRestrictions : { country : [ 'uk' ] } ,
164
+ fields : [ ...PLACE_RESULT_DATA_FIELDS ] ,
165
+ strictBounds : true ,
166
+ types : [ 'restaurant' ] ,
167
+ } ) ;
170
168
} ) ;
171
169
172
170
it ( `doesn't define bounds when only location bias is specified` , async ( ) => {
@@ -175,7 +173,7 @@ describe('PlacePicker', () => {
175
173
picker . locationBias = { lat : 12 , lng : 34 } ;
176
174
await env . waitForStability ( ) ;
177
175
178
- expect ( fakeAutocomplete . setOptions )
176
+ expect ( env . fakeGoogleMapsHarness ! . autocompleteSpy . setOptions )
179
177
. toHaveBeenCalledOnceWith ( jasmine . objectContaining ( {
180
178
bounds : undefined ,
181
179
} ) ) ;
@@ -187,7 +185,7 @@ describe('PlacePicker', () => {
187
185
picker . radius = 1000 ;
188
186
await env . waitForStability ( ) ;
189
187
190
- expect ( fakeAutocomplete . setOptions )
188
+ expect ( env . fakeGoogleMapsHarness ! . autocompleteSpy . setOptions )
191
189
. toHaveBeenCalledOnceWith ( jasmine . objectContaining ( {
192
190
bounds : undefined ,
193
191
} ) ) ;
@@ -199,7 +197,8 @@ describe('PlacePicker', () => {
199
197
picker . placeholder = 'Search nearby places' ;
200
198
await env . waitForStability ( ) ;
201
199
202
- expect ( fakeAutocomplete . setOptions ) . not . toHaveBeenCalled ( ) ;
200
+ expect ( env . fakeGoogleMapsHarness ! . autocompleteSpy . setOptions )
201
+ . not . toHaveBeenCalled ( ) ;
203
202
} ) ;
204
203
205
204
it ( `enables search & clear buttons on user input` , async ( ) => {
@@ -230,12 +229,13 @@ describe('PlacePicker', () => {
230
229
it ( `sets value based on user selection and fires event` , async ( ) => {
231
230
const dispatchEventSpy = spyOn ( PlacePicker . prototype , 'dispatchEvent' ) ;
232
231
let autocompleteSelectionHandler : Function ;
233
- fakeAutocomplete . addListener . withArgs ( 'place_changed' , jasmine . anything ( ) )
232
+ env . fakeGoogleMapsHarness ! . autocompleteSpy . addListener
233
+ . withArgs ( 'place_changed' , jasmine . anything ( ) )
234
234
. and . callFake ( ( eventName , handler ) => {
235
235
autocompleteSelectionHandler = handler ;
236
236
return { } as google . maps . MapsEventListener ;
237
237
} ) ;
238
- fakeAutocomplete . getPlace . and . returnValue (
238
+ env . fakeGoogleMapsHarness ! . autocompleteSpy . getPlace . and . returnValue (
239
239
FAKE_PLACE_RESULT_FROM_AUTOCOMPLETE ) ;
240
240
const { picker, input, searchButton, clearButton} = await prepareState ( ) ;
241
241
@@ -256,7 +256,8 @@ describe('PlacePicker', () => {
256
256
257
257
it ( `sets value to undefined when place's cleared & fires event` , async ( ) => {
258
258
let autocompleteSelectionHandler : Function ;
259
- fakeAutocomplete . addListener . withArgs ( 'place_changed' , jasmine . anything ( ) )
259
+ env . fakeGoogleMapsHarness ! . autocompleteSpy . addListener
260
+ . withArgs ( 'place_changed' , jasmine . anything ( ) )
260
261
. and . callFake ( ( eventName , handler ) => {
261
262
autocompleteSelectionHandler = handler ;
262
263
return { } as google . maps . MapsEventListener ;
@@ -280,7 +281,8 @@ describe('PlacePicker', () => {
280
281
} ) ;
281
282
282
283
it ( `sets value based on place returned by Find Place request` , async ( ) => {
283
- fakeAutocomplete . getBounds . and . returnValue ( FAKE_BOUNDS ) ;
284
+ env . fakeGoogleMapsHarness ! . autocompleteSpy . getBounds . and . returnValue (
285
+ FAKE_BOUNDS ) ;
284
286
const { picker, input, searchButton, clearButton} = await prepareState ( ) ;
285
287
286
288
await enterQueryText ( input , '123 Main St' ) ;
@@ -308,7 +310,8 @@ describe('PlacePicker', () => {
308
310
309
311
it ( 'sets value from fallback GA API when Place.findPlaceFromQuery is not available' ,
310
312
async ( ) => {
311
- fakeAutocomplete . getBounds . and . returnValue ( FAKE_BOUNDS ) ;
313
+ env . fakeGoogleMapsHarness ! . autocompleteSpy . getBounds . and . returnValue (
314
+ FAKE_BOUNDS ) ;
312
315
const { picker, input, searchButton, clearButton} = await prepareState ( ) ;
313
316
( env . fakeGoogleMapsHarness ! . findPlaceFromQueryHandler as jasmine . Spy )
314
317
. and . throwError ( new Error (
@@ -412,7 +415,8 @@ describe('PlacePicker', () => {
412
415
413
416
await picker . bindTo ( fakeMap ) ;
414
417
415
- expect ( fakeAutocomplete . bindTo ) . toHaveBeenCalledOnceWith ( 'bounds' , fakeMap ) ;
418
+ expect ( env . fakeGoogleMapsHarness ! . autocompleteSpy . bindTo )
419
+ . toHaveBeenCalledOnceWith ( 'bounds' , fakeMap ) ;
416
420
} ) ;
417
421
418
422
it ( `binds to map bounds declaratively via attribute` , async ( ) => {
@@ -422,7 +426,7 @@ describe('PlacePicker', () => {
422
426
` ) ;
423
427
const mapElement = root . querySelector < FakeMapElement > ( 'gmp-map' ) ! ;
424
428
425
- expect ( fakeAutocomplete . bindTo )
429
+ expect ( env . fakeGoogleMapsHarness ! . autocompleteSpy . bindTo )
426
430
. toHaveBeenCalledOnceWith ( 'bounds' , mapElement . innerMap ) ;
427
431
} ) ;
428
432
@@ -431,7 +435,8 @@ describe('PlacePicker', () => {
431
435
< gmpx-place-picker for-map ="my-map "> </ gmpx-place-picker >
432
436
` ) ;
433
437
434
- expect ( fakeAutocomplete . bindTo ) . not . toHaveBeenCalled ( ) ;
438
+ expect ( env . fakeGoogleMapsHarness ! . autocompleteSpy . bindTo )
439
+ . not . toHaveBeenCalled ( ) ;
435
440
} ) ;
436
441
437
442
it ( `doesn't bind to map bounds when id matches non-Map element` , async ( ) => {
@@ -440,6 +445,7 @@ describe('PlacePicker', () => {
440
445
< div id ="my-map "> </ div >
441
446
` ) ;
442
447
443
- expect ( fakeAutocomplete . bindTo ) . not . toHaveBeenCalled ( ) ;
448
+ expect ( env . fakeGoogleMapsHarness ! . autocompleteSpy . bindTo )
449
+ . not . toHaveBeenCalled ( ) ;
444
450
} ) ;
445
451
} ) ;
0 commit comments