Drop custom "classed" chai assertation and just use d3

This commit is contained in:
Bryan Housel
2017-04-24 10:27:29 -04:00
parent 149cbbe350
commit d07d20cba7
10 changed files with 56 additions and 68 deletions
+1 -1
View File
@@ -81,7 +81,7 @@ describe('d3.combobox', function() {
it('adds the combobox-input class', function() {
input.call(combobox);
expect(input).to.be.classed('combobox-input');
expect(input.classed('combobox-input')).to.be.true;
});
it('adds combobox under body by default', function() {
-13
View File
@@ -18,16 +18,3 @@ mocha.setup({
expect = chai.expect;
var d3 = iD.d3;
chai.use(function (chai, utils) {
var flag = utils.flag;
chai.Assertion.addMethod('classed', function (className) {
this.assert(
flag(this, 'object').classed(className)
, 'expected #{this} to be classed #{exp}'
, 'expected #{this} not to be classed #{exp}'
, className
);
});
});
+14 -14
View File
@@ -32,8 +32,8 @@ describe('iD.svgAreas', function () {
surface.call(iD.svgAreas(projection, context), graph, [graph.entity('w')], none);
expect(surface.select('path.way')).to.be.classed('way');
expect(surface.select('path.area')).to.be.classed('area');
expect(surface.select('path.way').classed('way')).to.be.true;
expect(surface.select('path.area').classed('area')).to.be.true;
});
it('adds tag classes', function () {
@@ -47,8 +47,8 @@ describe('iD.svgAreas', function () {
surface.call(iD.svgAreas(projection, context), graph, [graph.entity('w')], none);
expect(surface.select('.area')).to.be.classed('tag-building');
expect(surface.select('.area')).to.be.classed('tag-building-yes');
expect(surface.select('.area').classed('tag-building')).to.be.true;
expect(surface.select('.area').classed('tag-building-yes')).to.be.true;
});
it('handles deletion of a way and a member vertex (#1903)', function () {
@@ -85,31 +85,31 @@ describe('iD.svgAreas', function () {
it('stacks smaller areas above larger ones in a single render', function () {
surface.call(iD.svgAreas(projection, context), graph, [graph.entity('s'), graph.entity('l')], none);
expect(surface.select('.area:nth-child(1)')).to.be.classed('tag-landuse-park');
expect(surface.select('.area:nth-child(2)')).to.be.classed('tag-building-yes');
expect(surface.select('.area:nth-child(1)').classed('tag-landuse-park')).to.be.true;
expect(surface.select('.area:nth-child(2)').classed('tag-building-yes')).to.be.true;
});
it('stacks smaller areas above larger ones in a single render (reverse)', function () {
surface.call(iD.svgAreas(projection, context), graph, [graph.entity('l'), graph.entity('s')], none);
expect(surface.select('.area:nth-child(1)')).to.be.classed('tag-landuse-park');
expect(surface.select('.area:nth-child(2)')).to.be.classed('tag-building-yes');
expect(surface.select('.area:nth-child(1)').classed('tag-landuse-park')).to.be.true;
expect(surface.select('.area:nth-child(2)').classed('tag-building-yes')).to.be.true;
});
it('stacks smaller areas above larger ones in separate renders', function () {
surface.call(iD.svgAreas(projection, context), graph, [graph.entity('s')], none);
surface.call(iD.svgAreas(projection, context), graph, [graph.entity('l')], none);
expect(surface.select('.area:nth-child(1)')).to.be.classed('tag-landuse-park');
expect(surface.select('.area:nth-child(2)')).to.be.classed('tag-building-yes');
expect(surface.select('.area:nth-child(1)').classed('tag-landuse-park')).to.be.true;
expect(surface.select('.area:nth-child(2)').classed('tag-building-yes')).to.be.true;
});
it('stacks smaller areas above larger ones in separate renders (reverse)', function () {
surface.call(iD.svgAreas(projection, context), graph, [graph.entity('l')], none);
surface.call(iD.svgAreas(projection, context), graph, [graph.entity('s')], none);
expect(surface.select('.area:nth-child(1)')).to.be.classed('tag-landuse-park');
expect(surface.select('.area:nth-child(2)')).to.be.classed('tag-building-yes');
expect(surface.select('.area:nth-child(1)').classed('tag-landuse-park')).to.be.true;
expect(surface.select('.area:nth-child(2)').classed('tag-building-yes')).to.be.true;
});
});
@@ -124,7 +124,7 @@ describe('iD.svgAreas', function () {
surface.call(iD.svgAreas(projection, context), graph, areas, none);
expect(surface.select('.fill')).to.be.classed('relation');
expect(surface.select('.fill').classed('relation')).to.be.true;
});
it('renders no strokes for multipolygon areas', function () {
@@ -153,7 +153,7 @@ describe('iD.svgAreas', function () {
expect(surface.selectAll('.way.fill').size()).to.equal(0);
expect(surface.selectAll('.relation.fill').size()).to.equal(1);
expect(surface.select('.relation.fill')).to.be.classed('tag-natural-wood');
expect(surface.select('.relation.fill').classed('tag-natural-wood')).to.be.true;
});
it('renders no strokes for a multipolygon with tags on the outer way', function() {
+3 -3
View File
@@ -7,13 +7,13 @@ describe('iD.svgIcon', function () {
it('creates a generic SVG icon', function () {
selection.call(iD.svgIcon('#icon-bug'));
expect(selection.select('svg')).to.be.classed('icon');
expect(selection.select('svg').classed('icon')).to.be.true;
expect(selection.select('use').attr('xlink:href')).to.eql('#icon-bug');
});
it('classes the \'svg\' and \'use\' elements', function () {
selection.call(iD.svgIcon('#icon-bug', 'svg-class', 'use-class'));
expect(selection.select('svg')).to.be.classed('icon svg-class');
expect(selection.select('use')).to.be.classed('use-class');
expect(selection.select('svg').classed('icon svg-class')).to.be.true;
expect(selection.select('use').classed('use-class')).to.be.true;
});
});
+7 -7
View File
@@ -13,25 +13,25 @@ describe('iD.svgLayers', function () {
it('creates a surface', function () {
container.call(iD.svgLayers(projection, context));
expect(container.selectAll('svg')).to.be.classed('surface');
expect(container.selectAll('svg').classed('surface')).to.be.true;
});
it('creates surface defs', function () {
container.call(iD.svgLayers(projection, context));
var nodes = container.selectAll('svg defs').nodes();
expect(nodes.length).to.eql(1);
expect(d3.select(nodes[0])).to.be.classed('surface-defs');
expect(d3.select(nodes[0]).classed('surface-defs')).to.be.true;
});
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(5);
expect(d3.select(nodes[0])).to.be.classed('data-layer-osm');
expect(d3.select(nodes[1])).to.be.classed('data-layer-gpx');
expect(d3.select(nodes[2])).to.be.classed('data-layer-mapillary-images');
expect(d3.select(nodes[3])).to.be.classed('data-layer-mapillary-signs');
expect(d3.select(nodes[4])).to.be.classed('data-layer-debug');
expect(d3.select(nodes[0]).classed('data-layer-osm')).to.be.true;
expect(d3.select(nodes[1]).classed('data-layer-gpx')).to.be.true;
expect(d3.select(nodes[2]).classed('data-layer-mapillary-images')).to.be.true;
expect(d3.select(nodes[3]).classed('data-layer-mapillary-signs')).to.be.true;
expect(d3.select(nodes[4]).classed('data-layer-debug')).to.be.true;
});
});
+7 -7
View File
@@ -24,8 +24,8 @@ describe('iD.svgLines', function () {
surface.call(iD.svgLines(projection, context), graph, [line], all);
expect(surface.select('path.way')).to.be.classed('way');
expect(surface.select('path.line')).to.be.classed('line');
expect(surface.select('path.way').classed('way')).to.be.true;
expect(surface.select('path.line').classed('line')).to.be.true;
});
it('adds tag classes', function () {
@@ -36,8 +36,8 @@ describe('iD.svgLines', function () {
surface.call(iD.svgLines(projection, context), graph, [line], all);
expect(surface.select('.line')).to.be.classed('tag-highway');
expect(surface.select('.line')).to.be.classed('tag-highway-residential');
expect(surface.select('.line').classed('tag-highway')).to.be.true;
expect(surface.select('.line').classed('tag-highway-residential')).to.be.true;
});
it('adds stroke classes for the tags of the parent relation of multipolygon members', function() {
@@ -49,7 +49,7 @@ describe('iD.svgLines', function () {
surface.call(iD.svgLines(projection, context), graph, [line], all);
expect(surface.select('.stroke')).to.be.classed('tag-natural-wood');
expect(surface.select('.stroke').classed('tag-natural-wood')).to.be.true;
});
it('renders stroke for outer way of multipolygon with tags on the outer way', function() {
@@ -62,7 +62,7 @@ describe('iD.svgLines', function () {
surface.call(iD.svgLines(projection, context), graph, [w], all);
expect(surface.select('.stroke')).to.be.classed('tag-natural-wood');
expect(surface.select('.stroke').classed('tag-natural-wood')).to.be.true;
});
it('adds stroke classes for the tags of the outer way of multipolygon with tags on the outer way', function() {
@@ -76,7 +76,7 @@ describe('iD.svgLines', function () {
surface.call(iD.svgLines(projection, context), graph, [i], all);
expect(surface.select('.stroke')).to.be.classed('tag-natural-wood');
expect(surface.select('.stroke').classed('tag-natural-wood')).to.be.true;
});
describe('z-indexing', function() {
+5 -5
View File
@@ -9,11 +9,11 @@ describe('iD.svgOsm', function () {
container.call(iD.svgOsm());
var nodes = container.selectAll('.layer-osm').nodes();
expect(nodes.length).to.eql(5);
expect(d3.select(nodes[0])).to.be.classed('layer-areas');
expect(d3.select(nodes[1])).to.be.classed('layer-lines');
expect(d3.select(nodes[2])).to.be.classed('layer-hit');
expect(d3.select(nodes[3])).to.be.classed('layer-halo');
expect(d3.select(nodes[4])).to.be.classed('layer-label');
expect(d3.select(nodes[0]).classed('layer-areas')).to.be.true;
expect(d3.select(nodes[1]).classed('layer-lines')).to.be.true;
expect(d3.select(nodes[2]).classed('layer-hit')).to.be.true;
expect(d3.select(nodes[3]).classed('layer-halo')).to.be.true;
expect(d3.select(nodes[4]).classed('layer-label')).to.be.true;
});
});
+2 -2
View File
@@ -20,7 +20,7 @@ describe('iD.svgPoints', function () {
surface.call(iD.svgPoints(projection, context), graph, [point]);
expect(surface.select('.point')).to.be.classed('tag-amenity');
expect(surface.select('.point')).to.be.classed('tag-amenity-cafe');
expect(surface.select('.point').classed('tag-amenity')).to.be.true;
expect(surface.select('.point').classed('tag-amenity-cafe')).to.be.true;
});
});
+13 -13
View File
@@ -86,79 +86,79 @@ describe('iD.svgTagClasses', function () {
selection
.datum(iD.Entity({tags: {highway: 'track'}}))
.call(iD.svgTagClasses());
expect(selection).to.be.classed('tag-unpaved');
expect(selection.classed('tag-unpaved')).to.be.true;
});
it('does not add tag-unpaved for highway=track with explicit paved surface tagging', function() {
selection
.datum(iD.Entity({tags: {highway: 'track', surface: 'asphalt'}}))
.call(iD.svgTagClasses());
expect(selection).not.to.be.classed('tag-unpaved');
expect(selection.classed('tag-unpaved')).to.be.false;
selection
.datum(iD.Entity({tags: {highway: 'track', tracktype: 'grade1'}}))
.call(iD.svgTagClasses());
expect(selection).not.to.be.classed('tag-unpaved');
expect(selection.classed('tag-unpaved')).to.be.false;
});
it('adds tag-unpaved for highway=track with explicit unpaved surface tagging', function() {
selection
.datum(iD.Entity({tags: {highway: 'track', surface: 'dirt'}}))
.call(iD.svgTagClasses());
expect(selection).to.be.classed('tag-unpaved');
expect(selection.classed('tag-unpaved')).to.be.true;
selection
.datum(iD.Entity({tags: {highway: 'track', tracktype: 'grade3'}}))
.call(iD.svgTagClasses());
expect(selection).to.be.classed('tag-unpaved');
expect(selection.classed('tag-unpaved')).to.be.true;
});
it('does not add tag-unpaved for other highway types with no surface tagging', function() {
selection
.datum(iD.Entity({tags: {highway: 'tertiary'}}))
.call(iD.svgTagClasses());
expect(selection).not.to.be.classed('tag-unpaved');
expect(selection.classed('tag-unpaved')).to.be.false;
selection
.datum(iD.Entity({tags: {highway: 'foo'}}))
.call(iD.svgTagClasses());
expect(selection).not.to.be.classed('tag-unpaved');
expect(selection.classed('tag-unpaved')).to.be.false;
});
it('does not add tag-unpaved for other highway types with explicit paved surface tagging', function() {
selection
.datum(iD.Entity({tags: {highway: 'tertiary', surface: 'asphalt'}}))
.call(iD.svgTagClasses());
expect(selection).not.to.be.classed('tag-unpaved');
expect(selection.classed('tag-unpaved')).to.be.false;
selection
.datum(iD.Entity({tags: {highway: 'foo', tracktype: 'grade1'}}))
.call(iD.svgTagClasses());
expect(selection).not.to.be.classed('tag-unpaved');
expect(selection.classed('tag-unpaved')).to.be.false;
});
it('adds tag-unpaved for other highway types with explicit unpaved surface tagging', function() {
selection
.datum(iD.Entity({tags: {highway: 'tertiary', surface: 'dirt'}}))
.call(iD.svgTagClasses());
expect(selection).to.be.classed('tag-unpaved');
expect(selection.classed('tag-unpaved')).to.be.true;
selection
.datum(iD.Entity({tags: {highway: 'foo', tracktype: 'grade3'}}))
.call(iD.svgTagClasses());
expect(selection).to.be.classed('tag-unpaved');
expect(selection.classed('tag-unpaved')).to.be.true;
});
it('does not add tag-unpaved for non-highways', function() {
selection
.datum(iD.Entity({tags: {railway: 'abandoned', surface: 'gravel'}}))
.call(iD.svgTagClasses());
expect(selection).not.to.be.classed('tag-unpaved');
expect(selection.classed('tag-unpaved')).to.be.false;
selection
.datum(iD.Entity({tags: {amenity: 'parking', surface: 'dirt'}}))
.call(iD.svgTagClasses());
expect(selection).not.to.be.classed('tag-unpaved');
expect(selection.classed('tag-unpaved')).to.be.false;
});
it('adds tags based on the result of the `tags` accessor', function() {
+4 -3
View File
@@ -15,13 +15,14 @@ describe('iD.svgVertices', function () {
it('adds the .shared class to vertices that are members of two or more ways', function () {
var node = iD.Node({loc: [0, 0]}),
var zoom = 17,
node = iD.Node({loc: [0, 0]}),
way1 = iD.Way({nodes: [node.id], tags: {highway: 'residential'}}),
way2 = iD.Way({nodes: [node.id], tags: {highway: 'residential'}}),
graph = iD.Graph([node, way1, way2]);
surface.call(iD.svgVertices(projection, context), graph, [node], 17);
surface.call(iD.svgVertices(projection, context), graph, [node], zoom);
expect(surface.select('.vertex')).to.be.classed('shared');
expect(surface.select('.vertex').classed('shared')).to.be.true;
});
});