X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/501d13e1c0936cc3ba3d9639620517bae34e5784..43ce6e68c09cdb4e66a7af9849e36c9406d2eb05:/test/javascripts/osm_test.js diff --git a/test/javascripts/osm_test.js b/test/javascripts/osm_test.js index 51f74fe7a..045094314 100644 --- a/test/javascripts/osm_test.js +++ b/test/javascripts/osm_test.js @@ -1,26 +1,24 @@ //= require jquery -//= require jquery.cookie +//= require js-cookie/dist/js.cookie //= require osm -//= require leaflet +//= require leaflet/dist/leaflet-src //= require leaflet.osm //= require leaflet.map //= require i18n/translations -//= require querystring - -var querystring = require('querystring-component'); +//= require qs/dist/qs describe("OSM", function () { describe(".apiUrl", function () { it("returns a URL for a way", function () { - expect(OSM.apiUrl({type: "way", id: 10})).to.eq("/api/0.6/way/10/full"); + expect(OSM.apiUrl({ type: "way", id: 10 })).to.eq("/api/0.6/way/10/full"); }); it("returns a URL for a node", function () { - expect(OSM.apiUrl({type: "node", id: 10})).to.eq("/api/0.6/node/10"); + expect(OSM.apiUrl({ type: "node", id: 10 })).to.eq("/api/0.6/node/10"); }); it("returns a URL for a specific version", function () { - expect(OSM.apiUrl({type: "node", id: 10, version: 2})).to.eq("/api/0.6/node/10/2"); + expect(OSM.apiUrl({ type: "node", id: 10, version: 2 })).to.eq("/api/0.6/node/10/2"); }); }); @@ -53,15 +51,15 @@ describe("OSM", function () { it("parses object params", function () { var params = OSM.mapParams("?node=1"); expect(params).to.have.property("object"); - expect(params.object).to.eql({type: "node", id: 1}); + expect(params.object).to.eql({ type: "node", id: 1 }); params = OSM.mapParams("?way=1"); expect(params).to.have.property("object"); - expect(params.object).to.eql({type: "way", id: 1}); + expect(params.object).to.eql({ type: "way", id: 1 }); params = OSM.mapParams("?relation=1"); expect(params).to.have.property("object"); - expect(params.object).to.eql({type: "relation", id: 1}); + expect(params.object).to.eql({ type: "relation", id: 1 }); }); it("parses bbox params", function () { @@ -87,21 +85,21 @@ describe("OSM", function () { it("parses lat/lon/zoom from the hash", function () { document.location.hash = "#map=16/57.6247/-3.6845"; - params = OSM.mapParams("?"); + const params = OSM.mapParams("?"); expect(params).to.have.property("lat", 57.6247); expect(params).to.have.property("lon", -3.6845); expect(params).to.have.property("zoom", 16); }); it("sets lat/lon from OSM.home", function () { - OSM.home = {lat: 57.6247, lon: -3.6845}; + OSM.home = { lat: 57.6247, lon: -3.6845 }; var params = OSM.mapParams("?"); expect(params).to.have.property("lat", 57.6247); expect(params).to.have.property("lon", -3.6845); }); it("sets bbox from OSM.location", function () { - OSM.location = {minlon: -3.6845, minlat: 57.6247, maxlon: -3.7845, maxlat: 57.7247}; + OSM.location = { minlon: -3.6845, minlat: 57.6247, maxlon: -3.7845, maxlat: 57.7247 }; var expected = L.latLngBounds([57.6247, -3.6845], [57.7247, -3.7845]); var params = OSM.mapParams("?"); expect(params).to.have.property("bounds").deep.equal(expected); @@ -136,7 +134,7 @@ describe("OSM", function () { params = OSM.mapParams("?"); expect(params).to.have.property("layers", "C"); - document.location.hash = "#map=5/57.6247/-3.6845&layers=M" + document.location.hash = "#map=5/57.6247/-3.6845&layers=M"; params = OSM.mapParams("?"); expect(params).to.have.property("layers", "M"); }); @@ -158,66 +156,75 @@ describe("OSM", function () { describe(".formatHash", function () { it("formats lat/lon/zoom params", function () { var args = { center: L.latLng(57.6247, -3.6845), zoom: 9 }; - expect(OSM.formatHash(args)).to.eq("#map=9/57.6247/-3.6845"); + expect(OSM.formatHash(args)).to.eq("#map=9/57.625/-3.685"); }); it("respects zoomPrecision", function () { var args = { center: L.latLng(57.6247, -3.6845), zoom: 5 }; - expect(OSM.formatHash(args)).to.eq("#map=5/57.625/-3.685"); + expect(OSM.formatHash(args)).to.eq("#map=5/57.62/-3.68"); + args = { center: L.latLng(57.6247, -3.6845), zoom: 9 }; - expect(OSM.formatHash(args)).to.eq("#map=9/57.6247/-3.6845"); + expect(OSM.formatHash(args)).to.eq("#map=9/57.625/-3.685"); + + + args = { center: L.latLng(57.6247, -3.6845), zoom: 12 }; + expect(OSM.formatHash(args)).to.eq("#map=12/57.6247/-3.6845"); }); it("formats layers params", function () { var args = { center: L.latLng(57.6247, -3.6845), zoom: 9, layers: "C" }; - expect(OSM.formatHash(args)).to.eq("#map=9/57.6247/-3.6845&layers=C"); + expect(OSM.formatHash(args)).to.eq("#map=9/57.625/-3.685&layers=C"); }); it("ignores default layers", function () { var args = { center: L.latLng(57.6247, -3.6845), zoom: 9, layers: "M" }; - expect(OSM.formatHash(args)).to.eq("#map=9/57.6247/-3.6845"); + expect(OSM.formatHash(args)).to.eq("#map=9/57.625/-3.685"); }); }); - describe(".zoomPrecision", function () { - it("suggests 0 digits for z0-1", function () { - expect(OSM.zoomPrecision(0)).to.eq(0); - expect(OSM.zoomPrecision(1)).to.eq(0); - }); - it("suggests 1 digit for z2", function () { + describe(".zoomPrecision", function () { + it("suggests 1 digit for z0-2", function () { + expect(OSM.zoomPrecision(0)).to.eq(1); + expect(OSM.zoomPrecision(1)).to.eq(1); expect(OSM.zoomPrecision(2)).to.eq(1); }); - it("suggests 2 digits for z3-4", function () { + it("suggests 2 digits for z3-6", function () { expect(OSM.zoomPrecision(3)).to.eq(2); expect(OSM.zoomPrecision(4)).to.eq(2); + expect(OSM.zoomPrecision(5)).to.eq(2); + expect(OSM.zoomPrecision(6)).to.eq(2); }); - it("suggests 3 digits for z5-8", function () { - expect(OSM.zoomPrecision(5)).to.eq(3); - expect(OSM.zoomPrecision(6)).to.eq(3); + it("suggests 3 digits for z7-9", function () { expect(OSM.zoomPrecision(7)).to.eq(3); expect(OSM.zoomPrecision(8)).to.eq(3); + expect(OSM.zoomPrecision(9)).to.eq(3); }); - it("suggests 4 digits for z9-16", function () { - expect(OSM.zoomPrecision(9)).to.eq(4); + it("suggests 4 digits for z10-12", function () { expect(OSM.zoomPrecision(10)).to.eq(4); expect(OSM.zoomPrecision(11)).to.eq(4); expect(OSM.zoomPrecision(12)).to.eq(4); - expect(OSM.zoomPrecision(13)).to.eq(4); - expect(OSM.zoomPrecision(14)).to.eq(4); - expect(OSM.zoomPrecision(15)).to.eq(4); - expect(OSM.zoomPrecision(16)).to.eq(4); }); - it("suggests 5 digits for z17-20", function () { - expect(OSM.zoomPrecision(17)).to.eq(5); - expect(OSM.zoomPrecision(18)).to.eq(5); - expect(OSM.zoomPrecision(19)).to.eq(5); - expect(OSM.zoomPrecision(20)).to.eq(5); + it("suggests 5 digits for z13-16", function () { + expect(OSM.zoomPrecision(13)).to.eq(5); + expect(OSM.zoomPrecision(14)).to.eq(5); + expect(OSM.zoomPrecision(15)).to.eq(5); + expect(OSM.zoomPrecision(16)).to.eq(5); + }); + + it("suggests 6 digits for z17-19", function () { + expect(OSM.zoomPrecision(17)).to.eq(6); + expect(OSM.zoomPrecision(18)).to.eq(6); + expect(OSM.zoomPrecision(19)).to.eq(6); + }); + + it("suggests 7 digits for z20", function () { + expect(OSM.zoomPrecision(20)).to.eq(7); }); }); @@ -226,24 +233,25 @@ describe("OSM", function () { $("body").html($("