Update tests

This commit is contained in:
J Guthrie
2019-01-21 04:02:19 +00:00
committed by Bryan Housel
parent 067d30227a
commit 5aecfcabc9
2 changed files with 40 additions and 10 deletions
+32 -9
View File
@@ -10,7 +10,7 @@ describe('iD.actionStraighten', function () {
iD.osmNode({id: 'd', loc: [3, 0]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd']})
]);
expect(iD.actionStraighten('-', projection).disabled(graph)).not.to.be.ok;
expect(iD.actionStraighten(['-'], projection).disabled(graph)).not.to.be.ok;
});
it('returns \'too_bendy\' for ways with internal nodes far off centerline', function () {
@@ -21,7 +21,7 @@ describe('iD.actionStraighten', function () {
iD.osmNode({id: 'd', loc: [3, 0]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd']})
]);
expect(iD.actionStraighten('-', projection).disabled(graph)).to.equal('too_bendy');
expect(iD.actionStraighten(['-'], projection).disabled(graph)).to.equal('too_bendy');
});
it('returns \'too_bendy\' for ways with coincident start/end nodes', function () {
@@ -32,7 +32,7 @@ describe('iD.actionStraighten', function () {
iD.osmNode({id: 'd', loc: [0, 0]}),
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd']})
]);
expect(iD.actionStraighten('-', projection).disabled(graph)).to.equal('too_bendy');
expect(iD.actionStraighten(['-'], projection).disabled(graph)).to.equal('too_bendy');
});
});
@@ -45,7 +45,7 @@ describe('iD.actionStraighten', function () {
iD.osmWay({id: '-', nodes: ['a', 'b', 'c']})
]);
graph = iD.actionStraighten('-', projection)(graph);
graph = iD.actionStraighten(['-'], projection)(graph);
expect(graph.entity('-').nodes).to.eql(['a', 'c']);
expect(graph.hasEntity('b')).to.eq(undefined);
});
@@ -58,7 +58,7 @@ describe('iD.actionStraighten', function () {
iD.osmWay({id: '-', nodes: ['a', 'b', 'c']})
]);
graph = iD.actionStraighten('-', projection)(graph);
graph = iD.actionStraighten(['-'], projection)(graph);
expect(graph.entity('-').nodes).to.eql(['a', 'b', 'c']);
expect(graph.entity('b').loc[0]).to.be.closeTo(1, 1e-6);
expect(graph.entity('b').loc[1]).to.be.closeTo(0, 1e-6);
@@ -73,12 +73,35 @@ describe('iD.actionStraighten', function () {
iD.osmWay({id: '=', nodes: ['b']})
]);
graph = iD.actionStraighten('-', projection)(graph);
graph = iD.actionStraighten(['-'], projection)(graph);
expect(graph.entity('-').nodes).to.eql(['a', 'b', 'c']);
expect(graph.entity('b').loc[0]).to.be.closeTo(1, 1e-6);
expect(graph.entity('b').loc[1]).to.be.closeTo(0, 1e-6);
});
it('straightens multiple, connected ways', function() {
var graph = iD.Graph([
iD.Node({id: 'a', loc: [0, 0]}),
iD.Node({id: 'b', loc: [1, 0.01], tags: {foo: 'bar'}}),
iD.Node({id: 'c', loc: [2, -0.01]}),
iD.Node({id: 'd', loc: [3, 0]}),
iD.Way({id: '-', nodes: ['a', 'b', 'c', 'd']}),
iD.Node({id: 'e', loc: [4, 0]}),
iD.Node({id: 'f', loc: [5, 0.01], tags: {foo: 'bar'}}),
iD.Node({id: 'g', loc: [6, -0.01]}),
iD.Node({id: 'h', loc: [7, 0]}),
iD.Way({id: '--', nodes: ['d', 'e', 'f', 'g', 'h']})
]);
graph = iD.actionStraighten(['-', '--'], projection)(graph);
expect(graph.entity('-').nodes).to.eql(['a', 'b', 'd']);
expect(graph.entity('--').nodes).to.eql(['d', 'f', 'h']);
expect(graph.entity('f').loc[0]).to.be.closeTo(5, 1e-6);
expect(graph.entity('f').loc[1]).to.be.closeTo(0, 1e-6);
expect(graph.hasEntity('g')).to.eq(undefined);
});
describe('transitions', function () {
it('is transitionable', function() {
@@ -94,7 +117,7 @@ describe('iD.actionStraighten', function () {
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd']})
]);
graph = iD.actionStraighten('-', projection)(graph, 0);
graph = iD.actionStraighten(['-'], projection)(graph, 0);
expect(graph.entity('-').nodes).to.eql(['a', 'b', 'c', 'd']);
expect(graph.entity('b').loc[0]).to.be.closeTo(1, 1e-6);
expect(graph.entity('b').loc[1]).to.be.closeTo(0.01, 1e-6);
@@ -111,7 +134,7 @@ describe('iD.actionStraighten', function () {
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd']})
]);
graph = iD.actionStraighten('-', projection)(graph, 0.5);
graph = iD.actionStraighten(['-'], projection)(graph, 0.5);
expect(graph.entity('-').nodes).to.eql(['a', 'b', 'c', 'd']);
expect(graph.entity('b').loc[0]).to.be.closeTo(1, 1e-6);
expect(graph.entity('b').loc[1]).to.be.closeTo(0.005, 1e-6);
@@ -128,7 +151,7 @@ describe('iD.actionStraighten', function () {
iD.osmWay({id: '-', nodes: ['a', 'b', 'c', 'd']})
]);
graph = iD.actionStraighten('-', projection)(graph, 1);
graph = iD.actionStraighten(['-'], projection)(graph, 1);
expect(graph.entity('-').nodes).to.eql(['a', 'b', 'd']);
expect(graph.entity('b').loc[0]).to.be.closeTo(1, 1e-6);
expect(graph.entity('b').loc[1]).to.be.closeTo(0, 1e-6);
+8 -1
View File
@@ -23,10 +23,12 @@ describe('iD.operationStraighten', function () {
iD.osmNode({ id: 'n7', type: 'node' }),
iD.osmNode({ id: 'n8', type: 'node' }),
iD.osmNode({ id: 'n9', type: 'node' }),
iD.osmNode({ id: 'n10', type: 'node' }),
iD.osmWay({ id: 'w1', nodes: ['n1', 'n2'] }),
iD.osmWay({ id: 'w2', nodes: ['n2', 'n3', 'n4'] }),
iD.osmWay({ id: 'w3', nodes: ['n4', 'n5', 'n6'] }),
iD.osmWay({ id: 'w4', nodes: ['n7', 'n8', 'n9'] })
iD.osmWay({ id: 'w4', nodes: ['n7', 'n8', 'n9'] }),
iD.osmWay({ id: 'w5', nodes: ['n2', 'n10'] })
]);
});
@@ -40,6 +42,11 @@ describe('iD.operationStraighten', function () {
expect(result).to.be.not.ok;
});
it('is available for way with only 2 nodes connected to another 2-node way', function () {
var result = iD.operationStraighten(['w1', 'w5'], fakeContext.graph()).available();
expect(result).to.be.ok;
});
it('is not available for unknown selected id', function () {
var result = iD.operationStraighten(['w0'], fakeContext.graph()).available();
expect(result).to.be.not.ok;