Skip to content

Commit

Permalink
Add google.spec.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
simon04 committed Nov 22, 2020
1 parent da45547 commit e1efe48
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 0 deletions.
61 changes: 61 additions & 0 deletions spec/__snapshots__/google.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`L.Control.Geocoder.Google geocodes Innsbruck 1`] = `
Array [
Array [
Array [
Object {
"bbox": Object {
"_northEast": Object {
"lat": 47.3599301,
"lng": 11.45593,
},
"_southWest": Object {
"lat": 47.21098000000001,
"lng": 11.3016499,
},
},
"center": Object {
"lat": 47.2692124,
"lng": 11.4041024,
},
"name": "Innsbruck, Austria",
"properties": Array [
Object {
"long_name": "Innsbruck",
"short_name": "Innsbruck",
"types": Array [
"locality",
"political",
],
},
Object {
"long_name": "Innsbruck",
"short_name": "Innsbruck",
"types": Array [
"administrative_area_level_2",
"political",
],
},
Object {
"long_name": "Tyrol",
"short_name": "Tyrol",
"types": Array [
"administrative_area_level_1",
"political",
],
},
Object {
"long_name": "Austria",
"short_name": "AT",
"types": Array [
"country",
"political",
],
},
],
},
],
],
]
`;
82 changes: 82 additions & 0 deletions spec/google.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { testXMLHttpRequest } from './mockXMLHttpRequest';
import { Google } from '../src/geocoders/google';
import { GeocodingResult } from '../src/geocoders/interfaces';

describe('L.Control.Geocoder.Google', () => {
it('geocodes Innsbruck', () => {
const geocoder = new Google('0123xyz');
const callback = jest.fn();
testXMLHttpRequest(
'https://maps.googleapis.com/maps/api/geocode/json?key=0123xyz&address=Innsbruck',
{
results: [
{
address_components: [
{
long_name: 'Innsbruck',
short_name: 'Innsbruck',
types: ['locality', 'political']
},
{
long_name: 'Innsbruck',
short_name: 'Innsbruck',
types: ['administrative_area_level_2', 'political']
},
{
long_name: 'Tyrol',
short_name: 'Tyrol',
types: ['administrative_area_level_1', 'political']
},
{
long_name: 'Austria',
short_name: 'AT',
types: ['country', 'political']
}
],
formatted_address: 'Innsbruck, Austria',
geometry: {
bounds: {
northeast: {
lat: 47.3599301,
lng: 11.45593
},
southwest: {
lat: 47.21098000000001,
lng: 11.3016499
}
},
location: {
lat: 47.2692124,
lng: 11.4041024
},
location_type: 'APPROXIMATE',
viewport: {
northeast: {
lat: 47.3599301,
lng: 11.45593
},
southwest: {
lat: 47.21098000000001,
lng: 11.3016499
}
}
},
place_id: 'ChIJc8r44c9unUcRDZsdKH0cIJ0',
types: ['locality', 'political']
}
],
status: 'OK'
},
() => geocoder.geocode('Innsbruck', callback)
);

const feature: GeocodingResult = callback.mock.calls[0][0][0];
expect(feature.name).toBe('Innsbruck, Austria');
expect(feature.center).toStrictEqual({ lat: 47.2692124, lng: 11.4041024 });
expect(feature.bbox).toStrictEqual({
_northEast: { lat: 47.3599301, lng: 11.45593 },
_southWest: { lat: 47.21098000000001, lng: 11.3016499 }
});
expect(callback.mock.calls).toMatchSnapshot();
});
});

0 comments on commit e1efe48

Please sign in to comment.