Stop bundling wmf-sitematrix, move it extern

This also includes a bunch of tweaks to make the tests work
in both PhantomJS and modern browsers like Chrome.

Basically - introduce some more async into the test code so that
the coreData.get promise is guaranteed to settle.  Because in
PhantomJS the promise is polyfilled, and Chrome it's native, they
work slightly differently.
This commit is contained in:
Bryan Housel
2020-01-29 12:30:11 -05:00
parent 567eeac587
commit c481f90e7d
8 changed files with 366 additions and 324 deletions
+13 -15
View File
@@ -2,7 +2,6 @@ describe('iD.coreData', function() {
var _context;
before(function() {
iD.data = iD.data || {};
iD.data.test = { hello: 'world' };
});
@@ -36,26 +35,27 @@ describe('iD.coreData', function() {
.then(function(data) {
expect(data).to.be.a('object');
expect(data.hello).to.eql('world');
done();
})
.catch(function(err) {
throw err;
done();
});
.finally(done);
window.setTimeout(function() {}, 20); // async - to let the promise settle in phantomjs
});
it('returns a promise rejected if we can not get the data', function(done) {
var data = iD.coreData(_context);
var prom = data.get('wat');
prom
.then(function(data) {
throw new Error('got data ' + data);
done();
throw new Error('We were not supposed to get data but did: ' + data);
})
.catch(function(err) {
expect(/^Unknown data file/.test(err)).to.be.true;
done();
});
})
.finally(done);
window.setTimeout(function() {}, 20); // async - to let the promise settle in phantomjs
});
it('returns a promise to fetch data if we do not already have the data', function(done) {
var files = { 'intro_graph': 'data/intro_graph.min.json' };
var data = iD.coreData(_context).fileMap(files);
@@ -65,12 +65,10 @@ describe('iD.coreData', function() {
.then(function(data) {
expect(data).to.be.a('object');
expect(data.n1.tags.name).to.eql('Three Rivers City Hall');
done();
})
.catch(function(err) {
throw err;
done();
});
.finally(done);
window.setTimeout(function() {}, 20); // async - to let the promise settle in phantomjs
});
});
+55 -36
View File
@@ -35,11 +35,16 @@ describe('iD.uiFieldWikipedia', function() {
}
before(function() {
iD.data.wikipedia = [
['German','Deutsch','de'],
['English','English','en']
];
iD.services.wikipedia = iD.serviceWikipedia;
iD.services.wikidata = iD.serviceWikidata;
});
after(function() {
delete iD.data.wikipedia;
delete iD.services.wikipedia;
delete iD.services.wikidata;
});
@@ -61,59 +66,73 @@ describe('iD.uiFieldWikipedia', function() {
server.restore();
});
it('recognizes lang:title format', function() {
it('recognizes lang:title format', function(done) {
var wikipedia = iD.uiFieldWikipedia(field, context);
selection.call(wikipedia);
wikipedia.tags({wikipedia: 'en:Title'});
window.setTimeout(function() { // async, so data will be available
selection.call(wikipedia);
wikipedia.tags({wikipedia: 'en:Title'});
expect(iD.utilGetSetValue(selection.selectAll('.wiki-lang'))).to.equal('English');
expect(iD.utilGetSetValue(selection.selectAll('.wiki-title'))).to.equal('Title');
expect(iD.utilGetSetValue(selection.selectAll('.wiki-lang'))).to.equal('English');
expect(iD.utilGetSetValue(selection.selectAll('.wiki-title'))).to.equal('Title');
done();
}, 20);
});
it('sets language, value', function() {
it('sets language, value', function(done) {
var wikipedia = iD.uiFieldWikipedia(field, context).entity(entity);
wikipedia.on('change', changeTags);
selection.call(wikipedia);
window.setTimeout(function() { // async, so data will be available
wikipedia.on('change', changeTags);
selection.call(wikipedia);
var spy = sinon.spy();
wikipedia.on('change.spy', spy);
var spy = sinon.spy();
wikipedia.on('change.spy', spy);
iD.utilGetSetValue(selection.selectAll('.wiki-lang'), 'Deutsch');
happen.once(selection.selectAll('.wiki-lang').node(), { type: 'change' });
happen.once(selection.selectAll('.wiki-lang').node(), { type: 'blur' });
iD.utilGetSetValue(selection.selectAll('.wiki-lang'), 'Deutsch');
happen.once(selection.selectAll('.wiki-lang').node(), { type: 'change' });
happen.once(selection.selectAll('.wiki-lang').node(), { type: 'blur' });
iD.utilGetSetValue(selection.selectAll('.wiki-title'), 'Title');
happen.once(selection.selectAll('.wiki-title').node(), { type: 'change' });
happen.once(selection.selectAll('.wiki-title').node(), { type: 'blur' });
iD.utilGetSetValue(selection.selectAll('.wiki-title'), 'Title');
happen.once(selection.selectAll('.wiki-title').node(), { type: 'change' });
happen.once(selection.selectAll('.wiki-title').node(), { type: 'blur' });
expect(spy.callCount).to.equal(4);
expect(spy.getCall(0)).to.have.been.calledWith({ wikipedia: undefined}); // lang on change
expect(spy.getCall(1)).to.have.been.calledWith({ wikipedia: undefined}); // lang on blur
expect(spy.getCall(2)).to.have.been.calledWith({ wikipedia: 'de:Title' }); // title on change
expect(spy.getCall(3)).to.have.been.calledWith({ wikipedia: 'de:Title' }); // title on blur
expect(spy.callCount).to.equal(4);
expect(spy.getCall(0)).to.have.been.calledWith({ wikipedia: undefined}); // lang on change
expect(spy.getCall(1)).to.have.been.calledWith({ wikipedia: undefined}); // lang on blur
expect(spy.getCall(2)).to.have.been.calledWith({ wikipedia: 'de:Title' }); // title on change
expect(spy.getCall(3)).to.have.been.calledWith({ wikipedia: 'de:Title' }); // title on blur
done();
}, 20);
});
it('recognizes pasted URLs', function() {
it('recognizes pasted URLs', function(done) {
var wikipedia = iD.uiFieldWikipedia(field, context).entity(entity);
wikipedia.on('change', changeTags);
selection.call(wikipedia);
window.setTimeout(function() { // async, so data will be available
wikipedia.on('change', changeTags);
selection.call(wikipedia);
iD.utilGetSetValue(selection.selectAll('.wiki-title'), 'http://de.wikipedia.org/wiki/Title');
happen.once(selection.selectAll('.wiki-title').node(), { type: 'change' });
iD.utilGetSetValue(selection.selectAll('.wiki-title'), 'http://de.wikipedia.org/wiki/Title');
happen.once(selection.selectAll('.wiki-title').node(), { type: 'change' });
expect(iD.utilGetSetValue(selection.selectAll('.wiki-lang'))).to.equal('Deutsch');
expect(iD.utilGetSetValue(selection.selectAll('.wiki-title'))).to.equal('Title');
expect(iD.utilGetSetValue(selection.selectAll('.wiki-lang'))).to.equal('Deutsch');
expect(iD.utilGetSetValue(selection.selectAll('.wiki-title'))).to.equal('Title');
done();
}, 20);
});
it('preserves existing language', function() {
selection.call(iD.uiFieldWikipedia(field, context));
iD.utilGetSetValue(selection.selectAll('.wiki-lang'), 'Deutsch');
it('preserves existing language', function(done) {
var wikipedia1 = iD.uiFieldWikipedia(field, context);
window.setTimeout(function() { // async, so data will be available
selection.call(wikipedia1);
iD.utilGetSetValue(selection.selectAll('.wiki-lang'), 'Deutsch');
var wikipedia = iD.uiFieldWikipedia(field, context);
selection.call(wikipedia);
wikipedia.tags({});
expect(iD.utilGetSetValue(selection.selectAll('.wiki-lang'))).to.equal('Deutsch');
var wikipedia2 = iD.uiFieldWikipedia(field, context);
window.setTimeout(function() { // async, so data will be available
selection.call(wikipedia2);
wikipedia2.tags({});
expect(iD.utilGetSetValue(selection.selectAll('.wiki-lang'))).to.equal('Deutsch');
done();
}, 20);
}, 20);
});
it.skip('does not set delayed wikidata tag if graph has changed', function(done) {
+69 -42
View File
@@ -9,7 +9,7 @@ describe('iD.validations.outdated_tags', function () {
});
after(function() {
delete iD.data.deprecated;
iD.data.deprecated = [];
});
beforeEach(function() {
@@ -45,8 +45,7 @@ describe('iD.validations.outdated_tags', function () {
);
}
function validate() {
var validator = iD.validationOutdatedTags(context);
function validate(validator) {
var changes = context.history().changes();
var entities = changes.modified.concat(changes.created);
var issues = [];
@@ -56,63 +55,91 @@ describe('iD.validations.outdated_tags', function () {
return issues;
}
it('has no errors on init', function() {
var issues = validate();
expect(issues).to.have.lengthOf(0);
it('has no errors on init', function(done) {
var validator = iD.validationOutdatedTags(context);
window.setTimeout(function() { // async, so data will be available
var issues = validate(validator);
expect(issues).to.have.lengthOf(0);
done();
}, 20);
});
it('has no errors on good tags', function() {
it('has no errors on good tags', function(done) {
createWay({'highway': 'unclassified'});
var issues = validate();
expect(issues).to.have.lengthOf(0);
var validator = iD.validationOutdatedTags(context);
window.setTimeout(function() { // async, so data will be available
var issues = validate(validator);
expect(issues).to.have.lengthOf(0);
done();
}, 20);
});
it('flags deprecated tag with replacement', function() {
it('flags deprecated tag with replacement', function(done) {
createWay({'highway': 'ford'});
var issues = validate();
expect(issues).to.have.lengthOf(1);
var issue = issues[0];
expect(issue.type).to.eql('outdated_tags');
expect(issue.subtype).to.eql('deprecated_tags');
expect(issue.severity).to.eql('warning');
expect(issue.entityIds).to.have.lengthOf(1);
expect(issue.entityIds[0]).to.eql('w-1');
var validator = iD.validationOutdatedTags(context);
window.setTimeout(function() { // async, so data will be available
var issues = validate(validator);
expect(issues).to.have.lengthOf(1);
var issue = issues[0];
expect(issue.type).to.eql('outdated_tags');
expect(issue.subtype).to.eql('deprecated_tags');
expect(issue.severity).to.eql('warning');
expect(issue.entityIds).to.have.lengthOf(1);
expect(issue.entityIds[0]).to.eql('w-1');
done();
}, 20);
});
it('flags deprecated tag with no replacement', function() {
it('flags deprecated tag with no replacement', function(done) {
createWay({'highway': 'no'});
var issues = validate();
expect(issues).to.have.lengthOf(1);
var issue = issues[0];
expect(issue.type).to.eql('outdated_tags');
expect(issue.subtype).to.eql('deprecated_tags');
expect(issue.severity).to.eql('warning');
expect(issue.entityIds).to.have.lengthOf(1);
expect(issue.entityIds[0]).to.eql('w-1');
var validator = iD.validationOutdatedTags(context);
window.setTimeout(function() { // async, so data will be available
var issues = validate(validator);
expect(issues).to.have.lengthOf(1);
var issue = issues[0];
expect(issue.type).to.eql('outdated_tags');
expect(issue.subtype).to.eql('deprecated_tags');
expect(issue.severity).to.eql('warning');
expect(issue.entityIds).to.have.lengthOf(1);
expect(issue.entityIds[0]).to.eql('w-1');
done();
}, 20);
});
it('ignores way with no relations', function() {
it('ignores way with no relations', function(done) {
createWay({});
var issues = validate();
expect(issues).to.have.lengthOf(0);
var validator = iD.validationOutdatedTags(context);
window.setTimeout(function() { // async, so data will be available
var issues = validate(validator);
expect(issues).to.have.lengthOf(0);
done();
}, 20);
});
it('ignores multipolygon tagged on the relation', function() {
it('ignores multipolygon tagged on the relation', function(done) {
createRelation({}, { type: 'multipolygon', building: 'yes' });
var issues = validate();
expect(issues).to.have.lengthOf(0);
var validator = iD.validationOutdatedTags(context);
window.setTimeout(function() { // async, so data will be available
var issues = validate(validator);
expect(issues).to.have.lengthOf(0);
done();
}, 20);
});
it('flags multipolygon tagged on the outer way', function() {
it('flags multipolygon tagged on the outer way', function(done) {
createRelation({ building: 'yes' }, { type: 'multipolygon' });
var issues = validate();
expect(issues).to.not.have.lengthOf(0);
var issue = issues[0];
expect(issue.type).to.eql('outdated_tags');
expect(issue.subtype).to.eql('old_multipolygon');
expect(issue.entityIds).to.have.lengthOf(2);
expect(issue.entityIds[0]).to.eql('w-1');
expect(issue.entityIds[1]).to.eql('r-1');
var validator = iD.validationOutdatedTags(context);
window.setTimeout(function() { // async, so data will be available
var issues = validate(validator);
expect(issues).to.not.have.lengthOf(0);
var issue = issues[0];
expect(issue.type).to.eql('outdated_tags');
expect(issue.subtype).to.eql('old_multipolygon');
expect(issue.entityIds).to.have.lengthOf(2);
expect(issue.entityIds[0]).to.eql('w-1');
expect(issue.entityIds[1]).to.eql('r-1');
done();
}, 20);
});
});