+
+ describe(".parseHash", function () {
+ it("parses lat/lon/zoom params", function () {
+ var args = OSM.parseHash("#map=5/57.6247/-3.6845&layers=M");
+ expect(args).to.have.property("center").deep.equal(L.latLng(57.6247, -3.6845));
+ expect(args).to.have.property("zoom", 5);
+ });
+
+ it("parses layers params", function () {
+ var args = OSM.parseHash("#map=5/57.6247/-3.6845&layers=M");
+ expect(args).to.have.property("layers", "M");
+ });
+ });
+
+ 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");
+ });
+
+ 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");
+
+ args = { center: L.latLng(57.6247, -3.6845), zoom: 9 };
+ expect(OSM.formatHash(args)).to.eq("#map=9/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");
+ });
+
+ 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");
+ });
+ });
+
+ 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 () {
+ expect(OSM.zoomPrecision(2)).to.eq(1);
+ });
+
+ it("suggests 2 digits for z3-4", function () {
+ expect(OSM.zoomPrecision(3)).to.eq(2);
+ expect(OSM.zoomPrecision(4)).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);
+ expect(OSM.zoomPrecision(7)).to.eq(3);
+ expect(OSM.zoomPrecision(8)).to.eq(3);
+ });
+
+ it("suggests 4 digits for z9-16", function () {
+ expect(OSM.zoomPrecision(9)).to.eq(4);
+ 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);
+ });
+ });
+
+ describe(".locationCookie", function () {
+ it("creates a location cookie value", function () {
+ $("body").html($("<div id='map'>"));
+ var map = new L.OSM.Map("map", { center: [57.6247, -3.6845], zoom: 9 });
+ map.updateLayers("");
+ expect(OSM.locationCookie(map)).to.eq("-3.6845|57.6247|9|M");
+ });
+
+ it("respects zoomPrecision", function () {
+ $("body").html($("<div id='map'>"));
+ var map = new L.OSM.Map("map", { center: [57.6247, -3.6845], zoom: 9 });
+ map.updateLayers("");
+ expect(OSM.locationCookie(map)).to.eq("-3.6845|57.6247|9|M");
+
+ map.setZoom(5);
+ expect(OSM.locationCookie(map)).to.eq("-3.685|57.625|5|M");
+ });
+ });