photon.spec.ts 2.14 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
import { testXMLHttpRequest } from './mockXMLHttpRequest';
import { Photon } from '../src/geocoders/photon';
import { GeocodingResult } from '../src/geocoders/api';

describe('L.Control.Geocoder.Photon', () => {
  it('geocodes Innsbruck', () => {
    const geocoder = new Photon();
    const callback = jest.fn();
    testXMLHttpRequest(
      'https://photon.komoot.io/api/?q=Innsbruck',
      {
        features: [
          {
            geometry: { coordinates: [11.3927685, 47.2654296], type: 'Point' },
            type: 'Feature',
            properties: {
              osm_id: 8182617,
              osm_type: 'R',
              extent: [11.3811871, 47.2808566, 11.4181209, 47.2583715],
              country: 'Austria',
              osm_key: 'place',
              city: 'Innsbruck',
              countrycode: 'AT',
              osm_value: 'city',
              name: 'Innsbruck',
              state: 'Tyrol',
              type: 'locality'
            }
          },
          {
            geometry: { coordinates: [11.3959095, 47.2690806], type: 'Point' },
            type: 'Feature',
            properties: {
              osm_id: 7323902269,
              country: 'Austria',
              city: 'Innsbruck',
              countrycode: 'AT',
              postcode: '6020',
              type: 'house',
              osm_type: 'N',
              osm_key: 'amenity',
              housenumber: '1',
              street: 'Universitätsstraße',
              district: 'Innenstadt',
              osm_value: 'music_school',
              name: 'Mozarteum Innsbruck',
              state: 'Tyrol'
            }
          }
        ],
        type: 'FeatureCollection'
      },
      () => geocoder.geocode('Innsbruck', callback)
    );

    const feature: GeocodingResult = callback.mock.calls[0][0][0];
    expect(feature.name).toBe('Innsbruck, Innsbruck, Tyrol, Austria');
    expect(feature.center).toStrictEqual({ lat: 47.2654296, lng: 11.3927685 });
    expect(feature.bbox).toStrictEqual({
      _northEast: { lat: 47.2808566, lng: 11.4181209 },
      _southWest: { lat: 47.2583715, lng: 11.3811871 }
    });
    expect(callback.mock.calls).toMatchSnapshot();
  });
});