Add test for almost junction with both close ends

This commit is contained in:
SilentSpike
2020-01-31 17:58:53 +00:00
parent 006e692449
commit d96fde53db

View File

@@ -199,6 +199,36 @@ describe('iD.validations.almost_junction', function () {
return n1;
}
function closeEndNodesBothSmallAngle() {
// Square path with both endpoints near eachother
var n1 = iD.osmNode({id: 'n-1', loc: [0, 22.4427453]});
var n2 = iD.osmNode({id: 'n-2', loc: [0, 22.4429810]});
var n3 = iD.osmNode({id: 'n-3', loc: [0.0000063, 22.4429810]});
var n4 = iD.osmNode({id: 'n-4', loc: [0.0000063, 22.4427483]});
var w1 = iD.osmWay({id: 'w-1', nodes: ['n-1', 'n-2', 'n-3', 'n-4'], tags: { highway: 'path' }});
context.perform(
iD.actionAddEntity(n1),
iD.actionAddEntity(n2),
iD.actionAddEntity(n3),
iD.actionAddEntity(n4),
iD.actionAddEntity(w1)
);
// Horizontal path with end node within 4.25m and change of angle >9° (to both endpoints)
var n5 = iD.osmNode({id: 'n-5', loc: [0.0000124, 22.4427458]});
var n6 = iD.osmNode({id: 'n-6', loc: [0.0000445, 22.4427449]});
var w2 = iD.osmWay({id: 'w-2', nodes: ['n-5', 'n-6'], tags: { highway: 'path' }});
context.perform(
iD.actionAddEntity(n5),
iD.actionAddEntity(n6),
iD.actionAddEntity(w2)
);
return n1;
}
function validate() {
var validator = iD.validationAlmostJunction(context);
var changes = context.history().changes();
@@ -293,7 +323,6 @@ describe('iD.validations.almost_junction', function () {
expect(issues).to.have.lengthOf(0);
});
// TODO: Test case of both endpoints of another way close, should prioritise smaller angle change
it('joins close endpoints if insignificant angle change', function() {
var n1 = closeEndNodesSmallAngle();
var issues = validate();
@@ -359,4 +388,27 @@ describe('iD.validations.almost_junction', function () {
expect(issue.data.cross_loc).to.have.lengthOf(2);
expect(issue.data.cross_loc).to.eql(n1.loc);
});
it('joins to close endpoint with smaller angle change', function() {
var n1 = closeEndNodesBothSmallAngle();
var issues = validate();
expect(issues).to.have.lengthOf(1);
var issue = issues[0];
expect(issue.type).to.eql('almost_junction');
expect(issue.subtype).to.eql('highway-highway');
expect(issue.entityIds).to.have.lengthOf(3);
expect(issue.entityIds[0]).to.eql('w-2');
expect(issue.entityIds[1]).to.eql('n-5');
expect(issue.entityIds[2]).to.eql('w-1');
// Duplicate edge nodes means endpoints will be joined
expect(issue.data.edge).to.have.lengthOf(2);
expect(issue.data.edge[0]).to.eql('n-1');
expect(issue.data.edge[1]).to.eql('n-1');
// Crossing set to loc of end node means endpoints will be joined
expect(issue.data.cross_loc).to.have.lengthOf(2);
expect(issue.data.cross_loc).to.eql(n1.loc);
});
});