Skip to content

Commit

Permalink
Add tests for member ordering: node, way, relation
Browse files Browse the repository at this point in the history
  • Loading branch information
bhousel committed Jan 18, 2018
1 parent d6afd39 commit be9bbd9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/actions/add_member.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function actionAddMember(relationId, member, memberIndex, insertPair) {
// so that `osmJoinWays` can treat the pair like a single way.
tempWay = osmWay({ id: 'wTemp', nodes: insertPair.nodes });
graph = graph.replace(tempWay);
var tempMember = { id: tempWay.id, type: 'way', role: '' };
var tempMember = { id: tempWay.id, type: 'way', role: member.role };
var tempRelation = replaceMemberAll(relation, insertPair.originalID, tempMember);
groups = _groupBy(tempRelation.members, function(m) { return m.type; });
groups.way = groups.way || [];
Expand Down
24 changes: 24 additions & 0 deletions test/spec/actions/add_member.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,30 @@ describe('iD.actionAddMember', function() {
expect(members(graph)).to.eql(['-', '=', '~', '~', '=', '-']);
});

it('reorders members as node, way, relation (for Public Transport routing)', function() {
var graph = iD.coreGraph([
iD.osmNode({id: 'a', loc: [0, 0]}),
iD.osmNode({id: 'b', loc: [0, 0]}),
iD.osmNode({id: 'c', loc: [0, 0]}),
iD.osmWay({id: '-', nodes: ['a', 'b']}),
iD.osmWay({id: '=', nodes: ['b', 'c']}),
iD.osmRelation({id: 'r', members: [
{ id: 'n1', type: 'node', role: 'forward' },
{ id: '-', type: 'way', role: 'forward' },
{ id: 'r1', type: 'relation', role: 'forward' },
{ id: 'n2', type: 'node', role: 'forward' }
]})
]);

graph = iD.actionAddMember('r', { id: '=', type: 'way', role: 'forward' })(graph);
expect(graph.entity('r').members).to.eql([
{ id: 'n1', type: 'node', role: 'forward' },
{ id: 'n2', type: 'node', role: 'forward' },
{ id: '-', type: 'way', role: 'forward' },
{ id: '=', type: 'way', role: 'forward' },
{ id: 'r1', type: 'relation', role: 'forward' }
]);
});

});
});
25 changes: 25 additions & 0 deletions test/spec/actions/split.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,31 @@ describe('iD.actionSplit', function () {
graph = iD.actionSplit('b', ['='])(graph);
expect(members(graph)).to.eql(['~', '=', '-']);
});

it('reorders members as node, way, relation (for Public Transport routing)', function () {
var graph = iD.coreGraph([
iD.osmNode({ id: 'a', loc: [0, 0] }),
iD.osmNode({ id: 'b', loc: [1, 0] }),
iD.osmNode({ id: 'c', loc: [2, 0] }),
iD.osmWay({ id: '-', nodes: ['a', 'b', 'c'] }),
iD.osmRelation({id: 'r', members: [
{ id: 'n1', type: 'node', role: 'forward' },
{ id: '-', type: 'way', role: 'forward' },
{ id: 'r1', type: 'relation', role: 'forward' },
{ id: 'n2', type: 'node', role: 'forward' }
]})
]);

graph = iD.actionSplit('b', ['='])(graph);

expect(graph.entity('r').members).to.eql([
{ id: 'n1', type: 'node', role: 'forward' },
{ id: 'n2', type: 'node', role: 'forward' },
{ id: '-', type: 'way', role: 'forward' },
{ id: '=', type: 'way', role: 'forward' },
{ id: 'r1', type: 'relation', role: 'forward'}
]);
});
});

describe('splitting out-and-back routes', function () {
Expand Down

0 comments on commit be9bbd9

Please sign in to comment.