mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-25 15:05:32 +00:00
Merge pull request #5630 from wonga00/wonga_validation_tests
fixed maprules test and added missing_tag test
This commit is contained in:
@@ -3,6 +3,12 @@ import _intersection from 'lodash-es/intersection';
|
||||
import _reduce from 'lodash-es/reduce';
|
||||
import _every from 'lodash-es/every';
|
||||
|
||||
import {
|
||||
ValidationIssueType,
|
||||
ValidationIssueSeverity,
|
||||
validationIssue
|
||||
} from '../validations/validation_issue';
|
||||
|
||||
var buildRuleChecks = function() {
|
||||
return {
|
||||
equals: function (equals) {
|
||||
|
||||
@@ -143,6 +143,7 @@
|
||||
<script src='spec/util/session_mutex.js'></script>
|
||||
<script src='spec/util/util.js'></script>
|
||||
|
||||
<script src='spec/validations/missing_tag.js'></script>
|
||||
<script src='spec/operations/detach_node.js'></script>
|
||||
<script>
|
||||
window.mocha.run();
|
||||
|
||||
@@ -462,7 +462,7 @@ describe('maprules', function() {
|
||||
expect(rule.matches(entity)).to.be.false;
|
||||
});
|
||||
});
|
||||
describe('#findWarnings', function() {
|
||||
describe('#findIssues', function() {
|
||||
var selectors, entities, _graph;
|
||||
|
||||
before(function() {
|
||||
@@ -546,24 +546,23 @@ describe('maprules', function() {
|
||||
selectors.forEach(function(selector) { iD.serviceMapRules.addRule(selector); });
|
||||
validationRules = iD.serviceMapRules.validationRules();
|
||||
});
|
||||
it('finds warnings', function() {
|
||||
it('finds issues', function() {
|
||||
validationRules.forEach(function(rule, i) {
|
||||
var warnings = [];
|
||||
var issues = [];
|
||||
var entity = entities[i];
|
||||
var selector = selectors[i];
|
||||
|
||||
rule.findWarnings(entity, _graph, warnings);
|
||||
rule.findIssues(entity, _graph, issues);
|
||||
|
||||
var warning = warnings[0];
|
||||
var issue = issues[0];
|
||||
var type = Object.keys(selector).indexOf('error') ? 'error' : 'warning';
|
||||
|
||||
expect(warnings.length).to.eql(1);
|
||||
expect(warning.entity).to.eql(entity);
|
||||
expect(warning.message).to.eql(selector[type]);
|
||||
expect(type).to.eql(warning.severity);
|
||||
expect(issues.length).to.eql(1);
|
||||
expect(issue.entities).to.eql([entity]);
|
||||
expect(issue.message).to.eql(selector[type]);
|
||||
expect(type).to.eql(issue.severity);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
43
test/spec/validations/missing_tag.js
Normal file
43
test/spec/validations/missing_tag.js
Normal file
@@ -0,0 +1,43 @@
|
||||
describe('iD.validations.missing_tag', function () {
|
||||
var context;
|
||||
|
||||
beforeEach(function() {
|
||||
context = iD.Context();
|
||||
});
|
||||
|
||||
function createInvalidWay() {
|
||||
var n1 = iD.Node({id: 'n-1', loc: [4,4]});
|
||||
var n2 = iD.Node({id: 'n-2', loc: [4,5]});
|
||||
|
||||
var w = iD.Way({id: 'w-1', nodes: ['n-1', 'n-2']});
|
||||
|
||||
context.perform(
|
||||
iD.actionAddEntity(n1),
|
||||
iD.actionAddEntity(n2),
|
||||
iD.actionAddEntity(w)
|
||||
);
|
||||
}
|
||||
|
||||
function validate() {
|
||||
var validator = iD.validationMissingTag();
|
||||
var changes = context.history().changes();
|
||||
return validator(changes, context.graph());
|
||||
}
|
||||
|
||||
it('has no errors on init', function() {
|
||||
var issues = validate();
|
||||
expect(issues).to.have.lengthOf(0);
|
||||
});
|
||||
|
||||
it('finds missing tags', function() {
|
||||
createInvalidWay();
|
||||
var issues = validate();
|
||||
expect(issues).to.have.lengthOf(1);
|
||||
var issue = issues[0];
|
||||
expect(issue.type).to.eql(iD.ValidationIssueType.missing_tag);
|
||||
expect(issue.entities).to.have.lengthOf(1);
|
||||
expect(issue.entities[0].id).to.eql('w-1');
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user