From 3c57f7147fc4b115eeaa5bcbc4426c91b1e19ff5 Mon Sep 17 00:00:00 2001 From: Jon D Date: Wed, 24 Aug 2016 23:36:23 +0100 Subject: [PATCH] Add tests for reverse way-node behaviour. No implementation yet. --- test/spec/actions/reverse.js | 92 ++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/test/spec/actions/reverse.js b/test/spec/actions/reverse.js index 1412f932f..cc92959d5 100644 --- a/test/spec/actions/reverse.js +++ b/test/spec/actions/reverse.js @@ -156,4 +156,96 @@ describe('iD.actions.Reverse', function () { graph = iD.actions.Reverse(way.id)(graph); expect(graph.entity(relation.id).members[0].role).to.eql('east'); }); + + // For issue #3076 + it('reverses the direction of a forward facing stop sign on the way', function () { + var node1 = iD.Node(); + var node2 = iD.Node(); + var node3 = iD.Node(); + // Attach a forward facing stop sign to node 2 + node2.tags = { 'direction': 'forward', 'highway': 'stop' }; + // Create our way + var way = iD.Way({nodes: [node1.id, node2.id, node3.id]}); + // Act - reverse the way + var graph = iD.actions.Reverse(way.id)(iD.Graph([node1, node2, node3, way])); + // Assert - confirm that the stop sign on node 2 has changed direction + var target = graph.entity(node2.id); + expect(target.tags.direction).to.eql('backward'); + }); + + it('reverses the direction of a backward facing stop sign on the way', function () { + var node1 = iD.Node(); + var node2 = iD.Node(); + var node3 = iD.Node(); + // Attach a backward facing stop sign to node 2 + node2.tags = { 'direction': 'backward', 'highway': 'stop' }; + // Create our way + var way = iD.Way({nodes: [node1.id, node2.id, node3.id]}); + // Act - reverse the way + var graph = iD.actions.Reverse(way.id)(iD.Graph([node1, node2, node3, way])); + // Assert - confirm that the stop sign on node 2 has changed direction + var target = graph.entity(node2.id); + expect(target.tags.direction).to.eql('forward'); + }); + + it('does not assign a direction to a directionless stop sign on the way during a reverse', function () { + var node1 = iD.Node(); + var node2 = iD.Node(); + var node3 = iD.Node(); + // Attach a stop sign to node 2 with no direction specified + node2.tags = { 'highway': 'stop' }; + // Create our way + var way = iD.Way({nodes: [node1.id, node2.id, node3.id]}); + // Act - reverse the way + var graph = iD.actions.Reverse(way.id)(iD.Graph([node1, node2, node3, way])); + // Assert - confirm that the stop sign on node 2 has not gained a direction tag + var target = graph.entity(node2.id); + expect(target.tags.direction).to.be.undefined; + }); + + it('ignores directions other than forward or backward on attached stop sign during a reverse', function () { + var node1 = iD.Node(); + var node2 = iD.Node(); + var node3 = iD.Node(); + // Attach a stop sign to node 2 with a non-standard direction + node2.tags = { 'direction': 'empty', 'highway': 'stop' }; + // Create our way + var way = iD.Way({nodes: [node1.id, node2.id, node3.id]}); + // Act - reverse the way + var graph = iD.actions.Reverse(way.id)(iD.Graph([node1, node2, node3, way])); + // Assert - confirm that the stop sign on node 2 has not had its direction tag altered + var target = graph.entity(node2.id); + expect(target.tags.direction).to.eql('empty'); + }); + + it('reverses the direction of a forward facing traffic sign on the way', function () { + var node1 = iD.Node(); + var node2 = iD.Node(); + var node3 = iD.Node(); + // Attach a forward facing stop sign to node 2 using the traffic_sign approach + node2.tags = { 'traffic_sign:forward': 'stop' }; + // Create our way + var way = iD.Way({nodes: [node1.id, node2.id, node3.id]}); + // Act - reverse the way + var graph = iD.actions.Reverse(way.id)(iD.Graph([node1, node2, node3, way])); + // Assert - confirm that the stop sign on node 2 has changed direction + var target = graph.entity(node2.id); + expect(target.tags['traffic_sign:backward']).to.eql('stop'); + }); + + it('reverses the direction of a backward facing stop sign on the way', function () { + var node1 = iD.Node(); + var node2 = iD.Node(); + var node3 = iD.Node(); + // Attach a backward facing stop sign to node 2 using the traffic_sign approach + node2.tags = { 'traffic_sign:backward': 'stop' }; + // Create our way + var way = iD.Way({nodes: [node1.id, node2.id, node3.id]}); + // Act - reverse the way + var graph = iD.actions.Reverse(way.id)(iD.Graph([node1, node2, node3, way])); + // Assert - confirm that the stop sign on node 2 has changed direction + var target = graph.entity(node2.id); + expect(target.tags['traffic_sign:forward']).to.eql('stop'); + }); + });