From d0452e6be418ab1e0830b9b072f5d339cd07d1e3 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Fri, 26 Apr 2019 22:29:48 -0400 Subject: [PATCH] Convert fakeServer tests to use fakeFetch - Many text expects are now wrapped in setTimeout, as the fetch promises settle async now. - This makes the tests somewhat brittle, and we should maybe consider reworking some of them. For example it is very hard to perform a test like `expect(spy).to.have.not.been.called` in an async way. (We could instead inspect the fakeServer requests() to know this.) - Also includes some trickery for osm.js, which uses d3-xml (fetch) now for unauthenticated calls and osmauth (xhr) for authenticated calls --- test/spec/presets/index.js | 2 +- test/spec/services/mapillary.js | 45 +++-- test/spec/services/nominatim.js | 110 +++++++----- test/spec/services/openstreetcam.js | 23 ++- test/spec/services/osm.js | 267 ++++++++++------------------ test/spec/services/osm_wikibase.js | 37 ++-- test/spec/services/streetside.js | 18 +- test/spec/services/taginfo.js | 241 +++++++++++++++---------- test/spec/ui/fields/wikipedia.js | 6 +- 9 files changed, 389 insertions(+), 360 deletions(-) diff --git a/test/spec/presets/index.js b/test/spec/presets/index.js index c874b314b..3da1a6fab 100644 --- a/test/spec/presets/index.js +++ b/test/spec/presets/index.js @@ -245,7 +245,7 @@ describe('iD.presetIndex', function () { }; beforeEach(function () { - server = sinon.fakeServer.create(); + server = window.fakeFetch().create(); }); afterEach(function () { diff --git a/test/spec/services/mapillary.js b/test/spec/services/mapillary.js index 8642b9b51..a6f21c344 100644 --- a/test/spec/services/mapillary.js +++ b/test/spec/services/mapillary.js @@ -18,7 +18,7 @@ describe('iD.serviceMapillary', function() { .translate([-116508, 0]) // 10,0 .clipExtent([[0,0], dimensions]); - server = sinon.fakeServer.create(); + server = window.fakeFetch().create(); mapillary = iD.services.mapillary; mapillary.reset(); }); @@ -54,7 +54,7 @@ describe('iD.serviceMapillary', function() { }); describe('#loadImages', function() { - it('fires loadedImages when images are loaded', function() { + it('fires loadedImages when images are loaded', function(done) { var spy = sinon.spy(); mapillary.on('loadedImages', spy); mapillary.loadImages(context.projection); @@ -71,10 +71,13 @@ describe('iD.serviceMapillary', function() { [200, { 'Content-Type': 'application/json' }, JSON.stringify(response) ]); server.respond(); - expect(spy).to.have.been.calledOnce; + window.setTimeout(function() { + expect(spy).to.have.been.calledOnce; + done(); + }, 50); }); - it('does not load images around null island', function() { + it('does not load images around null island', function(done) { var spy = sinon.spy(); context.projection.translate([0,0]); mapillary.on('loadedImages', spy); @@ -92,10 +95,13 @@ describe('iD.serviceMapillary', function() { [200, { 'Content-Type': 'application/json' }, JSON.stringify(response) ]); server.respond(); - expect(spy).to.have.been.not.called; + window.setTimeout(function() { + expect(spy).to.have.been.not.called; + done(); + }, 50); }); - it.skip('loads multiple pages of image results', function() { + it.skip('loads multiple pages of image results', function(done) { var spy = sinon.spy(); mapillary.on('loadedImages', spy); mapillary.loadImages(context.projection); @@ -130,12 +136,16 @@ describe('iD.serviceMapillary', function() { [200, { 'Content-Type': 'application/json' }, JSON.stringify(response1) ]); server.respond(); - expect(spy).to.have.been.calledTwice; + window.setTimeout(function() { + expect(spy).to.have.been.calledTwice; + done(); + }, 50); }); }); + describe('#loadSigns', function() { - it('fires loadedSigns when signs are loaded', function() { + it('fires loadedSigns when signs are loaded', function(done) { var spy = sinon.spy(); mapillary.on('loadedSigns', spy); mapillary.loadSigns(context, context.projection); @@ -156,10 +166,13 @@ describe('iD.serviceMapillary', function() { [200, { 'Content-Type': 'application/json' }, JSON.stringify(response) ]); server.respond(); - expect(spy).to.have.been.calledOnce; + window.setTimeout(function() { + expect(spy).to.have.been.calledOnce; + done(); + }, 50); }); - it('does not load signs around null island', function() { + it('does not load signs around null island', function(done) { var spy = sinon.spy(); context.projection.translate([0,0]); mapillary.on('loadedSigns', spy); @@ -181,10 +194,13 @@ describe('iD.serviceMapillary', function() { [200, { 'Content-Type': 'application/json' }, JSON.stringify(response) ]); server.respond(); - expect(spy).to.have.been.not.called; + window.setTimeout(function() { + expect(spy).to.have.been.not.called; + done(); + }, 50); }); - it.skip('loads multiple pages of signs results', function() { + it.skip('loads multiple pages of signs results', function(done) { var spy = sinon.spy(); mapillary.on('loadedSigns', spy); mapillary.loadSigns(context, context.projection); @@ -226,7 +242,10 @@ describe('iD.serviceMapillary', function() { [200, { 'Content-Type': 'application/json' }, JSON.stringify(response1) ]); server.respond(); - expect(spy).to.have.been.calledTwice; + window.setTimeout(function() { + expect(spy).to.have.been.calledTwice; + done(); + }, 50); }); }); diff --git a/test/spec/services/nominatim.js b/test/spec/services/nominatim.js index fb984039b..8773018a9 100644 --- a/test/spec/services/nominatim.js +++ b/test/spec/services/nominatim.js @@ -11,7 +11,7 @@ describe('iD.serviceNominatim', function() { }); beforeEach(function() { - server = sinon.fakeServer.create(); + server = window.fakeFetch().create(); nominatim = iD.services.geocoder; nominatim.reset(); }); @@ -26,7 +26,7 @@ describe('iD.serviceNominatim', function() { describe('#countryCode', function() { - it('calls the given callback with the results of the country code query', function() { + it('calls the given callback with the results of the country code query', function(done) { var callback = sinon.spy(); nominatim.countryCode([16, 48], callback); @@ -35,69 +35,83 @@ describe('iD.serviceNominatim', function() { '{"address":{"country_code":"at"}}']); server.respond(); - expect(query(server.requests[0].url)).to.eql( - {zoom: '13', format: 'json', addressdetails: '1', lat: '48', lon: '16'}); - expect(callback).to.have.been.calledWithExactly(null, 'at'); + window.setTimeout(function() { + expect(query(server.requests()[0].url)).to.eql( + {zoom: '13', format: 'json', addressdetails: '1', lat: '48', lon: '16'} + ); + expect(callback).to.have.been.calledWithExactly(null, 'at'); + done(); + }, 50); }); }); describe('#reverse', function() { - it('should not cache distant result', function() { + it('should not cache distant result', function(done) { var callback = sinon.spy(); nominatim.reverse([16, 48], callback); server.respondWith('GET', new RegExp('https://nominatim.openstreetmap.org/reverse'), - [200, { 'Content-Type': 'application/json' }, - '{"address":{"country_code":"at"}}']); + [200, { 'Content-Type': 'application/json' }, '{"address":{"country_code":"at"}}']); server.respond(); - expect(query(server.requests[0].url)).to.eql( - {zoom: '13', format: 'json', addressdetails: '1', lat: '48', lon: '16'}); - expect(callback).to.have.been.calledWithExactly(null, {address: {country_code:'at'}}); + window.setTimeout(function() { + expect(query(server.requests()[0].url)).to.eql( + {zoom: '13', format: 'json', addressdetails: '1', lat: '48', lon: '16'} + ); + expect(callback).to.have.been.calledWithExactly(null, {address: {country_code:'at'}}); - server.restore(); - server = sinon.fakeServer.create(); + server.restore(); + server = window.fakeFetch().create(); - callback = sinon.spy(); - nominatim.reverse([17, 49], callback); + callback = sinon.spy(); + nominatim.reverse([17, 49], callback); - server.respondWith('GET', new RegExp('https://nominatim.openstreetmap.org/reverse'), - [200, { 'Content-Type': 'application/json' }, - '{"address":{"country_code":"cz"}}']); - server.respond(); + server.respondWith('GET', new RegExp('https://nominatim.openstreetmap.org/reverse'), + [200, { 'Content-Type': 'application/json' }, '{"address":{"country_code":"cz"}}']); + server.respond(); - expect(query(server.requests[0].url)).to.eql( - {zoom: '13', format: 'json', addressdetails: '1', lat: '49', lon: '17'}); - expect(callback).to.have.been.calledWithExactly(null, {address: {country_code:'cz'}}); + window.setTimeout(function() { + expect(query(server.requests()[0].url)).to.eql( + {zoom: '13', format: 'json', addressdetails: '1', lat: '49', lon: '17'} + ); + expect(callback).to.have.been.calledWithExactly(null, {address: {country_code:'cz'}}); + done(); + }, 50); + }, 50); }); - it('should cache nearby result', function() { + it('should cache nearby result', function(done) { var callback = sinon.spy(); nominatim.reverse([16, 48], callback); server.respondWith('GET', new RegExp('https://nominatim.openstreetmap.org/reverse'), - [200, { 'Content-Type': 'application/json' }, - '{"address":{"country_code":"at"}}']); + [200, { 'Content-Type': 'application/json' }, '{"address":{"country_code":"at"}}']); server.respond(); - expect(query(server.requests[0].url)).to.eql( - {zoom: '13', format: 'json', addressdetails: '1', lat: '48', lon: '16'}); - expect(callback).to.have.been.calledWithExactly(null, {address: {country_code:'at'}}); + window.setTimeout(function() { + expect(query(server.requests()[0].url)).to.eql( + {zoom: '13', format: 'json', addressdetails: '1', lat: '48', lon: '16'} + ); + expect(callback).to.have.been.calledWithExactly(null, {address: {country_code:'at'}}); - server.restore(); - server = sinon.fakeServer.create(); + server.restore(); + server = window.fakeFetch().create(); - callback = sinon.spy(); - nominatim.reverse([16.000001, 48.000001], callback); + callback = sinon.spy(); + nominatim.reverse([16.000001, 48.000001], callback); - server.respondWith('GET', new RegExp('https://nominatim.openstreetmap.org/reverse'), - [200, { 'Content-Type': 'application/json' }, - '{"address":{"country_code":"cz"}}']); - server.respond(); - expect(callback).to.have.been.calledWithExactly(null, {address: {country_code:'at'}}); + server.respondWith('GET', new RegExp('https://nominatim.openstreetmap.org/reverse'), + [200, { 'Content-Type': 'application/json' }, '{"address":{"country_code":"cz"}}']); + server.respond(); + + window.setTimeout(function() { + expect(callback).to.have.been.calledWithExactly(null, {address: {country_code:'at'}}); + done(); + }, 50); + }, 50); }); - it('calls the given callback with an error', function() { + it('calls the given callback with an error', function(done) { var callback = sinon.spy(); nominatim.reverse([1000, 1000], callback); @@ -106,16 +120,19 @@ describe('iD.serviceNominatim', function() { '{"error":"Unable to geocode"}']); server.respond(); - expect(query(server.requests[0].url)).to.eql( - {zoom: '13', format: 'json', addressdetails: '1', lat: '1000', lon: '1000'}); - expect(callback).to.have.been.calledWithExactly('Unable to geocode'); + window.setTimeout(function() { + expect(query(server.requests()[0].url)).to.eql( + {zoom: '13', format: 'json', addressdetails: '1', lat: '1000', lon: '1000'} + ); + expect(callback).to.have.been.calledWithExactly('Unable to geocode'); + done(); + }, 50); }); }); describe('#search', function() { - - it('calls the given callback with the results of the search query', function() { + it('calls the given callback with the results of the search query', function(done) { var callback = sinon.spy(); nominatim.search('philadelphia', callback); @@ -125,8 +142,11 @@ describe('iD.serviceNominatim', function() { ]); server.respond(); - expect(query(server.requests[0].url)).to.eql({format: 'json', limit: '10'}); - expect(callback).to.have.been.calledOnce; + window.setTimeout(function() { + expect(query(server.requests()[0].url)).to.eql({format: 'json', limit: '10'}); + expect(callback).to.have.been.calledOnce; + done(); + }, 50); }); }); diff --git a/test/spec/services/openstreetcam.js b/test/spec/services/openstreetcam.js index 13d03b56a..a12c48291 100644 --- a/test/spec/services/openstreetcam.js +++ b/test/spec/services/openstreetcam.js @@ -17,7 +17,7 @@ describe('iD.serviceOpenstreetcam', function() { .translate([-116508, 0]) // 10,0 .clipExtent([[0,0], dimensions]); - server = sinon.fakeServer.create(); + server = window.fakeFetch().create(); openstreetcam = iD.services.openstreetcam; openstreetcam.reset(); }); @@ -51,7 +51,7 @@ describe('iD.serviceOpenstreetcam', function() { }); describe('#loadImages', function() { - it('fires loadedImages when images are loaded', function() { + it('fires loadedImages when images are loaded', function(done) { var spy = sinon.spy(); openstreetcam.on('loadedImages', spy); openstreetcam.loadImages(context.projection); @@ -102,10 +102,13 @@ describe('iD.serviceOpenstreetcam', function() { [200, { 'Content-Type': 'application/json' }, JSON.stringify(data) ]); server.respond(); - expect(spy).to.have.been.calledOnce; + window.setTimeout(function() { + expect(spy).to.have.been.calledOnce; + done(); + }, 50); }); - it('does not load images around null island', function() { + it('does not load images around null island', function(done) { var spy = sinon.spy(); context.projection.translate([0,0]); openstreetcam.on('loadedImages', spy); @@ -157,10 +160,13 @@ describe('iD.serviceOpenstreetcam', function() { [200, { 'Content-Type': 'application/json' }, JSON.stringify(data) ]); server.respond(); - expect(spy).to.have.been.not.called; + window.setTimeout(function() { + expect(spy).to.have.been.not.called; + done(); + }, 50); }); - it.skip('loads multiple pages of image results', function() { + it.skip('loads multiple pages of image results', function(done) { var spy = sinon.spy(); openstreetcam.on('loadedImages', spy); openstreetcam.loadImages(context.projection); @@ -222,7 +228,10 @@ describe('iD.serviceOpenstreetcam', function() { }); server.respond(); - expect(spy).to.have.been.calledTwice; + window.setTimeout(function() { + expect(spy).to.have.been.calledTwice; + done(); + }, 50); }); }); diff --git a/test/spec/services/osm.js b/test/spec/services/osm.js index cfccfd0b6..45c438f5f 100644 --- a/test/spec/services/osm.js +++ b/test/spec/services/osm.js @@ -1,8 +1,8 @@ describe('iD.serviceOsm', function () { - var context, connection, server, spy; + var context, connection, spy; + var serverFetch, serverXHR; function login() { - if (!connection) return; connection.switch({ urlroot: 'http://www.openstreetmap.org', oauth_consumer_key: '5A043yRSEugj4DJ5TljuapfnrflWDte8jTOcWLlT', @@ -13,7 +13,6 @@ describe('iD.serviceOsm', function () { } function logout() { - if (!connection) return; connection.logout(); } @@ -26,7 +25,8 @@ describe('iD.serviceOsm', function () { }); beforeEach(function () { - server = sinon.fakeServer.create(); + serverFetch = window.fakeFetch().create(); // unauthenticated calls use d3-fetch + serverXHR = sinon.fakeServer.create(); // authenticated calls use XHR via osm-auth context = iD.coreContext(); connection = context.connection(); connection.switch({ urlroot: 'http://www.openstreetmap.org' }); @@ -35,7 +35,8 @@ describe('iD.serviceOsm', function () { }); afterEach(function() { - server.restore(); + serverFetch.restore(); + serverXHR.restore(); }); @@ -139,43 +140,33 @@ describe('iD.serviceOsm', function () { describe('#loadFromAPI', function () { var path = '/api/0.6/map?bbox=-74.542,40.655,-74.541,40.656'; var response = '' + - '' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ''; + '' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ''; - beforeEach(function() { - connection.reset(); - server = sinon.fakeServer.create(); - spy = sinon.spy(); - }); - - afterEach(function() { - server.restore(); - }); - - - it('returns an object', function (done) { + it('returns an object', function(done) { connection.loadFromAPI(path, function (err, xml) { expect(err).to.not.be.ok; expect(typeof xml).to.eql('object'); done(); }); - server.respondWith('GET', 'http://www.openstreetmap.org' + path, + serverFetch.respondWith('GET', 'http://www.openstreetmap.org' + path, [200, { 'Content-Type': 'text/xml' }, response]); - server.respond(); + serverFetch.respond(); }); it('retries an authenticated call unauthenticated if 400 Bad Request', function (done) { login(); + connection.loadFromAPI(path, function (err, xml) { expect(err).to.be.not.ok; expect(typeof xml).to.eql('object'); @@ -183,17 +174,13 @@ describe('iD.serviceOsm', function () { done(); }); - server.respondWith('GET', 'http://www.openstreetmap.org' + path, - function(request) { - if (connection.authenticated()) { - return request.respond(400, {}); - } else { - return request.respond(200, { 'Content-Type': 'text/xml' }, response); - } - } - ); - server.respond(); - server.respond(); + serverXHR.respondWith('GET', 'http://www.openstreetmap.org' + path, + [400, { 'Content-Type': 'text/plain' }, 'Bad Request']); + serverFetch.respondWith('GET', 'http://www.openstreetmap.org' + path, + [200, { 'Content-Type': 'text/xml' }, response]); + + serverXHR.respond(); + serverFetch.respond(); }); it('retries an authenticated call unauthenticated if 401 Unauthorized', function (done) { @@ -205,17 +192,13 @@ describe('iD.serviceOsm', function () { done(); }); - server.respondWith('GET', 'http://www.openstreetmap.org' + path, - function(request) { - if (connection.authenticated()) { - return request.respond(401, {}); - } else { - return request.respond(200, { 'Content-Type': 'text/xml' }, response); - } - } - ); - server.respond(); - server.respond(); + serverXHR.respondWith('GET', 'http://www.openstreetmap.org' + path, + [401, { 'Content-Type': 'text/plain' }, 'Unauthorized']); + serverFetch.respondWith('GET', 'http://www.openstreetmap.org' + path, + [200, { 'Content-Type': 'text/xml' }, response]); + + serverXHR.respond(); + serverFetch.respond(); }); it('retries an authenticated call unauthenticated if 403 Forbidden', function (done) { @@ -227,17 +210,13 @@ describe('iD.serviceOsm', function () { done(); }); - server.respondWith('GET', 'http://www.openstreetmap.org' + path, - function(request) { - if (connection.authenticated()) { - return request.respond(403, {}); - } else { - return request.respond(200, { 'Content-Type': 'text/xml' }, response); - } - } - ); - server.respond(); - server.respond(); + serverXHR.respondWith('GET', 'http://www.openstreetmap.org' + path, + [403, { 'Content-Type': 'text/plain' }, 'Forbidden']); + serverFetch.respondWith('GET', 'http://www.openstreetmap.org' + path, + [200, { 'Content-Type': 'text/xml' }, response]); + + serverXHR.respond(); + serverFetch.respond(); }); @@ -250,20 +229,9 @@ describe('iD.serviceOsm', function () { done(); }); - server.respondWith('GET', 'http://www.openstreetmap.org' + path, - function(request) { - if (!connection.authenticated()) { - // workaround: sinon.js seems to call error handler with a - // sinon.Event instead of the target XMLHttpRequest object.. - var orig = request.onreadystatechange; - request.onreadystatechange = function(o) { orig((o && o.target) || o); }; - return request.respond(509, {}); - } else { - return request.respond(200, { 'Content-Type': 'text/xml' }, response); - } - } - ); - server.respond(); + serverFetch.respondWith('GET', 'http://www.openstreetmap.org' + path, + [509, { 'Content-Type': 'text/plain' }, 'Bandwidth Limit Exceeded']); + serverFetch.respond(); }); it('dispatches change event if 429 Too Many Requests', function (done) { @@ -275,20 +243,9 @@ describe('iD.serviceOsm', function () { done(); }); - server.respondWith('GET', 'http://www.openstreetmap.org' + path, - function(request) { - if (!connection.authenticated()) { - // workaround: sinon.js seems to call error handler with a - // sinon.Event instead of the target XMLHttpRequest object.. - var orig = request.onreadystatechange; - request.onreadystatechange = function(o) { orig((o && o.target) || o); }; - return request.respond(429, {}); - } else { - return request.respond(200, { 'Content-Type': 'text/xml' }, response); - } - } - ); - server.respond(); + serverFetch.respondWith('GET', 'http://www.openstreetmap.org' + path, + [429, { 'Content-Type': 'text/plain' }, '429 Too Many Requests']); + serverFetch.respond(); }); }); @@ -320,28 +277,28 @@ describe('iD.serviceOsm', function () { var spy = sinon.spy(); connection.loadTiles(context.projection, spy); - server.respondWith('GET', /map\?bbox/, + serverFetch.respondWith('GET', /map\?bbox/, [200, { 'Content-Type': 'text/xml' }, tileXML]); - server.respond(); + serverFetch.respond(); window.setTimeout(function() { expect(spy).to.have.been.calledOnce; done(); - }, 20); + }, 50); }); it('#isDataLoaded', function(done) { expect(connection.isDataLoaded([-74.0444216, 40.6694299])).to.be.not.ok; connection.loadTiles(context.projection); - server.respondWith('GET', /map\?bbox/, + serverFetch.respondWith('GET', /map\?bbox/, [200, { 'Content-Type': 'text/xml' }, tileXML]); - server.respond(); + serverFetch.respond(); window.setTimeout(function() { expect(connection.isDataLoaded([-74.0444216, 40.6694299])).to.be.ok; done(); - }, 20); + }, 50); }); }); @@ -356,14 +313,6 @@ describe('iD.serviceOsm', function () { '' + ''; - beforeEach(function() { - server = sinon.fakeServer.create(); - }); - - afterEach(function() { - server.restore(); - }); - it('loads a node', function(done) { var id = 'n1'; connection.loadEntity(id, function(err, result) { @@ -372,9 +321,9 @@ describe('iD.serviceOsm', function () { done(); }); - server.respondWith('GET', 'http://www.openstreetmap.org/api/0.6/node/1', + serverFetch.respondWith('GET', 'http://www.openstreetmap.org/api/0.6/node/1', [200, { 'Content-Type': 'text/xml' }, nodeXML]); - server.respond(); + serverFetch.respond(); }); it('loads a way', function(done) { @@ -385,9 +334,9 @@ describe('iD.serviceOsm', function () { done(); }); - server.respondWith('GET', 'http://www.openstreetmap.org/api/0.6/way/1/full', + serverFetch.respondWith('GET', 'http://www.openstreetmap.org/api/0.6/way/1/full', [200, { 'Content-Type': 'text/xml' }, wayXML]); - server.respond(); + serverFetch.respond(); }); it('does not ignore repeat requests', function(done) { @@ -400,12 +349,12 @@ describe('iD.serviceOsm', function () { expect(entity2).to.be.an.instanceOf(iD.osmNode); done(); }); - server.respond(); + serverFetch.respond(); }); - server.respondWith('GET', 'http://www.openstreetmap.org/api/0.6/node/1', + serverFetch.respondWith('GET', 'http://www.openstreetmap.org/api/0.6/node/1', [200, { 'Content-Type': 'text/xml' }, nodeXML]); - server.respond(); + serverFetch.respond(); }); }); @@ -420,14 +369,6 @@ describe('iD.serviceOsm', function () { '' + ''; - beforeEach(function() { - server = sinon.fakeServer.create(); - }); - - afterEach(function() { - server.restore(); - }); - it('loads a node', function(done) { var id = 'n1'; connection.loadEntityVersion(id, 1, function(err, result) { @@ -436,9 +377,9 @@ describe('iD.serviceOsm', function () { done(); }); - server.respondWith('GET', 'http://www.openstreetmap.org/api/0.6/node/1/1', + serverFetch.respondWith('GET', 'http://www.openstreetmap.org/api/0.6/node/1/1', [200, { 'Content-Type': 'text/xml' }, nodeXML]); - server.respond(); + serverFetch.respond(); }); it('loads a way', function(done) { @@ -449,9 +390,9 @@ describe('iD.serviceOsm', function () { done(); }); - server.respondWith('GET', 'http://www.openstreetmap.org/api/0.6/way/1/1', + serverFetch.respondWith('GET', 'http://www.openstreetmap.org/api/0.6/way/1/1', [200, { 'Content-Type': 'text/xml' }, wayXML]); - server.respond(); + serverFetch.respond(); }); it('does not ignore repeat requests', function(done) { @@ -464,25 +405,17 @@ describe('iD.serviceOsm', function () { expect(entity2).to.be.an.instanceOf(iD.osmNode); done(); }); - server.respond(); + serverFetch.respond(); }); - server.respondWith('GET', 'http://www.openstreetmap.org/api/0.6/node/1/1', + serverFetch.respondWith('GET', 'http://www.openstreetmap.org/api/0.6/node/1/1', [200, { 'Content-Type': 'text/xml' }, nodeXML]); - server.respond(); + serverFetch.respond(); }); }); describe('#loadMultiple', function () { - beforeEach(function() { - server = sinon.fakeServer.create(); - }); - - afterEach(function() { - server.restore(); - }); - it('loads nodes'); it('loads ways'); it('does not ignore repeat requests'); @@ -493,7 +426,6 @@ describe('iD.serviceOsm', function () { var userDetailsFn; beforeEach(function() { - server = sinon.fakeServer.create(); userDetailsFn = connection.userDetails; connection.userDetails = function (callback) { callback(undefined, { id: 1, displayName: 'Steve' }); @@ -501,7 +433,6 @@ describe('iD.serviceOsm', function () { }); afterEach(function() { - server.restore(); connection.userDetails = userDetailsFn; }); @@ -527,9 +458,9 @@ describe('iD.serviceOsm', function () { done(); }); - server.respondWith('GET', 'http://www.openstreetmap.org/api/0.6/changesets?user=1', + serverXHR.respondWith('GET', 'http://www.openstreetmap.org/api/0.6/changesets?user=1', [200, { 'Content-Type': 'text/xml' }, changesetsXML]); - server.respond(); + serverXHR.respond(); }); it('excludes changesets without comment tag', function(done) { @@ -556,9 +487,9 @@ describe('iD.serviceOsm', function () { done(); }); - server.respondWith('GET', 'http://www.openstreetmap.org/api/0.6/changesets?user=1', + serverXHR.respondWith('GET', 'http://www.openstreetmap.org/api/0.6/changesets?user=1', [200, { 'Content-Type': 'text/xml' }, changesetsXML]); - server.respond(); + serverXHR.respond(); }); it('excludes changesets with empty comment', function(done) { @@ -586,34 +517,31 @@ describe('iD.serviceOsm', function () { done(); }); - server.respondWith('GET', 'http://www.openstreetmap.org/api/0.6/changesets?user=1', + serverXHR.respondWith('GET', 'http://www.openstreetmap.org/api/0.6/changesets?user=1', [200, { 'Content-Type': 'text/xml' }, changesetsXML]); - server.respond(); + serverXHR.respond(); }); - }); describe('#caches', function() { - it('loads reset caches', function (done) { + it('loads reset caches', function () { var caches = connection.caches(); expect(caches.tile).to.have.all.keys(['toLoad','loaded','inflight','seen','rtree']); expect(caches.note).to.have.all.keys(['toLoad','loaded','inflight','inflightPost','note','closed','rtree']); expect(caches.user).to.have.all.keys(['toLoad','user']); - done(); }); describe('sets/gets caches', function() { - it('sets/gets a tile', function (done) { + it('sets/gets a tile', function () { var obj = { tile: { loaded: { '1,2,16': true, '3,4,16': true } } }; connection.caches(obj); expect(connection.caches().tile.loaded['1,2,16']).to.eql(true); expect(Object.keys(connection.caches().tile.loaded).length).to.eql(2); - done(); }); - it('sets/gets a note', function (done) { + it('sets/gets a note', function () { var note = iD.osmNote({ id: 1, loc: [0, 0] }); var note2 = iD.osmNote({ id: 2, loc: [0, 0] }); var obj = { @@ -622,10 +550,9 @@ describe('iD.serviceOsm', function () { connection.caches(obj); expect(connection.caches().note.note[note.id]).to.eql(note); expect(Object.keys(connection.caches().note.note).length).to.eql(2); - done(); }); - it('sets/gets a user', function (done) { + it('sets/gets a user', function () { var user = { id: 1, display_name: 'Name' }; var user2 = { id: 2, display_name: 'Name' }; var obj = { @@ -634,7 +561,6 @@ describe('iD.serviceOsm', function () { connection.caches(obj); expect(connection.caches().user.user[user.id]).to.eql(user); expect(Object.keys(connection.caches().user.user).length).to.eql(2); - done(); }); }); @@ -676,14 +602,14 @@ describe('iD.serviceOsm', function () { connection.on('loadedNotes', spy); connection.loadNotes(context.projection, {}); - server.respondWith('GET', /notes\?/, + serverFetch.respondWith('GET', /notes\?/, [200, { 'Content-Type': 'text/xml' }, notesXML ]); - server.respond(); + serverFetch.respond(); window.setTimeout(function() { expect(spy).to.have.been.calledOnce; done(); - }, 20); + }, 50); }); }); @@ -696,6 +622,7 @@ describe('iD.serviceOsm', function () { .translate([-116508, 0]) // 10,0 .clipExtent([[0,0], dimensions]); }); + it('returns notes in the visible map area', function() { var notes = [ { minX: 10, minY: 0, maxX: 10, maxY: 0, data: { key: '0', loc: [10,0] } }, @@ -715,7 +642,7 @@ describe('iD.serviceOsm', function () { describe('#getNote', function() { - it('returns a note', function (done) { + it('returns a note', function () { var note = iD.osmNote({ id: 1, loc: [0, 0], }); var obj = { note: { note: { 1: note } } @@ -723,24 +650,22 @@ describe('iD.serviceOsm', function () { 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) { + it('removes a note that is new', function() { var note = iD.osmNote({ id: -1, loc: [0, 0], }); connection.replaceNote(note); connection.removeNote(note); var result = connection.getNote(-1); expect(result).to.eql(undefined); - done(); }); }); describe('#replaceNote', function() { - it('returns a new note', function (done) { + it('returns a new note', function () { var note = iD.osmNote({ id: 2, loc: [0, 0], }); var result = connection.replaceNote(note); expect(result.id).to.eql(2); @@ -749,10 +674,9 @@ describe('iD.serviceOsm', function () { var result_rtree = rtree.search({ 'minX': -1, 'minY': -1, 'maxX': 1, 'maxY': 1 }); expect(result_rtree.length).to.eql(1); expect(result_rtree[0].data).to.eql(note); - done(); }); - it('replaces a note', function (done) { + it('replaces a note', function () { var note = iD.osmNote({ id: 2, loc: [0, 0], }); connection.replaceNote(note); note.status = 'closed'; @@ -763,8 +687,6 @@ describe('iD.serviceOsm', function () { var result_rtree = rtree.search({ 'minX': -1, 'minY': -1, 'maxX': 1, 'maxY': 1 }); expect(result_rtree.length).to.eql(1); expect(result_rtree[0].data.status).to.eql('closed'); - - done(); }); }); @@ -787,15 +709,6 @@ describe('iD.serviceOsm', function () { '' + ''; - - beforeEach(function() { - server = sinon.fakeServer.create(); - }); - - afterEach(function() { - server.restore(); - }); - describe('#status', function() { it('gets API status', function(done) { connection.status(function(err, val) { @@ -803,9 +716,9 @@ describe('iD.serviceOsm', function () { done(); }); - server.respondWith('GET', 'http://www.openstreetmap.org/api/capabilities', + serverFetch.respondWith('GET', 'http://www.openstreetmap.org/api/capabilities', [200, { 'Content-Type': 'text/xml' }, capabilitiesXML]); - server.respond(); + serverFetch.respond(); }); }); @@ -817,9 +730,9 @@ describe('iD.serviceOsm', function () { done(); }); - server.respondWith('GET', 'http://www.openstreetmap.org/api/capabilities', + serverFetch.respondWith('GET', 'http://www.openstreetmap.org/api/capabilities', [200, { 'Content-Type': 'text/xml' }, capabilitiesXML]); - server.respond(); + serverFetch.respond(); }); }); diff --git a/test/spec/services/osm_wikibase.js b/test/spec/services/osm_wikibase.js index dc58ae094..ae05015d3 100644 --- a/test/spec/services/osm_wikibase.js +++ b/test/spec/services/osm_wikibase.js @@ -10,9 +10,9 @@ describe('iD.serviceOsmWikibase', function () { }); beforeEach(function () { + server = window.fakeFetch().create(); wikibase = iD.services.osmWikibase; wikibase.init(); - server = sinon.fakeServer.create(); }); afterEach(function () { @@ -273,7 +273,7 @@ describe('iD.serviceOsmWikibase', function () { }; describe('#getEntity', function () { - it('calls the given callback with the results of the getEntity data item query', function () { + it('calls the given callback with the results of the getEntity data item query', function (done) { var callback = sinon.spy(); wikibase.getEntity({key: 'amenity', value: 'parking', langCode: 'fr'}, callback); @@ -289,21 +289,24 @@ describe('iD.serviceOsmWikibase', function () { ); server.respond(); - expect(query(server.requests[0].url)).to.eql( - { - action: 'wbgetentities', - sites: 'wiki', - titles: 'Locale:fr|Key:amenity|Tag:amenity=parking', - languages: 'fr', - languagefallback: '1', - origin: '*', - format: 'json', - } - ); - expect(callback).to.have.been.calledWith(null, { - key: keyData({norm: true}), - tag: tagData({norm: true}) - }); + window.setTimeout(function() { + expect(query(server.requests()[0].url)).to.eql( + { + action: 'wbgetentities', + sites: 'wiki', + titles: 'Locale:fr|Key:amenity|Tag:amenity=parking', + languages: 'fr', + languagefallback: '1', + origin: '*', + format: 'json', + } + ); + expect(callback).to.have.been.calledWith(null, { + key: keyData({norm: true}), + tag: tagData({norm: true}) + }); + done(); + }, 50); }); }); diff --git a/test/spec/services/streetside.js b/test/spec/services/streetside.js index 8221718d1..73d46f3cb 100644 --- a/test/spec/services/streetside.js +++ b/test/spec/services/streetside.js @@ -17,7 +17,7 @@ describe('iD.serviceStreetside', function() { .translate([-116508, 0]) // 10,0 .clipExtent([[0,0], dimensions]); - server = sinon.fakeServer.create(); + server = window.fakeFetch().create(); streetside = iD.services.streetside; streetside.reset(); }); @@ -49,7 +49,7 @@ describe('iD.serviceStreetside', function() { }); describe('#loadBubbles', function() { - it('fires loadedBubbles when bubbles are loaded', function() { + it('fires loadedBubbles when bubbles are loaded', function(done) { // adjust projection so that only one tile is fetched // (JSONP hack will return the same data for every fetch) context.projection @@ -79,10 +79,14 @@ describe('iD.serviceStreetside', function() { ]; streetside.loadBubbles(context.projection, 0); // 0 = don't fetch margin tiles - expect(spy).to.have.been.calledOnce; + + window.setTimeout(function() { + expect(spy).to.have.been.calledOnce; + done(); + }, 50); }); - it('does not load bubbles around null island', function() { + it('does not load bubbles around null island', function(done) { context.projection .scale(iD.geoZoomToScale(18)) .translate([0, 0]) @@ -110,7 +114,11 @@ describe('iD.serviceStreetside', function() { ]; streetside.loadBubbles(context.projection, 0); // 0 = don't fetch margin tiles - expect(spy).to.have.been.not.called; + + window.setTimeout(function() { + expect(spy).to.have.been.not.called; + done(); + }, 50); }); }); diff --git a/test/spec/services/taginfo.js b/test/spec/services/taginfo.js index 6f310e3bc..0f6843e88 100644 --- a/test/spec/services/taginfo.js +++ b/test/spec/services/taginfo.js @@ -11,7 +11,7 @@ describe('iD.serviceTaginfo', function() { }); beforeEach(function() { - server = sinon.fakeServer.create(); + server = window.fakeFetch().create(); taginfo = iD.services.taginfo; // prepopulate popular keys list with "name" @@ -22,7 +22,8 @@ describe('iD.serviceTaginfo', function() { '{"data":[{"count_all":56136034,"key":"name","count_all_fraction":0.0132}]}'] ); server.respond(); - server = sinon.fakeServer.create(); + server.restore(); + server = window.fakeFetch().create(); }); afterEach(function() { @@ -35,7 +36,7 @@ describe('iD.serviceTaginfo', function() { describe('#keys', function() { - it('calls the given callback with the results of the keys query', function() { + it('calls the given callback with the results of the keys query', function(done) { var callback = sinon.spy(); taginfo.keys({query: 'amen'}, callback); @@ -45,15 +46,18 @@ describe('iD.serviceTaginfo', function() { ); server.respond(); - expect(query(server.requests[0].url)).to.eql( - {query: 'amen', page: '1', rp: '10', sortname: 'count_all', sortorder: 'desc', lang: 'en'} - ); - expect(callback).to.have.been.calledWith( - null, [{'title':'amenity', 'value':'amenity'}] - ); + window.setTimeout(function() { + expect(query(server.requests()[0].url)).to.eql( + {query: 'amen', page: '1', rp: '10', sortname: 'count_all', sortorder: 'desc', lang: 'en'} + ); + expect(callback).to.have.been.calledWith( + null, [{'title':'amenity', 'value':'amenity'}] + ); + done(); + }, 50); }); - it('includes popular keys', function() { + it('includes popular keys', function(done) { var callback = sinon.spy(); taginfo.keys({query: 'amen'}, callback); @@ -64,12 +68,15 @@ describe('iD.serviceTaginfo', function() { ); server.respond(); - expect(callback).to.have.been.calledWith( - null, [{'title':'amenity', 'value':'amenity'}] - ); + window.setTimeout(function() { + expect(callback).to.have.been.calledWith( + null, [{'title':'amenity', 'value':'amenity'}] + ); + done(); + }, 50); }); - it('includes popular keys with an entity type filter', function() { + it('includes popular keys with an entity type filter', function(done) { var callback = sinon.spy(); taginfo.keys({query: 'amen', filter: 'nodes'}, callback); @@ -80,12 +87,15 @@ describe('iD.serviceTaginfo', function() { ); server.respond(); - expect(callback).to.have.been.calledWith( - null, [{'title':'amenity', 'value':'amenity'}] - ); + window.setTimeout(function() { + expect(callback).to.have.been.calledWith( + null, [{'title':'amenity', 'value':'amenity'}] + ); + done(); + }, 50); }); - it('includes unpopular keys with a wiki page', function() { + it('includes unpopular keys with a wiki page', function(done) { var callback = sinon.spy(); taginfo.keys({query: 'amen'}, callback); @@ -96,13 +106,16 @@ describe('iD.serviceTaginfo', function() { ); server.respond(); - expect(callback).to.have.been.calledWith(null, [ - {'title':'amenity', 'value':'amenity'}, - {'title':'amenityother', 'value':'amenityother'} - ]); + window.setTimeout(function() { + expect(callback).to.have.been.calledWith(null, [ + {'title':'amenity', 'value':'amenity'}, + {'title':'amenityother', 'value':'amenityother'} + ]); + done(); + }, 50); }); - it('sorts keys with \':\' below keys without \':\'', function() { + it('sorts keys with \':\' below keys without \':\'', function(done) { var callback = sinon.spy(); taginfo.keys({query: 'ref'}, callback); @@ -113,14 +126,17 @@ describe('iD.serviceTaginfo', function() { ); server.respond(); - expect(callback).to.have.been.calledWith( - null, [{'title':'ref', 'value':'ref'},{'title':'ref:bag', 'value':'ref:bag'}] - ); + window.setTimeout(function() { + expect(callback).to.have.been.calledWith( + null, [{'title':'ref', 'value':'ref'},{'title':'ref:bag', 'value':'ref:bag'}] + ); + done(); + }, 50); }); }); describe('#multikeys', function() { - it('calls the given callback with the results of the multikeys query', function() { + it('calls the given callback with the results of the multikeys query', function(done) { var callback = sinon.spy(); taginfo.multikeys({query: 'recycling:'}, callback); @@ -130,15 +146,18 @@ describe('iD.serviceTaginfo', function() { ); server.respond(); - expect(query(server.requests[0].url)).to.eql( - {query: 'recycling:', page: '1', rp: '25', sortname: 'count_all', sortorder: 'desc', lang: 'en'} - ); - expect(callback).to.have.been.calledWith( - null, [{'title':'recycling:glass', 'value':'recycling:glass'}] - ); + window.setTimeout(function() { + expect(query(server.requests()[0].url)).to.eql( + {query: 'recycling:', page: '1', rp: '25', sortname: 'count_all', sortorder: 'desc', lang: 'en'} + ); + expect(callback).to.have.been.calledWith( + null, [{'title':'recycling:glass', 'value':'recycling:glass'}] + ); + done(); + }, 50); }); - it('excludes multikeys with extra colons', function() { + it('excludes multikeys with extra colons', function(done) { var callback = sinon.spy(); taginfo.multikeys({query: 'service:bicycle:'}, callback); @@ -149,12 +168,15 @@ describe('iD.serviceTaginfo', function() { ); server.respond(); - expect(callback).to.have.been.calledWith( - null, [{'title':'service:bicycle:retail', 'value':'service:bicycle:retail'}] - ); + window.setTimeout(function() { + expect(callback).to.have.been.calledWith( + null, [{'title':'service:bicycle:retail', 'value':'service:bicycle:retail'}] + ); + done(); + }, 50); }); - it('excludes multikeys with wrong prefix', function() { + it('excludes multikeys with wrong prefix', function(done) { var callback = sinon.spy(); taginfo.multikeys({query: 'service:bicycle:'}, callback); @@ -165,14 +187,17 @@ describe('iD.serviceTaginfo', function() { ); server.respond(); - expect(callback).to.have.been.calledWith( - null, [{'title':'service:bicycle:retail', 'value':'service:bicycle:retail'}] - ); + window.setTimeout(function() { + expect(callback).to.have.been.calledWith( + null, [{'title':'service:bicycle:retail', 'value':'service:bicycle:retail'}] + ); + done(); + }, 50); }); }); describe('#values', function() { - it('calls the given callback with the results of the values query', function() { + it('calls the given callback with the results of the values query', function(done) { var callback = sinon.spy(); taginfo.values({key: 'amenity', query: 'par'}, callback); @@ -182,15 +207,18 @@ describe('iD.serviceTaginfo', function() { ); server.respond(); - expect(query(server.requests[0].url)).to.eql( - {key: 'amenity', query: 'par', page: '1', rp: '25', sortname: 'count_all', sortorder: 'desc', lang: 'en'} - ); - expect(callback).to.have.been.calledWith( - null, [{'value':'parking','title':'A place for parking cars'}] - ); + window.setTimeout(function() { + expect(query(server.requests()[0].url)).to.eql( + {key: 'amenity', query: 'par', page: '1', rp: '25', sortname: 'count_all', sortorder: 'desc', lang: 'en'} + ); + expect(callback).to.have.been.calledWith( + null, [{'value':'parking','title':'A place for parking cars'}] + ); + done(); + }, 50); }); - it('includes popular values', function() { + it('includes popular values', function(done) { var callback = sinon.spy(); taginfo.values({key: 'amenity', query: 'par'}, callback); @@ -201,12 +229,15 @@ describe('iD.serviceTaginfo', function() { ); server.respond(); - expect(callback).to.have.been.calledWith( - null, [{'value':'parking','title':'A place for parking cars'}] - ); + window.setTimeout(function() { + expect(callback).to.have.been.calledWith( + null, [{'value':'parking','title':'A place for parking cars'}] + ); + done(); + }, 50); }); - it('does not get values for extremely unpopular keys', function() { + it('does not get values for extremely unpopular keys', function(done) { var callback = sinon.spy(); taginfo.values({key: 'name', query: 'ste'}, callback); @@ -217,10 +248,13 @@ describe('iD.serviceTaginfo', function() { ); server.respond(); - expect(callback).to.have.been.calledWith(null, []); + window.setTimeout(function() { + expect(callback).to.have.been.calledWith(null, []); + done(); + }, 50); }); - it('excludes values with capital letters and some punctuation', function() { + it('excludes values with capital letters and some punctuation', function(done) { var callback = sinon.spy(); taginfo.values({key: 'amenity', query: 'par'}, callback); @@ -234,12 +268,15 @@ describe('iD.serviceTaginfo', function() { ); server.respond(); - expect(callback).to.have.been.calledWith( - null, [{'value':'parking','title':'A place for parking cars'}] - ); + window.setTimeout(function() { + expect(callback).to.have.been.calledWith( + null, [{'value':'parking','title':'A place for parking cars'}] + ); + done(); + }, 50); }); - it('includes network values with capital letters and some punctuation', function() { + it('includes network values with capital letters and some punctuation', function(done) { var callback = sinon.spy(); taginfo.values({key: 'network', query: 'us'}, callback); @@ -253,16 +290,19 @@ describe('iD.serviceTaginfo', function() { ); server.respond(); - expect(callback).to.have.been.calledWith(null, [ - {'value':'US:TX:FM','title':'Farm to Market Roads in the U.S. state of Texas.'}, - {'value':'US:KY','title':'Primary and secondary state highways in the U.S. state of Kentucky.'}, - {'value':'US:US','title':'U.S. routes in the United States.'}, - {'value':'US:I','title':'Interstate highways in the United States.'}, - {'value':'US:MD','title':'State highways in the U.S. state of Maryland.'} - ]); + window.setTimeout(function() { + expect(callback).to.have.been.calledWith(null, [ + {'value':'US:TX:FM','title':'Farm to Market Roads in the U.S. state of Texas.'}, + {'value':'US:KY','title':'Primary and secondary state highways in the U.S. state of Kentucky.'}, + {'value':'US:US','title':'U.S. routes in the United States.'}, + {'value':'US:I','title':'Interstate highways in the United States.'}, + {'value':'US:MD','title':'State highways in the U.S. state of Maryland.'} + ]); + done(); + }, 50); }); - it('includes biological genus values with capital letters', function() { + it('includes biological genus values with capital letters', function(done) { var callback = sinon.spy(); taginfo.values({key: 'genus', query: 'qu'}, callback); @@ -272,12 +312,15 @@ describe('iD.serviceTaginfo', function() { ); server.respond(); - expect(callback).to.have.been.calledWith( - null, [{'value':'Quercus','title':'Oak'}] - ); + window.setTimeout(function() { + expect(callback).to.have.been.calledWith( + null, [{'value':'Quercus','title':'Oak'}] + ); + done(); + }, 50); }); - it('includes biological taxon values with capital letters', function() { + it('includes biological taxon values with capital letters', function(done) { var callback = sinon.spy(); taginfo.values({key: 'taxon', query: 'qu'}, callback); @@ -287,12 +330,15 @@ describe('iD.serviceTaginfo', function() { ); server.respond(); - expect(callback).to.have.been.calledWith( - null, [{'value':'Quercus robur','title':'Oak'}] - ); + window.setTimeout(function() { + expect(callback).to.have.been.calledWith( + null, [{'value':'Quercus robur','title':'Oak'}] + ); + done(); + }, 50); }); - it('includes biological species values with capital letters', function() { + it('includes biological species values with capital letters', function(done) { var callback = sinon.spy(); taginfo.values({key: 'species', query: 'qu'}, callback); @@ -302,14 +348,17 @@ describe('iD.serviceTaginfo', function() { ); server.respond(); - expect(callback).to.have.been.calledWith( - null, [{'value':'Quercus robur','title':'Oak'}] - ); + window.setTimeout(function() { + expect(callback).to.have.been.calledWith( + null, [{'value':'Quercus robur','title':'Oak'}] + ); + done(); + }, 50); }); }); describe('#roles', function() { - it('calls the given callback with the results of the roles query', function() { + it('calls the given callback with the results of the roles query', function(done) { var callback = sinon.spy(); taginfo.roles({rtype: 'route', query: 's', geometry: 'relation'}, callback); @@ -320,18 +369,21 @@ describe('iD.serviceTaginfo', function() { ); server.respond(); - expect(query(server.requests[0].url)).to.eql( - {rtype: 'route', query: 's', page: '1', rp: '25', sortname: 'count_relation_members', sortorder: 'desc', lang: 'en'} - ); - expect(callback).to.have.been.calledWith(null, [ - {'value': 'stop', 'title': 'stop'}, - {'value': 'south', 'title': 'south'} - ]); + window.setTimeout(function() { + expect(query(server.requests()[0].url)).to.eql( + {rtype: 'route', query: 's', page: '1', rp: '25', sortname: 'count_relation_members', sortorder: 'desc', lang: 'en'} + ); + expect(callback).to.have.been.calledWith(null, [ + {'value': 'stop', 'title': 'stop'}, + {'value': 'south', 'title': 'south'} + ]); + done(); + }, 50); }); }); describe('#docs', function() { - it('calls the given callback with the results of the docs query', function() { + it('calls the given callback with the results of the docs query', function(done) { var callback = sinon.spy(); taginfo.docs({key: 'amenity', value: 'parking'}, callback); @@ -341,12 +393,15 @@ describe('iD.serviceTaginfo', function() { ); server.respond(); - expect(query(server.requests[0].url)).to.eql( - {key: 'amenity', value: 'parking'} - ); - expect(callback).to.have.been.calledWith( - null, [{'on_way':false,'lang':'en','on_area':true,'image':'File:Car park2.jpg'}] - ); + window.setTimeout(function() { + expect(query(server.requests()[0].url)).to.eql( + {key: 'amenity', value: 'parking'} + ); + expect(callback).to.have.been.calledWith( + null, [{'on_way':false,'lang':'en','on_area':true,'image':'File:Car park2.jpg'}] + ); + done(); + }, 50); }); }); diff --git a/test/spec/ui/fields/wikipedia.js b/test/spec/ui/fields/wikipedia.js index 393d5c6e2..b8c5719d3 100644 --- a/test/spec/ui/fields/wikipedia.js +++ b/test/spec/ui/fields/wikipedia.js @@ -22,8 +22,10 @@ describe('iD.uiFieldWikipedia', function() { } } - function createServer(options) { - var server = sinon.fakeServer.create(options); + function createServer(options) { // eslint-disable-line no-unused-vars + // note - currently skipping the tests that use `options` to delay responses + // var server = sinon.fakeServer.create(options); + var server = window.fakeFetch().create(); server.respondWith('GET', new RegExp('\/w\/api\.php.*action=wbgetentities'), [200, { 'Content-Type': 'application/json' },