|
| 1 | +import {TestBed} from '@angular/core/testing'; |
| 2 | +import {MapGeocoderResponse, MapGeocoder} from './map-geocoder'; |
| 3 | +import {GoogleMapsModule} from '../google-maps-module'; |
| 4 | +import {createGeocoderConstructorSpy, createGeocoderSpy} from '../testing/fake-google-map-utils'; |
| 5 | + |
| 6 | +describe('MapGeocoder', () => { |
| 7 | + let geocoder: MapGeocoder; |
| 8 | + let geocoderConstructorSpy: jasmine.Spy; |
| 9 | + let geocoderSpy: jasmine.SpyObj<google.maps.Geocoder>; |
| 10 | + |
| 11 | + beforeEach(() => { |
| 12 | + TestBed.configureTestingModule({ |
| 13 | + imports: [GoogleMapsModule], |
| 14 | + }); |
| 15 | + |
| 16 | + geocoderSpy = createGeocoderSpy(); |
| 17 | + geocoderConstructorSpy = createGeocoderConstructorSpy(geocoderSpy).and.callThrough(); |
| 18 | + geocoder = TestBed.inject(MapGeocoder); |
| 19 | + }); |
| 20 | + |
| 21 | + afterEach(() => { |
| 22 | + (window.google as any) = undefined; |
| 23 | + }); |
| 24 | + |
| 25 | + it('initializes the Google Maps Geocoder', () => { |
| 26 | + expect(geocoderConstructorSpy).toHaveBeenCalled(); |
| 27 | + }); |
| 28 | + |
| 29 | + it('calls geocode on inputs', () => { |
| 30 | + const results: google.maps.GeocoderResult[] = []; |
| 31 | + const status = 'OK'; |
| 32 | + geocoderSpy.geocode.and.callFake((_: google.maps.GeocoderRequest, callback: Function) => { |
| 33 | + callback(results, status); |
| 34 | + }); |
| 35 | + const request: google.maps.DirectionsRequest = {}; |
| 36 | + geocoder.geocode(request).subscribe(response => { |
| 37 | + expect(response).toEqual({results, status} as MapGeocoderResponse); |
| 38 | + }); |
| 39 | + }); |
| 40 | +}); |
0 commit comments