mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-24 09:04:02 +02:00
e7ad3845f9
- 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
70 lines
2.6 KiB
JavaScript
70 lines
2.6 KiB
JavaScript
describe('iD.coreFileFetcher', function() {
|
|
|
|
describe('#fileMap', function() {
|
|
it('gets the fileMap', function() {
|
|
var data = iD.coreFileFetcher();
|
|
expect(data.fileMap()).to.be.a('object');
|
|
});
|
|
it('sets the fileMap', function() {
|
|
var data = iD.coreFileFetcher();
|
|
var files = { 'intro_graph': 'data/intro_graph.min.json' };
|
|
expect(data.fileMap(files)).to.be.ok;
|
|
});
|
|
});
|
|
|
|
describe('#get', function() {
|
|
it('returns a promise resolved if we already have the data', function(done) {
|
|
var data = iD.coreFileFetcher();
|
|
data.cache().test = { hello: 'world' };
|
|
|
|
var prom = data.get('test');
|
|
// expect(prom).to.be.a('promise'); // these are polyfilled in phantomjs
|
|
prom
|
|
.then(function(data) {
|
|
expect(data).to.be.a('object');
|
|
expect(data.hello).to.eql('world');
|
|
done();
|
|
})
|
|
.catch(function(err) {
|
|
done(err);
|
|
});
|
|
|
|
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.coreFileFetcher().assetPath('../dist/');
|
|
var prom = data.get('wat');
|
|
prom
|
|
.then(function(data) {
|
|
done(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();
|
|
});
|
|
|
|
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.coreFileFetcher().assetPath('../dist/').fileMap(files);
|
|
var prom = data.get('intro_graph');
|
|
// expect(prom).to.be.a('promise'); // these are polyfilled in phantomjs
|
|
prom
|
|
.then(function(data) {
|
|
expect(data).to.be.a('object');
|
|
expect(data.n2061.tags.name).to.eql('Three Rivers City Hall');
|
|
done();
|
|
})
|
|
.catch(function(err) {
|
|
done(err);
|
|
});
|
|
|
|
window.setTimeout(function() {}, 20); // async - to let the promise settle in phantomjs
|
|
});
|
|
});
|
|
|
|
});
|