Files
iD/test/spec/validations/disconnected_way.js
T
Bryan Housel c4fe42653a s/coordinates/loc and replace legacy names in tests
In iD codebase `loc` is usually a single coordinate pair
and `coordinates` is usually an array of pairs
2019-02-12 21:18:25 -05:00

70 lines
2.2 KiB
JavaScript

describe('iD.validations.disconnected_way', function () {
var context;
beforeEach(function() {
context = iD.coreContext();
});
function createWay(tags) {
var n1 = iD.osmNode({id: 'n-1', loc: [4,4]});
var n2 = iD.osmNode({id: 'n-2', loc: [4,5]});
var w = iD.osmWay({id: 'w-1', nodes: ['n-1', 'n-2'], tags: tags});
context.perform(
iD.actionAddEntity(n1),
iD.actionAddEntity(n2),
iD.actionAddEntity(w)
);
}
function createConnectingWays() {
var n1 = iD.osmNode({id: 'n-1', loc: [4,4]});
var n2 = iD.osmNode({id: 'n-2', loc: [4,5]});
var n3 = iD.osmNode({id: 'n-3', loc: [5,5]});
var w = iD.osmWay({id: 'w-1', nodes: ['n-1', 'n-2'], tags: {'highway': 'unclassified'}});
var w2 = iD.osmWay({id: 'w-2', nodes: ['n-1', 'n-3'], tags: {'highway': 'unclassified'}});
context.perform(
iD.actionAddEntity(n1),
iD.actionAddEntity(n2),
iD.actionAddEntity(n3),
iD.actionAddEntity(w),
iD.actionAddEntity(w2)
);
}
function validate() {
var validator = iD.validationDisconnectedWay();
var changes = context.history().changes();
var entities = changes.modified.concat(changes.created);
var issues = [];
entities.forEach(function(entity) {
issues = issues.concat(validator(entity, context));
});
return issues;
}
it('has no errors on init', function() {
var issues = validate();
expect(issues).to.have.lengthOf(0);
});
it('finds disconnected highway', function() {
createWay({'highway': 'unclassified'});
var issues = validate();
expect(issues).to.have.lengthOf(1);
var issue = issues[0];
expect(issue.type).to.eql('disconnected_way');
expect(issue.severity).to.eql('warning');
expect(issue.entities).to.have.lengthOf(1);
expect(issue.entities[0].id).to.eql('w-1');
});
it('ignores roads that are connected', function() {
createConnectingWays();
var issues = validate();
expect(issues).to.have.lengthOf(0);
});
});