mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-19 15:08:23 +02:00
Entity#mergeTags
This commit is contained in:
@@ -66,6 +66,20 @@ iD.Entity.prototype = {
|
||||
return iD.Entity(this, attrs, {_updated: true});
|
||||
},
|
||||
|
||||
mergeTags: function(tags) {
|
||||
var merged = _.clone(this.tags);
|
||||
for (var k in tags) {
|
||||
var t1 = merged[k],
|
||||
t2 = tags[k];
|
||||
if (t1 && t1 !== t2) {
|
||||
merged[k] = t1 + "; " + t2;
|
||||
} else {
|
||||
merged[k] = t2;
|
||||
}
|
||||
}
|
||||
return this.update({tags: merged});
|
||||
},
|
||||
|
||||
created: function() {
|
||||
return this._updated && this.osmId().charAt(0) === '-';
|
||||
},
|
||||
|
||||
@@ -69,6 +69,33 @@ describe('iD.Entity', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#mergeTags", function () {
|
||||
it("returns a new Entity", function () {
|
||||
var a = iD.Entity(),
|
||||
b = a.mergeTags({});
|
||||
expect(b instanceof iD.Entity).to.be.true;
|
||||
expect(a).not.to.equal(b);
|
||||
});
|
||||
|
||||
it("merges tags", function () {
|
||||
var a = iD.Entity({tags: {a: 'a'}}),
|
||||
b = a.mergeTags({b: 'b'});
|
||||
expect(b.tags).to.eql({a: 'a', b: 'b'});
|
||||
});
|
||||
|
||||
it("combines non-conflicting tags", function () {
|
||||
var a = iD.Entity({tags: {a: 'a'}}),
|
||||
b = a.mergeTags({a: 'a'});
|
||||
expect(b.tags).to.eql({a: 'a'});
|
||||
});
|
||||
|
||||
it("combines conflicting tags with semicolons", function () {
|
||||
var a = iD.Entity({tags: {a: 'a'}}),
|
||||
b = a.mergeTags({a: 'b'});
|
||||
expect(b.tags).to.eql({a: 'a; b'});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#osmId", function () {
|
||||
it("returns an OSM ID as a string", function () {
|
||||
expect(iD.Entity({id: 'w1234'}).osmId()).to.eql('1234');
|
||||
|
||||
Reference in New Issue
Block a user