]> git.openstreetmap.org Git - rails.git/blobdiff - test/javascripts/osm_test.js
Moved inline styling to stylesheet
[rails.git] / test / javascripts / osm_test.js
index 5e982fc4d16dd078c8ffc322dbaa248f591affe7..51f74fe7a56b98087fba50772169642e0797d673 100644 (file)
@@ -2,6 +2,9 @@
 //= require jquery.cookie
 //= require osm
 //= require leaflet
+//= require leaflet.osm
+//= require leaflet.map
+//= require i18n/translations
 //= require querystring
 
 var querystring = require('querystring-component');
@@ -70,18 +73,8 @@ describe("OSM", function () {
       expect(params).to.have.property("bounds").deep.equal(expected);
     });
 
-    it("parses lat/lon/zoom params", function () {
-      var params = OSM.mapParams("?lat=57.6247&lon=-3.6845");
-      expect(params).to.have.property("lat", 57.6247);
-      expect(params).to.have.property("lon", -3.6845);
-      expect(params).to.have.property("zoom", 5);
-
-      params = OSM.mapParams("?lat=57.6247&lon=-3.6845&zoom=10");
-      expect(params).to.have.property("lat", 57.6247);
-      expect(params).to.have.property("lon", -3.6845);
-      expect(params).to.have.property("zoom", 10);
-
-      params = OSM.mapParams("?mlat=57.6247&mlon=-3.6845");
+    it("parses mlat/mlon/zoom params", function () {
+      var params = OSM.mapParams("?mlat=57.6247&mlon=-3.6845");
       expect(params).to.have.property("lat", 57.6247);
       expect(params).to.have.property("lon", -3.6845);
       expect(params).to.have.property("zoom", 12);
@@ -227,4 +220,33 @@ describe("OSM", function () {
       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");
+    });
+  });
+
+  describe(".distance", function () {
+    it("computes distance between points", function () {
+      var latlng1 = L.latLng(51.76712,-0.00484),
+        latlng2 = L.latLng(51.7675159, -0.0078329);
+
+      expect(OSM.distance(latlng1, latlng2)).to.be.closeTo(210.664, 0.005);
+      expect(OSM.distance(latlng2, latlng1)).to.be.closeTo(210.664, 0.005);
+    });
+  });
 });