]> git.openstreetmap.org Git - rails.git/blob - test/javascripts/polyline_decoder_test.js
Merge remote-tracking branch 'upstream/pull/7060'
[rails.git] / test / javascripts / polyline_decoder_test.js
1 //= require polyline_decoder
2
3 describe("OSM.decodePolyline", function () {
4   it("decodes a precision-5 polyline into {lat, lng} objects", function () {
5     const coords = [[38.5, -120.2], [40.7, -120.95]];
6     const encoded = polyline.encode(coords, 5);
7     const points = OSM.decodePolyline(encoded, { precision: 5 });
8     expect(points).to.eql([
9       { lat: 38.5, lng: -120.2 },
10       { lat: 40.7, lng: -120.95 }
11     ]);
12   });
13
14   it("honours a custom precision option", function () {
15     const coords = [[38.5, -120.2], [40.7, -120.95]];
16     const encoded = polyline.encode(coords, 6);
17     const points = OSM.decodePolyline(encoded, { precision: 6 });
18     expect(points).to.eql([
19       { lat: 38.5, lng: -120.2 },
20       { lat: 40.7, lng: -120.95 }
21     ]);
22   });
23
24   it("returns an empty array for an empty string", function () {
25     expect(OSM.decodePolyline("", { precision: 5 })).to.eql([]);
26   });
27 });