From 0b32f4c4ee36e6ea0e19322896d88ff0e1f9200f Mon Sep 17 00:00:00 2001 From: vershwal Date: Sun, 15 Jul 2018 22:20:43 +0530 Subject: [PATCH 1/2] Some mvt tests. --- test/index.html | 1 + test/spec/svg/mvt.js | 98 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 test/spec/svg/mvt.js diff --git a/test/index.html b/test/index.html index 188b9084c0..e89eaa1c3f 100644 --- a/test/index.html +++ b/test/index.html @@ -115,6 +115,7 @@ + diff --git a/test/spec/svg/mvt.js b/test/spec/svg/mvt.js new file mode 100644 index 0000000000..8def1b567c --- /dev/null +++ b/test/spec/svg/mvt.js @@ -0,0 +1,98 @@ +describe('iD.svgMvt', function () { + var context; + var surface; + var dispatch = d3.dispatch('change'); + var projection = iD.geoRawMercator() + .translate([6934098.868981334, 4092682.5519805425]) + .scale(iD.geoZoomToScale(17)) + .clipExtent([[0, 0], [1000, 1000]]); + + + var gj = { + 'type': 'FeatureCollection', + 'features': [ + { + 'type': 'Feature', + 'id': 316973311, + 'geometry': { + 'type': 'Point', + 'coordinates': [ + -74.38928604125977, + 40.150275473401365 + ] + }, + 'properties': { + 'abbr': 'N.J.', + 'area': 19717.8, + 'name': 'New Jersey', + 'name_en': 'New Jersey', + 'osm_id': 316973311 + } + } + ] + }; + + beforeEach(function () { + context = iD.coreContext(); + d3.select(document.createElement('div')) + .attr('id', 'map') + .call(context.map().centerZoom([-74.389286, 40.1502754], 17)); + + surface = context.surface(); + }); + + it('creates layer-mvt', function () { + var render = iD.svgMvt(projection, context, dispatch); + surface.call(render); + + var layers = surface.selectAll('g.layer-mvt').nodes(); + expect(layers.length).to.eql(1); + }); + + it('draws geojson', function () { + var render = iD.svgMvt(projection, context, dispatch).geojson(gj); + surface.call(render); + + var path = surface.selectAll('path.mvt'); + expect(path.nodes().length).to.eql(1); + expect(path.attr('d')).to.match(/^M.*z$/); + }); + + describe('#url', function() { + it('handles pbf url', function () { + var url = 'https://api.mapbox.com/v4/mapbox.mapbox-streets-v6/9/150/194.vector.pbf?access_token=' + +'pk.eyJ1IjoidmVyc2h3YWwiLCJhIjoiY2pocmk1c2J5M28wbDM1cGU1ZDdpeDB1eSJ9.KN1fjHMCdSUsYcuvwiXWIA'; + var render = iD.svgMvt(projection, context, dispatch).url(url); + surface.call(render); + + var path = surface.selectAll('path.mvt'); + expect(path.nodes().length).to.eql(1); + expect(path.attr('d')).to.match(/^M.*z$/); + }); + }); + + describe('#showLabels', function() { + it('shows labels by default', function () { + var render = iD.svgMvt(projection, context, dispatch).geojson(gj); + surface.call(render); + + var label = surface.selectAll('text.mvtlabel'); + expect(label.nodes().length).to.eql(1); + expect(label.text()).to.eql('New Jersey'); + + var halo = surface.selectAll('text.mvtlabel-halo'); + expect(halo.nodes().length).to.eql(1); + expect(halo.text()).to.eql('New Jersey'); + }); + + + it('hides labels with showLabels(false)', function () { + var render = iD.svgMvt(projection, context, dispatch).geojson(gj).showLabels(false); + surface.call(render); + + expect(surface.selectAll('text.mvtlabel').empty()).to.be.ok; + expect(surface.selectAll('text.mvtlabel-halo').empty()).to.be.ok; + }); + }); + +}); From 213fa3706d851b8300f4135bcb9277caf98dfc57 Mon Sep 17 00:00:00 2001 From: vershwal Date: Mon, 16 Jul 2018 22:10:59 +0530 Subject: [PATCH 2/2] Created new file for pbf test in test/data. --- test/data/mvttest.pbf | Bin 0 -> 24576 bytes test/spec/svg/mvt.js | 3 +-- 2 files changed, 1 insertion(+), 2 deletions(-) create mode 100644 test/data/mvttest.pbf diff --git a/test/data/mvttest.pbf b/test/data/mvttest.pbf new file mode 100644 index 0000000000000000000000000000000000000000..63858a7a95cc69bbca67f9ba98ddd88fa0f8ada7 GIT binary patch literal 24576 zcmeI4eQXnD9LMjyy|(K!nOz-odUP&q^Hz52-heorqb3{6#>+4$!Exf00e*l5C8%|;J-&;ttfdbD%dTi z9*P>Np(tKY_NGkT)Uso#Z9}lNC#dwaKG+#lvX4}np{N?^8&yf0ssX{~UFK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 diff --git a/test/spec/svg/mvt.js b/test/spec/svg/mvt.js index 8def1b567c..e5ab522aa4 100644 --- a/test/spec/svg/mvt.js +++ b/test/spec/svg/mvt.js @@ -60,8 +60,7 @@ describe('iD.svgMvt', function () { describe('#url', function() { it('handles pbf url', function () { - var url = 'https://api.mapbox.com/v4/mapbox.mapbox-streets-v6/9/150/194.vector.pbf?access_token=' - +'pk.eyJ1IjoidmVyc2h3YWwiLCJhIjoiY2pocmk1c2J5M28wbDM1cGU1ZDdpeDB1eSJ9.KN1fjHMCdSUsYcuvwiXWIA'; + var url = '../../data/mvttest.pbf'; var render = iD.svgMvt(projection, context, dispatch).url(url); surface.call(render);