Merge pull request #6302 from openstreetmap/text-raw-tag-editor

Text raw tag editor / Copy-paste tags
This commit is contained in:
Bryan Housel
2019-05-03 14:53:08 -04:00
committed by GitHub
11 changed files with 307 additions and 85 deletions
+46 -27
View File
@@ -2,57 +2,76 @@ describe('iD.util', function() {
describe('utilGetAllNodes', function() {
it('gets all descendant nodes of a way', function() {
var a = iD.osmNode({ id: 'a' }),
b = iD.osmNode({ id: 'b' }),
w = iD.osmWay({ id: 'w', nodes: ['a','b','a'] }),
graph = iD.coreGraph([a, b, w]),
result = iD.utilGetAllNodes(['w'], graph);
var a = iD.osmNode({ id: 'a' });
var b = iD.osmNode({ id: 'b' });
var w = iD.osmWay({ id: 'w', nodes: ['a','b','a'] });
var graph = iD.coreGraph([a, b, w]);
var result = iD.utilGetAllNodes(['w'], graph);
expect(result).to.have.members([a, b]);
expect(result).to.have.lengthOf(2);
});
it('gets all descendant nodes of a relation', function() {
var a = iD.osmNode({ id: 'a' }),
b = iD.osmNode({ id: 'b' }),
c = iD.osmNode({ id: 'c' }),
w = iD.osmWay({ id: 'w', nodes: ['a','b','a'] }),
r = iD.osmRelation({ id: 'r', members: [{id: 'w'}, {id: 'c'}] }),
graph = iD.coreGraph([a, b, c, w, r]),
result = iD.utilGetAllNodes(['r'], graph);
var a = iD.osmNode({ id: 'a' });
var b = iD.osmNode({ id: 'b' });
var c = iD.osmNode({ id: 'c' });
var w = iD.osmWay({ id: 'w', nodes: ['a','b','a'] });
var r = iD.osmRelation({ id: 'r', members: [{id: 'w'}, {id: 'c'}] });
var graph = iD.coreGraph([a, b, c, w, r]);
var result = iD.utilGetAllNodes(['r'], graph);
expect(result).to.have.members([a, b, c]);
expect(result).to.have.lengthOf(3);
});
it('gets all descendant nodes of multiple ids', function() {
var a = iD.osmNode({ id: 'a' }),
b = iD.osmNode({ id: 'b' }),
c = iD.osmNode({ id: 'c' }),
d = iD.osmNode({ id: 'd' }),
e = iD.osmNode({ id: 'e' }),
w1 = iD.osmWay({ id: 'w1', nodes: ['a','b','a'] }),
w2 = iD.osmWay({ id: 'w2', nodes: ['c','b','a','c'] }),
r = iD.osmRelation({ id: 'r', members: [{id: 'w1'}, {id: 'd'}] }),
graph = iD.coreGraph([a, b, c, d, e, w1, w2, r]),
result = iD.utilGetAllNodes(['r', 'w2', 'e'], graph);
var a = iD.osmNode({ id: 'a' });
var b = iD.osmNode({ id: 'b' });
var c = iD.osmNode({ id: 'c' });
var d = iD.osmNode({ id: 'd' });
var e = iD.osmNode({ id: 'e' });
var w1 = iD.osmWay({ id: 'w1', nodes: ['a','b','a'] });
var w2 = iD.osmWay({ id: 'w2', nodes: ['c','b','a','c'] });
var r = iD.osmRelation({ id: 'r', members: [{id: 'w1'}, {id: 'd'}] });
var graph = iD.coreGraph([a, b, c, d, e, w1, w2, r]);
var result = iD.utilGetAllNodes(['r', 'w2', 'e'], graph);
expect(result).to.have.members([a, b, c, d, e]);
expect(result).to.have.lengthOf(5);
});
it('handles recursive relations', function() {
var a = iD.osmNode({ id: 'a' }),
r1 = iD.osmRelation({ id: 'r1', members: [{id: 'r2'}] }),
r2 = iD.osmRelation({ id: 'r2', members: [{id: 'r1'}, {id: 'a'}] }),
graph = iD.coreGraph([a, r1, r2]),
result = iD.utilGetAllNodes(['r1'], graph);
var a = iD.osmNode({ id: 'a' });
var r1 = iD.osmRelation({ id: 'r1', members: [{id: 'r2'}] });
var r2 = iD.osmRelation({ id: 'r2', members: [{id: 'r1'}, {id: 'a'}] });
var graph = iD.coreGraph([a, r1, r2]);
var result = iD.utilGetAllNodes(['r1'], graph);
expect(result).to.have.members([a]);
expect(result).to.have.lengthOf(1);
});
});
it('utilTagDiff', function() {
var oldTags = { a: 'one', b: 'two', c: 'three' };
var newTags = { a: 'one', b: 'three', d: 'four' };
var diff = iD.utilTagDiff(oldTags, newTags);
expect(diff).to.have.length(4);
expect(diff[0]).to.eql({
type: '-', key: 'b', oldVal: 'two', newVal: 'three', display: '- b=two' // delete-modify
});
expect(diff[1]).to.eql({
type: '+', key: 'b', oldVal: 'two', newVal: 'three', display: '+ b=three' // insert-modify
});
expect(diff[2]).to.eql({
type: '-', key: 'c', oldVal: 'three', newVal: undefined, display: '- c=three' // delete
});
expect(diff[3]).to.eql({
type: '+', key: 'd', oldVal: undefined, newVal: 'four', display: '+ d=four' // insert
});
});
it('utilTagText', function() {
expect(iD.utilTagText({})).to.eql('');
expect(iD.utilTagText({tags:{foo:'bar'}})).to.eql('foo=bar');