Files
iD/test/spec/actions/restrict_turn.js
Bryan Housel 241159b547 Cleanup docs and tests for actionRestrictTurn / actionUnrestrictTurn
- actionRestrictTurn will no longer "infer" the turn type
- restrictionType *must* be passed in - this is ok because the only code
  we use this action (restrictions.js) already has inferred the type
- this simplifies what the action actually does
- moved the tests from restrict_turn.js that were really just testing
  the restriction type inferrence over to intersection.js
  (and added a few more tests for iD.osmInferRestriction)
2018-02-28 23:55:59 -05:00

81 lines
2.3 KiB
JavaScript

describe('iD.actionRestrictTurn', function() {
it('adds a via node restriction to an unrestricted turn', function() {
//
// u === * --- w
//
var graph = iD.coreGraph([
iD.osmNode({id: 'u'}),
iD.osmNode({id: '*'}),
iD.osmNode({id: 'w'}),
iD.osmWay({id: '=', nodes: ['u', '*']}),
iD.osmWay({id: '-', nodes: ['*', 'w']})
]);
var turn = {
from: { node: 'u', way: '=' },
via: { node: '*'},
to: { node: 'w', way: '-' }
};
var action = iD.actionRestrictTurn(turn, 'no_straight_on', 'r');
graph = action(graph);
var r = graph.entity('r');
expect(r.tags).to.eql({type: 'restriction', restriction: 'no_straight_on'});
var f = r.memberByRole('from');
expect(f.id).to.eql('=');
expect(f.type).to.eql('way');
var v = r.memberByRole('via');
expect(v.id).to.eql('*');
expect(v.type).to.eql('node');
var t = r.memberByRole('to');
expect(t.id).to.eql('-');
expect(t.type).to.eql('way');
});
it('adds a via way restriction to an unrestricted turn', function() {
//
// u === v1
// |
// w --- v2
//
var graph = iD.coreGraph([
iD.osmNode({id: 'u'}),
iD.osmNode({id: 'v1'}),
iD.osmNode({id: 'v2'}),
iD.osmNode({id: 'w'}),
iD.osmWay({id: '=', nodes: ['u', 'v1']}),
iD.osmWay({id: '|', nodes: ['v1', 'v2']}),
iD.osmWay({id: '-', nodes: ['v2', 'w']})
]);
var turn = {
from: { node: 'u', way: '=' },
via: { ways: ['|'] },
to: { node: 'w', way: '-' }
};
var action = iD.actionRestrictTurn(turn, 'no_u_turn', 'r');
graph = action(graph);
var r = graph.entity('r');
expect(r.tags).to.eql({type: 'restriction', restriction: 'no_u_turn'});
var f = r.memberByRole('from');
expect(f.id).to.eql('=');
expect(f.type).to.eql('way');
var v = r.memberByRole('via');
expect(v.id).to.eql('|');
expect(v.type).to.eql('way');
var t = r.memberByRole('to');
expect(t.id).to.eql('-');
expect(t.type).to.eql('way');
});
});