|
| 1 | +describe('L.Control.Geocoder.Openrouteservice', function() { |
| 2 | + var server; |
| 3 | + var geocoder = new L.Control.Geocoder.Openrouteservice('0123'); |
| 4 | + |
| 5 | + beforeEach(function() { |
| 6 | + server = sinon.fakeServer.create(); |
| 7 | + }); |
| 8 | + afterEach(function() { |
| 9 | + server.restore(); |
| 10 | + }); |
| 11 | + |
| 12 | + it('geocodes Innsbruck', function() { |
| 13 | + server.respondWith( |
| 14 | + 'https://api.openrouteservice.org/geocode/search?api_key=0123&text=innsbruck', |
| 15 | + JSON.stringify({ |
| 16 | + geocoding: { |
| 17 | + version: '0.2', |
| 18 | + attribution: 'openrouteservice.org | OpenStreetMap contributors | Geocoding by Pelias', |
| 19 | + query: {}, |
| 20 | + warnings: ["performance optimization: excluding 'address' layer"], |
| 21 | + engine: { name: 'Pelias', author: 'Mapzen', version: '1.0' } |
| 22 | + }, |
| 23 | + type: 'FeatureCollection', |
| 24 | + features: [ |
| 25 | + { |
| 26 | + type: 'Feature', |
| 27 | + geometry: { type: 'Point', coordinates: [11.407851, 47.272308] }, |
| 28 | + properties: { |
| 29 | + id: '101748061', |
| 30 | + layer: 'locality', |
| 31 | + source_id: '101748061', |
| 32 | + name: 'Innsbruck', |
| 33 | + confidence: 1, |
| 34 | + match_type: 'exact', |
| 35 | + accuracy: 'centroid', |
| 36 | + country: 'Austria', |
| 37 | + country_a: 'AUT', |
| 38 | + region: 'Tirol', |
| 39 | + region_a: 'TR', |
| 40 | + county: 'Innsbruck', |
| 41 | + county_a: 'IN', |
| 42 | + localadmin: 'Innsbruck', |
| 43 | + locality: 'Innsbruck', |
| 44 | + continent: 'Europe', |
| 45 | + label: 'Innsbruck, Austria' |
| 46 | + }, |
| 47 | + bbox: [11.3218091258, 47.2470573997, 11.452584553, 47.29398] |
| 48 | + } |
| 49 | + ], |
| 50 | + bbox: [10.9896885523, 46.9624806033, 11.7051690163, 47.4499185397] |
| 51 | + }) |
| 52 | + ); |
| 53 | + |
| 54 | + var callback = sinon.fake(); |
| 55 | + geocoder.geocode('innsbruck', callback); |
| 56 | + server.respond(); |
| 57 | + |
| 58 | + expect(callback.calledOnce).to.be.ok(); |
| 59 | + expect(callback.lastArg).to.be.ok(); |
| 60 | + expect(callback.lastArg.length).to.eql(1); |
| 61 | + expect(callback.lastArg[0].name).to.eql('Innsbruck, Austria'); |
| 62 | + expect(callback.lastArg[0].center).to.eql({ lat: 47.272308, lng: 11.407851 }); |
| 63 | + expect(callback.lastArg[0].bbox).to.eql( |
| 64 | + L.latLngBounds([ |
| 65 | + { lat: 47.2470573997, lng: 11.3218091258 }, |
| 66 | + { lat: 47.29398, lng: 11.452584553 } |
| 67 | + ]) |
| 68 | + ); |
| 69 | + }); |
| 70 | +}); |
0 commit comments