From 95ac00ffbf9824709178bbd4743b252e02e4aba2 Mon Sep 17 00:00:00 2001 From: Jon D Date: Thu, 25 Aug 2016 06:54:54 +0100 Subject: [PATCH] Add tests for left/right reversal. --- test/spec/actions/reverse.js | 62 ++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/test/spec/actions/reverse.js b/test/spec/actions/reverse.js index cc92959d5..2e2ce7aef 100644 --- a/test/spec/actions/reverse.js +++ b/test/spec/actions/reverse.js @@ -188,6 +188,38 @@ describe('iD.actions.Reverse', function () { expect(target.tags.direction).to.eql('forward'); }); + it('reverses the direction of a left facing stop sign on the way', function () { + var node1 = iD.Node(); + var node2 = iD.Node(); + var node3 = iD.Node(); + // Attach a left facing stop sign to node 2 (not sure this is a real situation, + // but allows us to test) + node2.tags = { 'direction': 'left', '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('right'); + }); + + it('reverses the direction of a right facing stop sign on the way', function () { + var node1 = iD.Node(); + var node2 = iD.Node(); + var node3 = iD.Node(); + // Attach a right facing stop sign to node 2 (not sure this is a real situation, + // but allows us to test) + node2.tags = { 'direction': 'right', '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('left'); + }); + 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(); @@ -248,4 +280,34 @@ describe('iD.actions.Reverse', function () { expect(target.tags['traffic_sign:forward']).to.eql('stop'); }); + it('reverses the direction of a left facing traffic sign on the way', function () { + var node1 = iD.Node(); + var node2 = iD.Node(); + var node3 = iD.Node(); + // Attach a left facing stop sign to node 2 using the traffic_sign approach + node2.tags = { 'traffic_sign:left': '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:right']).to.eql('stop'); + }); + + it('reverses the direction of a right facing stop sign on the way', function () { + var node1 = iD.Node(); + var node2 = iD.Node(); + var node3 = iD.Node(); + // Attach a right facing stop sign to node 2 using the traffic_sign approach + node2.tags = { 'traffic_sign:right': '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:left']).to.eql('stop'); + }); + });