Files
iD/test/spec/core/validator.js
Bryan Housel 11201eb822 Rewrite the validator in ES6/Promises, several improvements here:
- implements a validation work queue, jobs are run during browser idle callbacks
- when merging base entities, don't run validations 2x on both base and head graphs (this was wasteful)
- keep track of resolved issues in a separate set (it's not a simple compare of base/head anymore)
  this happens after validation queue is empty and avoids race conditions and inaccurate resolved counts
2021-01-25 12:50:11 -05:00

51 lines
1.5 KiB
JavaScript

describe('iD.coreValidator', function () {
var context;
beforeEach(function() {
context = iD.coreContext().init();
});
function createInvalidWay() {
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']});
context.perform(
iD.actionAddEntity(n1),
iD.actionAddEntity(n2),
iD.actionAddEntity(w)
);
}
it('has no issues on init', function() {
var validator = new iD.coreValidator(context);
validator.init();
var issues = validator.getIssues();
expect(issues).to.have.lengthOf(0);
});
it('validate returns a promise, fulfilled when the validation has completed', function(done) {
createInvalidWay();
var validator = new iD.coreValidator(context);
validator.init();
var issues = validator.getIssues();
expect(issues).to.have.lengthOf(0);
var prom = validator.validate();
prom
.then(function() {
issues = validator.getIssues();
expect(issues).to.have.lengthOf(1);
var issue = issues[0];
expect(issue.type).to.eql('missing_tag');
expect(issue.entityIds).to.have.lengthOf(1);
expect(issue.entityIds[0]).to.eql('w-1');
})
.finally(done);
window.setTimeout(function() {}, 20); // async - to let the promise settle in phantomjs
});
});