From 492bb5b37edcd3e7523f623bf1e027d76ff53cc2 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Thu, 7 Feb 2019 11:31:32 -0500 Subject: [PATCH] Eliminate magic scale numbers from tests, add `loadNotes` test xml --- test/spec/services/mapillary.js | 2 +- test/spec/services/openstreetcam.js | 6 +-- test/spec/services/osm.js | 62 +++++++++++++++++++---------- test/spec/services/streetside.js | 10 ++--- 4 files changed, 51 insertions(+), 29 deletions(-) diff --git a/test/spec/services/mapillary.js b/test/spec/services/mapillary.js index f1ca87dc4..8642b9b51 100644 --- a/test/spec/services/mapillary.js +++ b/test/spec/services/mapillary.js @@ -14,7 +14,7 @@ describe('iD.serviceMapillary', function() { beforeEach(function() { context = iD.coreContext().assetPath('../dist/'); context.projection - .scale(667544.214430109) // z14 + .scale(iD.geoZoomToScale(14)) .translate([-116508, 0]) // 10,0 .clipExtent([[0,0], dimensions]); diff --git a/test/spec/services/openstreetcam.js b/test/spec/services/openstreetcam.js index a3f512986..13d03b56a 100644 --- a/test/spec/services/openstreetcam.js +++ b/test/spec/services/openstreetcam.js @@ -1,6 +1,6 @@ describe('iD.serviceOpenstreetcam', function() { - var dimensions = [64, 64], - context, server, openstreetcam; + var dimensions = [64, 64]; + var context, server, openstreetcam; before(function() { iD.services.openstreetcam = iD.serviceOpenstreetcam; @@ -13,7 +13,7 @@ describe('iD.serviceOpenstreetcam', function() { beforeEach(function() { context = iD.coreContext().assetPath('../dist/'); context.projection - .scale(667544.214430109) // z14 + .scale(iD.geoZoomToScale(14)) .translate([-116508, 0]) // 10,0 .clipExtent([[0,0], dimensions]); diff --git a/test/spec/services/osm.js b/test/spec/services/osm.js index 0bc95d8f3..476ff73c3 100644 --- a/test/spec/services/osm.js +++ b/test/spec/services/osm.js @@ -596,21 +596,42 @@ describe('iD.serviceOsm', function () { }); describe('#loadNotes', function() { + var notesXML = '' + + '' + + '' + + ' 1' + + ' https://www.openstreetmap.org/api/0.6/notes/1' + + ' https://www.openstreetmap.org/api/0.6/notes/1/comment' + + ' https://www.openstreetmap.org/api/0.6/notes/1/close' + + ' 2019-01-01 00:00:00 UTC' + + ' open' + + ' ' + + ' ' + + ' 2019-01-01 00:00:00 UTC' + + ' 1' + + ' Steve' + + ' https://www.openstreetmap.org/user/Steve' + + ' opened' + + ' This is a note' + + ' <p>This is a note</p>' + + ' ' + + ' ' + + '' + + ''; + beforeEach(function() { + var dimensions = [64, 64]; context.projection - .scale(116722210.56960216) - .translate([244505613.61327893, 74865520.92230521]) - .clipExtent([[0,0], [609.34375, 826]]); + .scale(iD.geoZoomToScale(14)) + .translate([-116508, 0]) // 10,0 + .clipExtent([[0,0], dimensions]); }); it('fires loadedNotes when notes are loaded', function() { connection.on('loadedNotes', spy); - connection.loadNotes(context.projection, [64, 64], {}); + connection.loadNotes(context.projection, {}); - var url = 'http://www.openstreetmap.org/api/0.6/notes?limit=10000&closed=7&bbox=-120.05859375,34.45221847282654,-119.970703125,34.52466147177173'; - var notesXML = ''; // TODO: determine output even though this test note is closed and will be gone soon - - server.respondWith('GET', url, + server.respondWith('GET', /notes\?/, [200, { 'Content-Type': 'text/xml' }, notesXML ]); server.respond(); @@ -623,7 +644,7 @@ describe('iD.serviceOsm', function () { beforeEach(function() { var dimensions = [64, 64]; context.projection - .scale(667544.214430109) // z14 + .scale(iD.geoZoomToScale(14)) .translate([-116508, 0]) // 10,0 .clipExtent([[0,0], dimensions]); }); @@ -646,17 +667,17 @@ describe('iD.serviceOsm', function () { describe('#getNote', function() { - it('returns a note', function (done) { - var note = iD.osmNote({ id: 1, loc: [0, 0], }); - var obj = { - note: { note: { 1: note } } - }; - connection.caches(obj); - var result = connection.getNote(1); - expect(result).to.deep.equal(note); - done(); - }); + it('returns a note', function (done) { + var note = iD.osmNote({ id: 1, loc: [0, 0], }); + var obj = { + note: { note: { 1: note } } + }; + connection.caches(obj); + var result = connection.getNote(1); + expect(result).to.deep.equal(note); + done(); }); + }); describe('#removeNote', function() { it('removes a note that is new', function(done) { @@ -701,7 +722,8 @@ describe('iD.serviceOsm', function () { describe('API capabilities', function() { - var capabilitiesXML = '' + + var capabilitiesXML = '' + + '' + '' + '' + '' + diff --git a/test/spec/services/streetside.js b/test/spec/services/streetside.js index b8adb2f1c..8221718d1 100644 --- a/test/spec/services/streetside.js +++ b/test/spec/services/streetside.js @@ -1,6 +1,6 @@ describe('iD.serviceStreetside', function() { - var dimensions = [64, 64], - context, server, streetside; + var dimensions = [64, 64]; + var context, server, streetside; before(function() { iD.services.streetside = iD.serviceStreetside; @@ -13,7 +13,7 @@ describe('iD.serviceStreetside', function() { beforeEach(function() { context = iD.coreContext().assetPath('../dist/'); context.projection - .scale(667544.214430109) // z14 + .scale(iD.geoZoomToScale(14)) .translate([-116508, 0]) // 10,0 .clipExtent([[0,0], dimensions]); @@ -53,7 +53,7 @@ describe('iD.serviceStreetside', function() { // adjust projection so that only one tile is fetched // (JSONP hack will return the same data for every fetch) context.projection - .scale(10680707.430881744) // z18 + .scale(iD.geoZoomToScale(18)) .translate([-1863988.9381333336, 762.8270222954452]) // 10.002,0.002 .clipExtent([[0,0], dimensions]); @@ -84,7 +84,7 @@ describe('iD.serviceStreetside', function() { it('does not load bubbles around null island', function() { context.projection - .scale(10680707.430881744) // z18 + .scale(iD.geoZoomToScale(18)) .translate([0, 0]) .clipExtent([[0,0], dimensions]);