google.spec.ts 2.58 KB
Newer Older
JOE XMG's avatar
update  
JOE XMG committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { testXMLHttpRequest } from './mockXMLHttpRequest';
import { Google } from '../src/geocoders/google';
import { GeocodingResult } from '../src/geocoders/api';

describe('L.Control.Geocoder.Google', () => {
  it('geocodes Innsbruck', () => {
    const geocoder = new Google({ apiKey: '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();
  });
});