Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some mvt tests. #5149

Merged
merged 2 commits into from
Jul 17, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
<script src='spec/svg/layers.js'></script>
<script src='spec/svg/lines.js'></script>
<script src='spec/svg/midpoints.js'></script>
<script src='spec/svg/mvt.js'></script>
<script src='spec/svg/osm.js'></script>
<script src='spec/svg/points.js'></script>
<script src='spec/svg/svg.js'></script>
Expand Down
98 changes: 98 additions & 0 deletions test/spec/svg/mvt.js
Original file line number Diff line number Diff line change
@@ -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='
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid linking to a mapbox streets pbf here.
Can you try to use sinon to fake a response?

Here is an example in the OpenStreetCam test:
https://github.com/openstreetmap/iD/blob/master/test/spec/services/openstreetcam.js#L54-L105

I think it would be ok to store .pbf test fixture in the test/data folder, and use fs.readFile to load the data .

+'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;
});
});

});