From 6dd9e9ce48f30db97238f5641f13687afa522d09 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Fri, 5 Apr 2019 13:53:57 -0700 Subject: [PATCH] Add code tests for incompatible_source validation --- test/index.html | 1 + test/spec/validations/incompatible_source.js | 60 ++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 test/spec/validations/incompatible_source.js diff --git a/test/index.html b/test/index.html index 954589083..4cb1e94fa 100644 --- a/test/index.html +++ b/test/index.html @@ -155,6 +155,7 @@ + diff --git a/test/spec/validations/incompatible_source.js b/test/spec/validations/incompatible_source.js new file mode 100644 index 000000000..f8a3e2d90 --- /dev/null +++ b/test/spec/validations/incompatible_source.js @@ -0,0 +1,60 @@ +describe('iD.validations.incompatible_source', 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.validationIncompatibleSource(); + 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 source tag', function() { + createWay({ amenity: 'cafe', building: 'yes', name: 'Key Largo Café'}); + var issues = validate(); + expect(issues).to.have.lengthOf(0); + }); + + it('ignores way with okay source tag', function() { + createWay({ amenity: 'cafe', building: 'yes', name: 'Key Largo Café', source: 'survey'}); + var issues = validate(); + expect(issues).to.have.lengthOf(0); + }); + + it('flags way with incompatible source tag', function() { + createWay({ amenity: 'cafe', building: 'yes', name: 'Key Largo Café', source: 'Google Maps'}); + var issues = validate(); + expect(issues).to.have.lengthOf(1); + var issue = issues[0]; + expect(issue.type).to.eql('incompatible_source'); + expect(issue.entities).to.have.lengthOf(1); + expect(issue.entities[0].id).to.eql('w-1'); + }); + +});