Fix file fetcher tests that touch the intro_graph

- Before it wasn't actually loading the intro graph because assetPath not set
- The test for Three Rivers City Hall was using the wrong nodeid
- All these test errors were being ignored because of the use of .finally(done)
- To actually make an error happen, we can call `done(err)` with the Error
This commit is contained in:
Bryan Housel
2021-08-16 15:23:31 -04:00
parent 1282d3b059
commit e7ad3845f9

View File

@@ -1,14 +1,5 @@
describe('iD.coreFileFetcher', function() { describe('iD.coreFileFetcher', function() {
before(function() {
iD.fileFetcher.cache().test = { hello: 'world' };
});
after(function() {
delete iD.fileFetcher.cache().test;
});
describe('#fileMap', function() { describe('#fileMap', function() {
it('gets the fileMap', function() { it('gets the fileMap', function() {
var data = iD.coreFileFetcher(); var data = iD.coreFileFetcher();
@@ -24,44 +15,52 @@ describe('iD.coreFileFetcher', function() {
describe('#get', function() { describe('#get', function() {
it('returns a promise resolved if we already have the data', function(done) { it('returns a promise resolved if we already have the data', function(done) {
var data = iD.coreFileFetcher(); var data = iD.coreFileFetcher();
data.cache().test = { hello: 'world' };
var prom = data.get('test'); var prom = data.get('test');
// expect(prom).to.be.a('promise'); // these are polyfilled in phantomjs // expect(prom).to.be.a('promise'); // these are polyfilled in phantomjs
prom prom
.then(function(data) { .then(function(data) {
expect(data).to.be.a('object'); expect(data).to.be.a('object');
expect(data.hello).to.eql('world'); expect(data.hello).to.eql('world');
done();
}) })
.finally(done); .catch(function(err) {
done(err);
});
window.setTimeout(function() {}, 20); // async - to let the promise settle in phantomjs 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) { it('returns a promise rejected if we can not get the data', function(done) {
var data = iD.coreFileFetcher(); var data = iD.coreFileFetcher().assetPath('../dist/');
var prom = data.get('wat'); var prom = data.get('wat');
prom prom
.then(function(data) { .then(function(data) {
throw new Error('We were not supposed to get data but did: ' + data); done(new Error('We were not supposed to get data but did: ' + data));
}) })
.catch(function(err) { .catch(function(err) {
expect(/^Unknown data file/.test(err)).to.be.true; expect(/^Unknown data file/.test(err)).to.be.true;
}) done();
.finally(done); });
window.setTimeout(function() {}, 20); // async - to let the promise settle in phantomjs 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) { 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 files = { 'intro_graph': 'data/intro_graph.min.json' };
var data = iD.coreFileFetcher().fileMap(files); var data = iD.coreFileFetcher().assetPath('../dist/').fileMap(files);
var prom = data.get('intro_graph'); var prom = data.get('intro_graph');
// expect(prom).to.be.a('promise'); // these are polyfilled in phantomjs // expect(prom).to.be.a('promise'); // these are polyfilled in phantomjs
prom prom
.then(function(data) { .then(function(data) {
expect(data).to.be.a('object'); expect(data).to.be.a('object');
expect(data.n1.tags.name).to.eql('Three Rivers City Hall'); expect(data.n2061.tags.name).to.eql('Three Rivers City Hall');
done();
}) })
.finally(done); .catch(function(err) {
done(err);
});
window.setTimeout(function() {}, 20); // async - to let the promise settle in phantomjs window.setTimeout(function() {}, 20); // async - to let the promise settle in phantomjs
}); });