Files
iD/test/spec/validations/mismatched_geometry.js
T
Bryan Housel 0fe766d9a4 WIP on external presets
- preset data is no longer bundled into iD.js
- some code pathways commented out re: external presets
- many changes so that tests can run without presets at start, or async
- still need to make sure fallbacks are always there (point, line, area, etc)
2020-02-05 09:38:26 -05:00

116 lines
3.6 KiB
JavaScript

describe('iD.validations.mismatched_geometry', function () {
var context, _savedAreaKeys;
beforeEach(function() {
_savedAreaKeys = iD.osmAreaKeys;
context = iD.coreContext().init();
});
afterEach(function() {
iD.osmSetAreaKeys(_savedAreaKeys);
});
function createPoint(tags) {
var n1 = iD.osmNode({id: 'n-1', loc: [4,4], tags: tags});
context.perform(
iD.actionAddEntity(n1)
);
}
function createOpenWay(tags) {
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', 'n-3'], tags: tags});
context.perform(
iD.actionAddEntity(n1),
iD.actionAddEntity(n2),
iD.actionAddEntity(n3),
iD.actionAddEntity(w)
);
}
function createClosedWay(tags) {
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', 'n-3', 'n-1'], tags: tags});
context.perform(
iD.actionAddEntity(n1),
iD.actionAddEntity(n2),
iD.actionAddEntity(n3),
iD.actionAddEntity(w)
);
}
function validate() {
var validator = iD.validationMismatchedGeometry(context);
var changes = context.history().changes();
var entities = changes.modified.concat(changes.created);
var issues = [];
entities.forEach(function(entity) {
issues = issues.concat(validator(entity, context.graph()));
});
return issues;
}
it('has no errors on init', function() {
var issues = validate();
expect(issues).to.have.lengthOf(0);
});
it('ignores points', function() {
createPoint({ building: 'yes' });
var issues = validate();
expect(issues).to.have.lengthOf(0);
});
it('ignores open way without area tag', function() {
createOpenWay({});
var issues = validate();
expect(issues).to.have.lengthOf(0);
});
it('ignores closed way with area tag', function() {
createClosedWay({ building: 'yes' });
var issues = validate();
expect(issues).to.have.lengthOf(0);
});
it('ignores open way with tag that allows both lines and areas', function() {
createOpenWay({ man_made: 'yes' });
var issues = validate();
expect(issues).to.have.lengthOf(0);
});
it('flags open way with area tag', function() {
iD.osmSetAreaKeys({ building: {} });
createOpenWay({ building: 'yes' });
var issues = validate();
expect(issues).to.have.lengthOf(1);
var issue = issues[0];
expect(issue.type).to.eql('mismatched_geometry');
expect(issue.subtype).to.eql('area_as_line');
expect(issue.severity).to.eql('warning');
expect(issue.entityIds).to.have.lengthOf(1);
expect(issue.entityIds[0]).to.eql('w-1');
});
it('flags open way with both area and line tags', function() {
createOpenWay({ area: 'yes', barrier: 'fence' });
var issues = validate();
expect(issues).to.have.lengthOf(1);
var issue = issues[0];
expect(issue.type).to.eql('mismatched_geometry');
expect(issue.subtype).to.eql('area_as_line');
expect(issue.severity).to.eql('warning');
expect(issue.entityIds).to.have.lengthOf(1);
expect(issue.entityIds[0]).to.eql('w-1');
});
});