Add new test cases

This commit is contained in:
J Guthrie
2019-01-21 01:26:10 +00:00
committed by Bryan Housel
parent e59bb75bcc
commit 067d30227a
2 changed files with 71 additions and 1 deletions
+3 -1
View File
@@ -86,6 +86,9 @@
<script src='spec/modes/add_point.js'></script>
<script src='spec/modes/add_note.js'></script>
<script src='spec/operations/detach_node.js'></script>
<script src='spec/operations/straighten.js'></script>
<script src='spec/osm/changeset.js'></script>
<script src='spec/osm/entity.js'></script>
<script src='spec/osm/intersection.js'></script>
@@ -158,7 +161,6 @@
<script src='spec/validations/tag_suggests_area.js'></script>
<script src='spec/validations/unknown_road.js'></script>
<script src='spec/operations/detach_node.js'></script>
<script>
window.mocha.run();
</script>
+68
View File
@@ -0,0 +1,68 @@
describe('iD.operationStraighten', function () {
var fakeContext;
var graph;
// Set up the fake context
fakeContext = {};
fakeContext.graph = function () { return graph; };
fakeContext.hasHiddenConnections = function () { return false; };
describe('#available', function () {
beforeEach(function () {
// w1 - way with 2 nodes
// w2 - way with 3 nodes connected to w1
// w3 - way with 3 nodes connected to w2
// w4 - way with 3 nodes not connected to other ways
graph = iD.coreGraph([
iD.osmNode({ id: 'n1', type: 'node' }),
iD.osmNode({ id: 'n2', type: 'node' }),
iD.osmNode({ id: 'n3', type: 'node' }),
iD.osmNode({ id: 'n4', type: 'node' }),
iD.osmNode({ id: 'n5', type: 'node' }),
iD.osmNode({ id: 'n6', type: 'node' }),
iD.osmNode({ id: 'n7', type: 'node' }),
iD.osmNode({ id: 'n8', type: 'node' }),
iD.osmNode({ id: 'n9', 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'] })
]);
});
it('is not available for no selected ids', function () {
var result = iD.operationStraighten([], fakeContext.graph()).available();
expect(result).to.be.not.ok;
});
it('is not available for way with only 2 nodes', function () {
var result = iD.operationStraighten(['w1'], fakeContext.graph()).available();
expect(result).to.be.not.ok;
});
it('is not available for unknown selected id', function () {
var result = iD.operationStraighten(['w0'], fakeContext.graph()).available();
expect(result).to.be.not.ok;
});
it('is not available for non-continuous ways', function () {
var result = iD.operationStraighten(['w3', 'w4'], fakeContext.graph()).available();
expect(result).to.be.not.ok;
});
it('is available for selected way with more than 2 nodes', function () {
var result = iD.operationStraighten(['w2'], fakeContext.graph()).available();
expect(result).to.be.ok;
});
it('is available for selected, ordered, continuous ways', function () {
var result = iD.operationStraighten(['w1', 'w2', 'w3'], fakeContext.graph()).available();
expect(result).to.be.ok;
});
it('is available for selected, un-ordered, continuous ways', function () {
var result = iD.operationStraighten(['w1', 'w3', 'w2'], fakeContext.graph()).available();
expect(result).to.be.ok;
});
});
});