Restore field inheritance

This commit is contained in:
Bryan Housel
2020-02-10 16:22:02 -05:00
parent 7364cb38fe
commit 3608659d21
6 changed files with 104 additions and 90 deletions
+11 -11
View File
@@ -1,25 +1,25 @@
describe('iD.actionChangePreset', function() {
var oldPreset = iD.presetPreset('old', {tags: {old: 'true'}}),
newPreset = iD.presetPreset('new', {tags: {new: 'true'}});
var oldPreset = iD.presetPreset('old', {tags: {old: 'true'}});
var newPreset = iD.presetPreset('new', {tags: {new: 'true'}});
it('changes from one preset\'s tags to another\'s', function() {
var entity = iD.osmNode({tags: {old: 'true'}}),
graph = iD.coreGraph([entity]),
action = iD.actionChangePreset(entity.id, oldPreset, newPreset);
var entity = iD.osmNode({tags: {old: 'true'}});
var graph = iD.coreGraph([entity]);
var action = iD.actionChangePreset(entity.id, oldPreset, newPreset);
expect(action(graph).entity(entity.id).tags).to.eql({new: 'true'});
});
it('adds the tags of a new preset to an entity without an old preset', function() {
var entity = iD.osmNode(),
graph = iD.coreGraph([entity]),
action = iD.actionChangePreset(entity.id, null, newPreset);
var entity = iD.osmNode();
var graph = iD.coreGraph([entity]);
var action = iD.actionChangePreset(entity.id, null, newPreset);
expect(action(graph).entity(entity.id).tags).to.eql({new: 'true'});
});
it('removes the tags of an old preset from an entity without a new preset', function() {
var entity = iD.osmNode({tags: {old: 'true'}}),
graph = iD.coreGraph([entity]),
action = iD.actionChangePreset(entity.id, oldPreset, null);
var entity = iD.osmNode({tags: {old: 'true'}});
var graph = iD.coreGraph([entity]);
var action = iD.actionChangePreset(entity.id, oldPreset, null);
expect(action(graph).entity(entity.id).tags).to.eql({});
});
});
+23 -9
View File
@@ -1,7 +1,17 @@
describe('iD.presetPreset', function() {
it('has optional fields', function() {
var preset = iD.presetPreset('test', {});
expect(preset.fields).to.eql([]);
describe('#fields', function() {
it('has no fields by default', function() {
var preset = iD.presetPreset('test', {});
expect(preset.fields()).to.eql([]);
});
});
describe('#moreFields', function() {
it('has no moreFields by default', function() {
var preset = iD.presetPreset('test', {});
expect(preset.moreFields()).to.eql([]);
});
});
describe('#matchGeometry', function() {
@@ -136,14 +146,16 @@ describe('iD.presetPreset', function() {
});
it('adds default tags of fields with matching geometry', function() {
var isAddable = true;
var field = iD.presetField('field', {key: 'building', geometry: 'area', default: 'yes'});
var preset = iD.presetPreset('test', {fields: ['field']}, {field: field});
var preset = iD.presetPreset('test', {fields: ['field']}, isAddable, {field: field});
expect(preset.setTags({}, 'area')).to.eql({area: 'yes', building: 'yes'});
});
it('adds no default tags of fields with non-matching geometry', function() {
var isAddable = true;
var field = iD.presetField('field', {key: 'building', geometry: 'area', default: 'yes'});
var preset = iD.presetPreset('test', {fields: ['field']}, {field: field});
var preset = iD.presetPreset('test', {fields: ['field']}, isAddable, {field: field});
expect(preset.setTags({}, 'point')).to.eql({});
});
@@ -179,8 +191,9 @@ describe('iD.presetPreset', function() {
});
it('removes tags that match field default tags', function() {
var field = iD.presetField('field', {key: 'building', geometry: 'area', default: 'yes'}),
preset = iD.presetPreset('test', {fields: ['field']}, {field: field});
var isAddable = true;
var field = iD.presetField('field', {key: 'building', geometry: 'area', default: 'yes'});
var preset = iD.presetPreset('test', {fields: ['field']}, isAddable, {field: field});
expect(preset.unsetTags({building: 'yes'}, 'area')).to.eql({});
});
@@ -190,8 +203,9 @@ describe('iD.presetPreset', function() {
});
it('preserves tags that do not match field default tags', function() {
var field = iD.presetField('field', {key: 'building', geometry: 'area', default: 'yes'}),
preset = iD.presetPreset('test', {fields: ['field']}, {field: field});
var isAddable = true;
var field = iD.presetField('field', {key: 'building', geometry: 'area', default: 'yes'});
var preset = iD.presetPreset('test', {fields: ['field']}, isAddable, {field: field});
expect(preset.unsetTags({building: 'yep'}, 'area')).to.eql({ building: 'yep'});
});