mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-28 19:01:31 +02:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user