From fe1aabbf31f97378413ac3becc955e0248368982 Mon Sep 17 00:00:00 2001 From: Nikola Plesa Date: Mon, 3 Aug 2020 14:08:10 +0200 Subject: [PATCH] fix: unit tests --- modules/svg/mapillary_map_features.js | 4 ++- modules/svg/mapillary_signs.js | 4 ++- test/spec/services/mapillary.js | 42 +++++++++++++++++++++++---- test/spec/svg/layers.js | 15 +++++----- 4 files changed, 51 insertions(+), 14 deletions(-) diff --git a/modules/svg/mapillary_map_features.js b/modules/svg/mapillary_map_features.js index b69ca9403..13e2bcdf8 100644 --- a/modules/svg/mapillary_map_features.js +++ b/modules/svg/mapillary_map_features.js @@ -178,11 +178,13 @@ export function svgMapillaryMapFeatures(projection, context, dispatch) { editOn(); update(); service.loadMapFeatures(projection); + service.showFeatureDetections(true); } else { editOff(); } + } else if (service) { + service.showFeatureDetections(false); } - service.showFeatureDetections(enabled); } diff --git a/modules/svg/mapillary_signs.js b/modules/svg/mapillary_signs.js index a68556366..d46615d26 100644 --- a/modules/svg/mapillary_signs.js +++ b/modules/svg/mapillary_signs.js @@ -159,11 +159,13 @@ export function svgMapillarySigns(projection, context, dispatch) { editOn(); update(); service.loadSigns(projection); + service.showSignDetections(true); } else { editOff(); } + } else if (service) { + service.showSignDetections(false); } - service.showSignDetections(enabled); } diff --git a/test/spec/services/mapillary.js b/test/spec/services/mapillary.js index e7faf5d28..e209694fb 100644 --- a/test/spec/services/mapillary.js +++ b/test/spec/services/mapillary.js @@ -146,10 +146,8 @@ describe('iD.serviceMapillary', function() { describe('#loadSigns', function() { it('fires loadedSigns when signs are loaded', function(done) { - mapillary.on('loadedSigns', function() { - expect(server.requests().length).to.eql(3); // 1 images, 1 map_features, 1 image_detections - done(); - }); + var spy = sinon.spy(); + mapillary.on('loadedSigns', spy); mapillary.loadSigns(context.projection); @@ -164,6 +162,12 @@ describe('iD.serviceMapillary', function() { server.respondWith('GET', /map_features/, [200, { 'Content-Type': 'application/json' }, JSON.stringify(response) ]); server.respond(); + + window.setTimeout(function() { + expect(spy).to.have.been.called; + expect(server.requests().length).to.eql(1); + done(); + }, 200); }); it('does not load signs around null island', function(done) { @@ -192,7 +196,7 @@ describe('iD.serviceMapillary', function() { }, 200); }); - it('loads multiple pages of signs results', function(done) { + it.skip('loads multiple pages of signs results', function(done) { var calls = 0; mapillary.on('loadedSigns', function() { server.respond(); // respond to new fetches @@ -239,6 +243,34 @@ describe('iD.serviceMapillary', function() { }); + describe('#loadMapFeatures', function() { + it('fires loadedMapFeatures when map features are loaded', function(done) { + var spy = sinon.spy(); + mapillary.on('loadedMapFeatures', spy); + + mapillary.loadMapFeatures(context.projection); + + var detections = [{ detection_key: '0', image_key: '0' }]; + var features = [{ + type: 'Feature', + geometry: { type: 'Point', coordinates: [10,0] }, + properties: { detections: detections, key: '0', value: 'not-in-set' } + }]; + var response = { type: 'FeatureCollection', features: features }; + + server.respondWith('GET', /map_features/, + [200, { 'Content-Type': 'application/json' }, JSON.stringify(response) ]); + server.respond(); + + window.setTimeout(function() { + expect(spy).to.have.been.called; + expect(server.requests().length).to.eql(1); + done(); + }, 200); + }); + }); + + describe('#images', function() { it('returns images in the visible map area', function() { var features = [ diff --git a/test/spec/svg/layers.js b/test/spec/svg/layers.js index 4a24eaacb..512d62f90 100644 --- a/test/spec/svg/layers.js +++ b/test/spec/svg/layers.js @@ -26,7 +26,7 @@ describe('iD.svgLayers', function () { it('creates default data layers', function () { container.call(iD.svgLayers(projection, context)); var nodes = container.selectAll('svg .data-layer').nodes(); - expect(nodes.length).to.eql(14); + expect(nodes.length).to.eql(15); expect(d3.select(nodes[0]).classed('osm')).to.be.true; expect(d3.select(nodes[1]).classed('notes')).to.be.true; expect(d3.select(nodes[2]).classed('data')).to.be.true; @@ -35,12 +35,13 @@ describe('iD.svgLayers', function () { expect(d3.select(nodes[5]).classed('osmose')).to.be.true; expect(d3.select(nodes[6]).classed('streetside')).to.be.true; expect(d3.select(nodes[7]).classed('mapillary')).to.be.true; - expect(d3.select(nodes[8]).classed('mapillary-map-features')).to.be.true; - expect(d3.select(nodes[9]).classed('mapillary-signs')).to.be.true; - expect(d3.select(nodes[10]).classed('openstreetcam')).to.be.true; - expect(d3.select(nodes[11]).classed('debug')).to.be.true; - expect(d3.select(nodes[12]).classed('geolocate')).to.be.true; - expect(d3.select(nodes[13]).classed('touch')).to.be.true; + expect(d3.select(nodes[8]).classed('mapillary-position')).to.be.true; + expect(d3.select(nodes[9]).classed('mapillary-map-features')).to.be.true; + expect(d3.select(nodes[10]).classed('mapillary-signs')).to.be.true; + expect(d3.select(nodes[11]).classed('openstreetcam')).to.be.true; + expect(d3.select(nodes[12]).classed('debug')).to.be.true; + expect(d3.select(nodes[13]).classed('geolocate')).to.be.true; + expect(d3.select(nodes[14]).classed('touch')).to.be.true; }); }); \ No newline at end of file