diff --git a/js/id/core/way.js b/js/id/core/way.js index 14bbd14fd..9eb27650d 100644 --- a/js/id/core/way.js +++ b/js/id/core/way.js @@ -59,7 +59,7 @@ _.extend(iD.Way.prototype, { areAdjacent: function(n1, n2) { for (var i = 0; i < this.nodes.length; i++) { - if (this.nodes[i] === n1) { + if (this.nodes[i] === n1) { if (this.nodes[i - 1] === n2) return true; if (this.nodes[i + 1] === n2) return true; } diff --git a/test/spec/core/way.js b/test/spec/core/way.js index 00f33b4df..935d51dc4 100644 --- a/test/spec/core/way.js +++ b/test/spec/core/way.js @@ -141,6 +141,30 @@ describe('iD.Way', function() { }); }); + describe("#areAdjacent", function() { + it("returns false for nodes not in the way", function() { + expect(iD.Way().areAdjacent('a', 'b')).to.equal(false); + }); + + it("returns false for non-adjacent nodes in the way", function() { + expect(iD.Way({nodes: ['a', 'b', 'c']}).areAdjacent('a', 'c')).to.equal(false); + }); + + it("returns true for adjacent nodes in the way (forward)", function() { + var way = iD.Way({nodes: ['a', 'b', 'c', 'd']}); + expect(way.areAdjacent('a', 'b')).to.equal(true); + expect(way.areAdjacent('b', 'c')).to.equal(true); + expect(way.areAdjacent('c', 'd')).to.equal(true); + }); + + it("returns true for adjacent nodes in the way (reverse)", function() { + var way = iD.Way({nodes: ['a', 'b', 'c', 'd']}); + expect(way.areAdjacent('b', 'a')).to.equal(true); + expect(way.areAdjacent('c', 'b')).to.equal(true); + expect(way.areAdjacent('d', 'c')).to.equal(true); + }); + }); + describe("#geometry", function() { it("returns 'line' when the way is not an area", function () { expect(iD.Way().geometry()).to.equal('line');