mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 21:48:20 +02:00
Add tests for generic_name validation
This commit is contained in:
@@ -149,6 +149,7 @@
|
||||
<script src='spec/validations/almost_junction.js'></script>
|
||||
<script src='spec/validations/crossing_ways.js'></script>
|
||||
<script src='spec/validations/disconnected_way.js'></script>
|
||||
<script src='spec/validations/generic_name.js'></script>
|
||||
<script src='spec/validations/missing_role.js'></script>
|
||||
<script src='spec/validations/missing_tag.js'></script>
|
||||
<script src='spec/validations/old_multipolygon.js'></script>
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
describe('iD.validations.generic_name', 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 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 validate() {
|
||||
var validator = iD.validationGenericName();
|
||||
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('ignores way with no tags', function() {
|
||||
createWay({});
|
||||
var issues = validate();
|
||||
expect(issues).to.have.lengthOf(0);
|
||||
});
|
||||
|
||||
it('ignores feature with no name', function() {
|
||||
createWay({ shop: 'supermarket' });
|
||||
var issues = validate();
|
||||
expect(issues).to.have.lengthOf(0);
|
||||
});
|
||||
|
||||
it('ignores feature with a specific name', function() {
|
||||
createWay({ shop: 'supermarket', name: "Lou's" });
|
||||
var issues = validate();
|
||||
expect(issues).to.have.lengthOf(0);
|
||||
});
|
||||
|
||||
it('ignores feature with a specific name that includes a generic name', function() {
|
||||
createWay({ shop: 'supermarket', name: "Lou's Store" });
|
||||
var issues = validate();
|
||||
expect(issues).to.have.lengthOf(0);
|
||||
});
|
||||
|
||||
it('flags feature with a known generic name', function() {
|
||||
createWay({ shop: 'supermarket', name: 'Store' });
|
||||
var issues = validate();
|
||||
expect(issues).to.have.lengthOf(1);
|
||||
var issue = issues[0];
|
||||
expect(issue.type).to.eql('generic_name');
|
||||
expect(issue.entities).to.have.lengthOf(1);
|
||||
expect(issue.entities[0].id).to.eql('w-1');
|
||||
});
|
||||
|
||||
it('flags feature with a name that is just a defining tag key', function() {
|
||||
createWay({ amenity: 'drinking_water', name: 'Amenity' });
|
||||
var issues = validate();
|
||||
expect(issues).to.have.lengthOf(1);
|
||||
var issue = issues[0];
|
||||
expect(issue.type).to.eql('generic_name');
|
||||
expect(issue.entities).to.have.lengthOf(1);
|
||||
expect(issue.entities[0].id).to.eql('w-1');
|
||||
});
|
||||
|
||||
it('flags feature with a name that is just a defining tag value', function() {
|
||||
createWay({ shop: 'red_bicycle_emporium', name: 'Red Bicycle Emporium' });
|
||||
var issues = validate();
|
||||
expect(issues).to.have.lengthOf(1);
|
||||
var issue = issues[0];
|
||||
expect(issue.type).to.eql('generic_name');
|
||||
expect(issue.entities).to.have.lengthOf(1);
|
||||
expect(issue.entities[0].id).to.eql('w-1');
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user