2 //= require jquery.cookie
5 describe("OSM", function () {
6 describe(".apiUrl", function () {
7 it("returns a URL for a way", function () {
8 expect(OSM.apiUrl({type: "way", id: 10})).to.eq("/api/0.6/way/10/full");
11 it("returns a URL for a node", function () {
12 expect(OSM.apiUrl({type: "node", id: 10})).to.eq("/api/0.6/node/10");
15 it("returns a URL for a specific version", function () {
16 expect(OSM.apiUrl({type: "node", id: 10, version: 2})).to.eq("/api/0.6/node/10/2");
20 describe(".mapParams", function () {
21 beforeEach(function () {
24 document.cookie = "_osm_location=; expires=Thu, 01 Jan 1970 00:00:00 GMT";
26 // Test with another cookie set.
27 document.cookie = "_osm_session=deadbeef";
30 it("parses marker params", function () {
31 var params = OSM.mapParams("?mlat=57.6247&mlon=-3.6845");
32 expect(params).to.have.property("mlat", 57.6247);
33 expect(params).to.have.property("mlon", -3.6845);
34 expect(params).to.have.property("marker", true);
37 it("parses object params", function () {
38 var params = OSM.mapParams("?node=1");
39 expect(params).to.have.property("object");
40 expect(params).to.have.property("object_zoom", true);
41 expect(params.object).to.eql({type: "node", id: 1});
43 params = OSM.mapParams("?way=1");
44 expect(params).to.have.property("object");
45 expect(params).to.have.property("object_zoom", true);
46 expect(params.object).to.eql({type: "way", id: 1});
48 params = OSM.mapParams("?relation=1");
49 expect(params).to.have.property("object");
50 expect(params).to.have.property("object_zoom", true);
51 expect(params.object).to.eql({type: "relation", id: 1});
54 it("parses bbox params", function () {
55 var params = OSM.mapParams("?bbox=-3.6845,57.6247,-3.7845,57.7247");
56 expect(params).to.have.property("bbox", true);
57 expect(params).to.have.property("minlon", -3.6845);
58 expect(params).to.have.property("minlat", 57.6247);
59 expect(params).to.have.property("maxlon", -3.7845);
60 expect(params).to.have.property("maxlat", 57.7247);
61 expect(params).to.have.property("box", false);
63 params = OSM.mapParams("?minlon=-3.6845&minlat=57.6247&maxlon=-3.7845&maxlat=57.7247");
64 expect(params).to.have.property("bbox", true);
65 expect(params).to.have.property("minlon", -3.6845);
66 expect(params).to.have.property("minlat", 57.6247);
67 expect(params).to.have.property("maxlon", -3.7845);
68 expect(params).to.have.property("maxlat", 57.7247);
69 expect(params).to.have.property("box", false);
71 params = OSM.mapParams("?bbox=-3.6845,57.6247,-3.7845,57.7247&box=yes");
72 expect(params).to.have.property("box", true);
74 params = OSM.mapParams("?minlon=-3.6845&minlat=57.6247&maxlon=-3.7845&maxlat=57.7247&box=yes");
75 expect(params).to.have.property("box", true);
78 it("infers lat/long from bbox", function () {
79 var params = OSM.mapParams("?bbox=-3.6845,57.6247,-3.7845,57.7247");
80 expect(params).to.have.property("lat", 57.6747);
81 expect(params).to.have.property("lon", -3.7344999999999997);
83 params = OSM.mapParams("?minlon=-3.6845&minlat=57.6247&maxlon=-3.7845&maxlat=57.7247");
84 expect(params).to.have.property("lat", 57.6747);
85 expect(params).to.have.property("lon", -3.7344999999999997);
88 it("parses lat/lon params", function () {
89 var params = OSM.mapParams("?lat=57.6247&lon=-3.6845");
90 expect(params).to.have.property("lat", 57.6247);
91 expect(params).to.have.property("lon", -3.6845);
93 params = OSM.mapParams("?mlat=57.6247&mlon=-3.6845");
94 expect(params).to.have.property("lat", 57.6247);
95 expect(params).to.have.property("lon", -3.6845);
98 it("sets lat/lon from OSM.home", function () {
99 OSM.home = {lat: 57.6247, lon: -3.6845};
100 var params = OSM.mapParams("?");
101 expect(params).to.have.property("lat", 57.6247);
102 expect(params).to.have.property("lon", -3.6845);
105 it("sets bbox from OSM.location", function () {
106 OSM.location = {minlon: -3.6845, minlat: 57.6247, maxlon: -3.7845, maxlat: 57.7247};
107 var params = OSM.mapParams("?");
108 expect(params).to.have.property("bbox", true);
109 expect(params).to.have.property("minlon", -3.6845);
110 expect(params).to.have.property("minlat", 57.6247);
111 expect(params).to.have.property("maxlon", -3.7845);
112 expect(params).to.have.property("maxlat", 57.7247);
115 it("parses params from the _osm_location cookie", function () {
116 document.cookie = "_osm_location=-3.6845|57.6247|5|M";
117 var params = OSM.mapParams("?");
118 expect(params).to.have.property("lat", 57.6247);
119 expect(params).to.have.property("lon", -3.6845);
120 expect(params).to.have.property("zoom", 5);
121 expect(params).to.have.property("layers", "M");
124 it("defaults lat/lon to London", function () {
125 var params = OSM.mapParams("?");
126 expect(params).to.have.property("lat", 51.5);
127 expect(params).to.have.property("lon", -0.1);
130 it("parses layers param", function () {
131 var params = OSM.mapParams("?layers=M");
132 expect(params).to.have.property("layers", "M");