Make several data external instead of bundled:

Also dist/data/* contains minified files now

These are now external and will fetch as needed:
-export { dataAddressFormats } from './address-formats.json';
-export { dataDeprecated } from './deprecated.json';
-export { dataDiscarded } from './discarded.json';
-export { dataLanguages } from './languages.json';
-export { dataPhoneFormats } from './phone-formats.json';
-export { dataShortcuts } from './shortcuts.json';
-export { dataTerritoryLanguages } from './territory-languages.json';
This commit is contained in:
Bryan Housel
2020-01-28 22:21:31 -05:00
parent 3ac800c619
commit 567eeac587
40 changed files with 2815 additions and 3193 deletions
+6 -4
View File
@@ -1,9 +1,11 @@
describe('iD.actionDiscardTags', function() {
var discardTags = { created_by: true };
it('discards obsolete tags from modified entities', function() {
var way = iD.osmWay({ id: 'w1', tags: { created_by: 'Potlatch' } });
var base = iD.coreGraph([way]);
var head = base.replace(way.update({ tags: { created_by: 'Potlatch', foo: 'bar' } }));
var action = iD.actionDiscardTags(iD.coreDifference(base, head));
var action = iD.actionDiscardTags(iD.coreDifference(base, head), discardTags);
expect(action(head).entity(way.id).tags).to.eql({foo: 'bar'});
});
@@ -11,7 +13,7 @@ describe('iD.actionDiscardTags', function() {
var way = iD.osmWay({ tags: { created_by: 'Potlatch' } });
var base = iD.coreGraph();
var head = base.replace(way);
var action = iD.actionDiscardTags(iD.coreDifference(base, head));
var action = iD.actionDiscardTags(iD.coreDifference(base, head), discardTags);
expect(action(head).entity(way.id).tags).to.eql({});
});
@@ -19,7 +21,7 @@ describe('iD.actionDiscardTags', function() {
var way = iD.osmWay();
var base = iD.coreGraph();
var head = base.replace(way);
var action = iD.actionDiscardTags(iD.coreDifference(base, head));
var action = iD.actionDiscardTags(iD.coreDifference(base, head), discardTags);
expect(action(head).entity(way.id)).to.equal(way);
});
@@ -27,7 +29,7 @@ describe('iD.actionDiscardTags', function() {
var way = iD.osmWay({ tags: { lmnop: '' } });
var base = iD.coreGraph();
var head = base.replace(way);
var action = iD.actionDiscardTags(iD.coreDifference(base, head));
var action = iD.actionDiscardTags(iD.coreDifference(base, head), discardTags);
expect(action(head).entity(way.id).tags).to.eql({});
});
});
+29 -27
View File
@@ -1,4 +1,6 @@
describe('iD.actionMergeRemoteChanges', function () {
var discardTags = { created_by: true };
var base = iD.coreGraph([
iD.osmNode({id: 'a', loc: [1, 1], version: '1', tags: {foo: 'foo'}}),
@@ -73,7 +75,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('a').update({tags: remoteTags, version: '2'}),
localGraph = makeGraph([local]),
remoteGraph = makeGraph([remote]),
action = iD.actionMergeRemoteChanges('a', localGraph, remoteGraph);
action = iD.actionMergeRemoteChanges('a', localGraph, remoteGraph, discardTags);
var result = action(localGraph);
expect(result).to.eql(localGraph);
@@ -86,7 +88,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('a').update({tags: remoteTags, version: '2'}),
localGraph = makeGraph([local]),
remoteGraph = makeGraph([remote]),
action = iD.actionMergeRemoteChanges('a', localGraph, remoteGraph),
action = iD.actionMergeRemoteChanges('a', localGraph, remoteGraph, discardTags),
result = action(localGraph);
expect(result).to.eql(localGraph);
@@ -99,7 +101,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('a').update({tags: remoteTags, version: '2'}),
localGraph = makeGraph([local]),
remoteGraph = makeGraph([remote]),
action = iD.actionMergeRemoteChanges('a', localGraph, remoteGraph),
action = iD.actionMergeRemoteChanges('a', localGraph, remoteGraph, discardTags),
result = action(localGraph);
expect(result).to.eql(localGraph);
@@ -112,7 +114,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('a').update({tags: remoteTags, version: '2'}),
localGraph = makeGraph([local]),
remoteGraph = makeGraph([remote]),
action = iD.actionMergeRemoteChanges('a', localGraph, remoteGraph),
action = iD.actionMergeRemoteChanges('a', localGraph, remoteGraph, discardTags),
result = action(localGraph);
expect(result).to.eql(localGraph);
@@ -126,7 +128,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('a').update({tags: remoteTags, version: '2'}),
localGraph = makeGraph([local]),
remoteGraph = makeGraph([remote]),
action = iD.actionMergeRemoteChanges('a', localGraph, remoteGraph),
action = iD.actionMergeRemoteChanges('a', localGraph, remoteGraph, discardTags),
result = action(localGraph);
expect(result.entity('a').version).to.eql('2');
@@ -141,7 +143,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('a').update({tags: remoteTags, version: '2'}),
localGraph = makeGraph([local]),
remoteGraph = makeGraph([remote]),
action = iD.actionMergeRemoteChanges('a', localGraph, remoteGraph),
action = iD.actionMergeRemoteChanges('a', localGraph, remoteGraph, discardTags),
result = action(localGraph);
expect(result.entity('a').version).to.eql('2');
@@ -160,7 +162,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('a').update({tags: remoteTags, loc: remoteLoc, version: '2'}),
localGraph = makeGraph([local]),
remoteGraph = makeGraph([remote]),
action = iD.actionMergeRemoteChanges('a', localGraph, remoteGraph),
action = iD.actionMergeRemoteChanges('a', localGraph, remoteGraph, discardTags),
result = action(localGraph);
expect(result).to.eql(localGraph);
@@ -176,7 +178,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('a').update({tags: remoteTags, loc: remoteLoc, version: '2'}),
localGraph = makeGraph([local]),
remoteGraph = makeGraph([remote]),
action = iD.actionMergeRemoteChanges('a', localGraph, remoteGraph),
action = iD.actionMergeRemoteChanges('a', localGraph, remoteGraph, discardTags),
result = action(localGraph);
expect(result.entity('a').version).to.eql('2');
@@ -195,7 +197,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('w1').update({tags: remoteTags, version: '2'}),
localGraph = makeGraph([local]),
remoteGraph = makeGraph([remote]),
action = iD.actionMergeRemoteChanges('w1', localGraph, remoteGraph),
action = iD.actionMergeRemoteChanges('w1', localGraph, remoteGraph, discardTags),
result = action(localGraph);
expect(result.entity('w1').version).to.eql('2');
@@ -212,7 +214,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('w1').update({tags: remoteTags, nodes: remoteNodes, version: '2'}),
localGraph = makeGraph([local]),
remoteGraph = makeGraph([remote, r2, r3]),
action = iD.actionMergeRemoteChanges('w1', localGraph, remoteGraph),
action = iD.actionMergeRemoteChanges('w1', localGraph, remoteGraph, discardTags),
result = action(localGraph);
expect(result.entity('w1').version).to.eql('2');
@@ -232,7 +234,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('w1').update({tags: remoteTags, nodes: remoteNodes, version: '2'}),
localGraph = makeGraph([local, r2, r3]),
remoteGraph = makeGraph([remote]),
action = iD.actionMergeRemoteChanges('w1', localGraph, remoteGraph),
action = iD.actionMergeRemoteChanges('w1', localGraph, remoteGraph, discardTags),
result = action(localGraph);
expect(result.entity('w1').version).to.eql('2');
@@ -251,7 +253,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('w1').update({tags: remoteTags, nodes: remoteNodes, version: '2'}),
localGraph = makeGraph([local, r1, r2]),
remoteGraph = makeGraph([remote, r3, r4]),
action = iD.actionMergeRemoteChanges('w1', localGraph, remoteGraph),
action = iD.actionMergeRemoteChanges('w1', localGraph, remoteGraph, discardTags),
result = action(localGraph);
expect(result.entity('w1').version).to.eql('2');
@@ -270,7 +272,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('w1').update({tags: remoteTags, nodes: remoteNodes, version: '2'}),
localGraph = makeGraph([local, r1, r2]),
remoteGraph = makeGraph([remote, r3, r4]),
action = iD.actionMergeRemoteChanges('w1', localGraph, remoteGraph),
action = iD.actionMergeRemoteChanges('w1', localGraph, remoteGraph, discardTags),
result = action(localGraph);
expect(result).to.eql(localGraph);
@@ -283,7 +285,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('p1').update({loc: remoteLoc, version: '2'}),
localGraph = makeGraph([local]),
remoteGraph = makeGraph([remote]),
action = iD.actionMergeRemoteChanges('w1', localGraph, remoteGraph),
action = iD.actionMergeRemoteChanges('w1', localGraph, remoteGraph, discardTags),
result = action(localGraph);
expect(result.entity('p1').version).to.eql('2');
@@ -297,7 +299,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('p1').update({loc: remoteLoc, version: '2'}),
localGraph = makeGraph([local]),
remoteGraph = makeGraph([remote]),
action = iD.actionMergeRemoteChanges('w1', localGraph, remoteGraph),
action = iD.actionMergeRemoteChanges('w1', localGraph, remoteGraph, discardTags),
result = action(localGraph);
expect(result).to.eql(localGraph);
@@ -315,7 +317,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('r').update({tags: remoteTags, members: remoteMembers, version: '2'}),
localGraph = makeGraph([local]),
remoteGraph = makeGraph([remote, s1, s2, s3, s4, w4]),
action = iD.actionMergeRemoteChanges('r', localGraph, remoteGraph),
action = iD.actionMergeRemoteChanges('r', localGraph, remoteGraph, discardTags),
result = action(localGraph);
expect(result).to.eql(localGraph);
@@ -331,7 +333,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('r').update({tags: remoteTags, members: remoteMembers, version: '2'}),
localGraph = makeGraph([local]),
remoteGraph = makeGraph([remote]),
action = iD.actionMergeRemoteChanges('r', localGraph, remoteGraph),
action = iD.actionMergeRemoteChanges('r', localGraph, remoteGraph, discardTags),
result = action(localGraph);
expect(result.entity('r').version).to.eql('2');
@@ -349,7 +351,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('a').update({tags: remoteTags, loc: remoteLoc, version: '2'}),
localGraph = makeGraph([local]),
remoteGraph = makeGraph([remote]),
action = iD.actionMergeRemoteChanges('a', localGraph, remoteGraph);
action = iD.actionMergeRemoteChanges('a', localGraph, remoteGraph, discardTags);
action(localGraph);
expect(action.conflicts()).not.to.be.empty;
@@ -369,7 +371,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('a').update({tags: remoteTags, loc: remoteLoc, version: '2'}),
localGraph = makeGraph([local]),
remoteGraph = makeGraph([remote]),
action = iD.actionMergeRemoteChanges('a', localGraph, remoteGraph).withOption('force_local'),
action = iD.actionMergeRemoteChanges('a', localGraph, remoteGraph, discardTags).withOption('force_local'),
result = action(localGraph);
expect(result.entity('a').version).to.eql('2');
@@ -386,7 +388,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('a').update({tags: remoteTags, loc: remoteLoc, version: '2'}),
localGraph = makeGraph([local]),
remoteGraph = makeGraph([remote]),
action = iD.actionMergeRemoteChanges('a', localGraph, remoteGraph).withOption('force_remote'),
action = iD.actionMergeRemoteChanges('a', localGraph, remoteGraph, discardTags).withOption('force_remote'),
result = action(localGraph);
expect(result.entity('a').version).to.eql('2');
@@ -406,7 +408,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('w1').update({tags: remoteTags, nodes: remoteNodes, version: '2'}),
localGraph = makeGraph([local, r1, r2]),
remoteGraph = makeGraph([remote, r3, r4]),
action = iD.actionMergeRemoteChanges('w1', localGraph, remoteGraph).withOption('force_local'),
action = iD.actionMergeRemoteChanges('w1', localGraph, remoteGraph, discardTags).withOption('force_local'),
result = action(localGraph);
expect(result.entity('w1').version).to.eql('2');
@@ -423,7 +425,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('w1').update({tags: remoteTags, nodes: remoteNodes, version: '2'}),
localGraph = makeGraph([local, r1, r2]),
remoteGraph = makeGraph([remote, r3, r4]),
action = iD.actionMergeRemoteChanges('w1', localGraph, remoteGraph).withOption('force_remote'),
action = iD.actionMergeRemoteChanges('w1', localGraph, remoteGraph, discardTags).withOption('force_remote'),
result = action(localGraph);
expect(result.entity('w1').version).to.eql('2');
@@ -440,7 +442,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('p1').update({loc: remoteLoc, version: '2'}),
localGraph = makeGraph([local]),
remoteGraph = makeGraph([remote]),
action = iD.actionMergeRemoteChanges('w1', localGraph, remoteGraph).withOption('force_local'),
action = iD.actionMergeRemoteChanges('w1', localGraph, remoteGraph, discardTags).withOption('force_local'),
result = action(localGraph);
expect(result.entity('p1').version).to.eql('2');
@@ -454,7 +456,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('p1').update({loc: remoteLoc, version: '2'}),
localGraph = makeGraph([local]),
remoteGraph = makeGraph([remote]),
action = iD.actionMergeRemoteChanges('w1', localGraph, remoteGraph).withOption('force_remote'),
action = iD.actionMergeRemoteChanges('w1', localGraph, remoteGraph, discardTags).withOption('force_remote'),
result = action(localGraph);
expect(result.entity('p1').version).to.eql('2');
@@ -469,7 +471,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('w1').update({nodes: remoteNodes, version: '2'}),
localGraph = makeGraph([local, localr1, r2]),
remoteGraph = makeGraph([remote, r3, r4]),
action = iD.actionMergeRemoteChanges('w1', localGraph, remoteGraph).withOption('force_remote'),
action = iD.actionMergeRemoteChanges('w1', localGraph, remoteGraph, discardTags).withOption('force_remote'),
result = action(localGraph);
expect(result.entity('w1').nodes).to.eql(remoteNodes);
@@ -489,7 +491,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('r').update({tags: remoteTags, members: remoteMembers, version: '2'}),
localGraph = makeGraph([local, r1, r2, r3, r4, w3]),
remoteGraph = makeGraph([remote, s1, s2, s3, s4, w4]),
action = iD.actionMergeRemoteChanges('r', localGraph, remoteGraph).withOption('force_local'),
action = iD.actionMergeRemoteChanges('r', localGraph, remoteGraph, discardTags).withOption('force_local'),
result = action(localGraph);
expect(result.entity('r').version).to.eql('2');
@@ -506,7 +508,7 @@ describe('iD.actionMergeRemoteChanges', function () {
remote = base.entity('r').update({tags: remoteTags, members: remoteMembers, version: '2'}),
localGraph = makeGraph([local, r1, r2, r3, r4, w3]),
remoteGraph = makeGraph([remote, s1, s2, s3, s4, w4]),
action = iD.actionMergeRemoteChanges('r', localGraph, remoteGraph).withOption('force_remote'),
action = iD.actionMergeRemoteChanges('r', localGraph, remoteGraph, discardTags).withOption('force_remote'),
result = action(localGraph);
expect(result.entity('r').version).to.eql('2');
+33 -18
View File
@@ -22,7 +22,7 @@ describe('iD.coreData', function() {
});
it('sets the fileMap', function() {
var data = iD.coreData(_context);
var files = { 'intro_graph': 'data/intro_graph.json' };
var files = { 'intro_graph': 'data/intro_graph.min.json' };
expect(data.fileMap(files)).to.be.ok;
});
});
@@ -31,31 +31,46 @@ describe('iD.coreData', function() {
it('returns a promise resolved if we already have the data', function(done) {
var data = iD.coreData(_context);
var prom = data.get('test');
expect(prom).to.be.a('promise');
prom.then(function (data) {
expect(data).to.be.a('object');
expect(data.hello).to.eql('world');
done();
});
// 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) {
throw err;
done();
});
});
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.catch(function (err) {
expect(/^Unknown data file/.test(err)).to.be.true;
done();
});
prom
.then(function(data) {
throw new Error('got data ' + data);
done();
})
.catch(function(err) {
expect(/^Unknown data file/.test(err)).to.be.true;
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.json' };
var files = { 'intro_graph': 'data/intro_graph.min.json' };
var data = iD.coreData(_context).fileMap(files);
var prom = data.get('intro_graph');
expect(prom).to.be.a('promise');
prom.then(function (data) {
expect(data).to.be.a('object');
expect(data.n1.tags.name).to.eql('Three Rivers City Hall');
done();
});
// expect(prom).to.be.a('promise'); // these are polyfilled in phantomjs
prom
.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();
});
});
});
+16 -8
View File
@@ -222,46 +222,54 @@ describe('iD.osmEntity', function () {
});
describe('#deprecatedTags', function () {
var deprecated = [
{ old: { highway: 'no' } },
{ old: { amenity: 'toilet' }, replace: { amenity: 'toilets' } },
{ old: { speedlimit: '*' }, replace: { maxspeed: '$1' } },
{ old: { man_made: 'water_tank' }, replace: { man_made: 'storage_tank', content: 'water' } },
{ old: { amenity: 'gambling', gambling: 'casino' }, replace: { amenity: 'casino' } }
];
it('returns none if entity has no tags', function () {
expect(iD.osmEntity().deprecatedTags()).to.eql([]);
expect(iD.osmEntity().deprecatedTags(deprecated)).to.eql([]);
});
it('returns none when no tags are deprecated', function () {
expect(iD.osmEntity({ tags: { amenity: 'toilets' } }).deprecatedTags()).to.eql([]);
expect(iD.osmEntity({ tags: { amenity: 'toilets' } }).deprecatedTags(deprecated)).to.eql([]);
});
it('returns 1:0 replacement', function () {
expect(iD.osmEntity({ tags: { highway: 'no' } }).deprecatedTags()).to.eql(
expect(iD.osmEntity({ tags: { highway: 'no' } }).deprecatedTags(deprecated)).to.eql(
[{ old: { highway: 'no' } }]
);
});
it('returns 1:1 replacement', function () {
expect(iD.osmEntity({ tags: { amenity: 'toilet' } }).deprecatedTags()).to.eql(
expect(iD.osmEntity({ tags: { amenity: 'toilet' } }).deprecatedTags(deprecated)).to.eql(
[{ old: { amenity: 'toilet' }, replace: { amenity: 'toilets' } }]
);
});
it('returns 1:1 wildcard', function () {
expect(iD.osmEntity({ tags: { speedlimit: '50' } }).deprecatedTags()).to.eql(
expect(iD.osmEntity({ tags: { speedlimit: '50' } }).deprecatedTags(deprecated)).to.eql(
[{ old: { speedlimit: '*' }, replace: { maxspeed: '$1' } }]
);
});
it('returns 1:2 total replacement', function () {
expect(iD.osmEntity({ tags: { man_made: 'water_tank' } }).deprecatedTags()).to.eql(
expect(iD.osmEntity({ tags: { man_made: 'water_tank' } }).deprecatedTags(deprecated)).to.eql(
[{ old: { man_made: 'water_tank' }, replace: { man_made: 'storage_tank', content: 'water' } }]
);
});
it('returns 1:2 partial replacement', function () {
expect(iD.osmEntity({ tags: { man_made: 'water_tank', content: 'water' } }).deprecatedTags()).to.eql(
expect(iD.osmEntity({ tags: { man_made: 'water_tank', content: 'water' } }).deprecatedTags(deprecated)).to.eql(
[{ old: { man_made: 'water_tank' }, replace: { man_made: 'storage_tank', content: 'water' } }]
);
});
it('returns 2:1 replacement', function () {
expect(iD.osmEntity({ tags: { amenity: 'gambling', gambling: 'casino' } }).deprecatedTags()).to.eql(
expect(iD.osmEntity({ tags: { amenity: 'gambling', gambling: 'casino' } }).deprecatedTags(deprecated)).to.eql(
[{ old: { amenity: 'gambling', gambling: 'casino' }, replace: { amenity: 'casino' } }]
);
});
+2
View File
@@ -19,6 +19,8 @@ iD.data.presets = {
man_made: { name: 'Man Made', tags: { man_made: '*' }, geometry: ['vertex', 'point', 'line', 'area'] }
}
};
// creating `coreContext` creates validators, and `validatonOutdatedTags` will try to load this
iD.data.deprecated = [];
mocha.setup({
+14
View File
@@ -1,6 +1,19 @@
describe('iD.uiFieldLocalized', function() {
var context, selection, field;
before(function() {
iD.data.languages = {
de: { nativeName: 'Deutsch' },
en: { nativeName: 'English' }
};
iD.data.territory_languages = {};
});
after(function() {
delete iD.data.languages;
delete iD.data.territory_languages;
});
beforeEach(function() {
context = iD.coreContext();
selection = d3.select(document.createElement('div'));
@@ -8,6 +21,7 @@ describe('iD.uiFieldLocalized', function() {
field.locked = function() { return false; };
});
it('adds a blank set of fields when the + button is clicked', function() {
var localized = iD.uiFieldLocalized(field, context);
selection.call(localized);
+12
View File
@@ -1,10 +1,22 @@
describe('iD.validations.outdated_tags', function () {
var context;
before(function() {
iD.data.deprecated = [
{ old: { highway: 'no' } },
{ old: { highway: 'ford' }, replace: { ford: '*' } }
];
});
after(function() {
delete iD.data.deprecated;
});
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]});