Improve svg and util test coverage

This commit is contained in:
Tom MacWright
2013-03-07 15:44:23 -05:00
parent fd2f464bf9
commit e2dc3f46b2
2 changed files with 41 additions and 0 deletions

View File

@@ -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]),

View File

@@ -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]);
});
});
});
});