From e2dc3f46b270dbbf63e0fa8c22eebe00e328814e Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Thu, 7 Mar 2013 15:44:23 -0500 Subject: [PATCH] Improve svg and util test coverage --- test/spec/svg.js | 22 ++++++++++++++++++++++ test/spec/util.js | 19 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/test/spec/svg.js b/test/spec/svg.js index 19aedcdd4..78ad5ac66 100644 --- a/test/spec/svg.js +++ b/test/spec/svg.js @@ -9,6 +9,28 @@ describe("iD.svg.LineString", function () { expect(iD.svg.LineString(projection, graph, [10, 10])(way)).to.equal("M0,0L2,3"); }); + describe('resampling', function() { + it("resamples a linestring", function () { + var a = iD.Node({loc: [0, 0]}), + b = iD.Node({loc: [10, 0]}), + way = iD.Way({nodes: [a.id, b.id]}), + graph = iD.Graph([a, b, way]), + projection = Object; + + expect(iD.svg.LineString(projection, graph, [10, 10], 2)(way)).to.equal('M0,0L2,0L4,0L6,0L8,0L10,0'); + }); + + it("does not resmample when no steps are possible", function () { + var a = iD.Node({loc: [0, 0]}), + b = iD.Node({loc: [10, 0]}), + way = iD.Way({nodes: [a.id, b.id]}), + graph = iD.Graph([a, b, way]), + projection = Object; + + expect(iD.svg.LineString(projection, graph, [10, 10], 20)(way)).to.equal('M0,0L10,0'); + }); + }); + it("returns null for an entity with no nodes", function () { var way = iD.Way(), graph = iD.Graph([way]), diff --git a/test/spec/util.js b/test/spec/util.js index 662416a0e..472de1324 100644 --- a/test/spec/util.js +++ b/test/spec/util.js @@ -28,4 +28,23 @@ describe('iD.Util', function() { expect(iD.util.getPrototypeOf({})).to.eql({}); expect(iD.util.getPrototypeOf(new a())).to.eql({ foo: 'foo' }); }); + + describe('#asyncMap', function() { + it('handles correct replies', function() { + iD.util.asyncMap([1, 2, 3], + function(d, c) { c(null, d * 2); }, + function(err, res) { + expect(err).to.eql([null, null, null]); + expect(res).to.eql([2, 4, 6]); + }); + }); + it('handles errors', function() { + iD.util.asyncMap([1, 2, 3], + function(d, c) { c('whoops ' + d, null); }, + function(err, res) { + expect(err).to.eql(['whoops 1', 'whoops 2', 'whoops 3']); + expect(res).to.eql([null, null, null]); + }); + }); + }); });