mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 05:30:35 +02:00
Change utilTagDiff to return an object with details
This commit is contained in:
+14
-2
@@ -22,10 +22,22 @@ export function utilTagDiff(oldTags, newTags) {
|
||||
var newVal = newTags[k];
|
||||
|
||||
if (oldVal && (!newVal || newVal !== oldVal)) {
|
||||
tagDiff.push('- ' + k + '=' + oldVal);
|
||||
tagDiff.push({
|
||||
type: '-',
|
||||
key: k,
|
||||
oldVal: oldVal,
|
||||
newVal: newVal,
|
||||
display: '- ' + k + '=' + oldVal
|
||||
});
|
||||
}
|
||||
if (newVal && (!oldVal || newVal !== oldVal)) {
|
||||
tagDiff.push('+ ' + k + '=' + newVal);
|
||||
tagDiff.push({
|
||||
type: '+',
|
||||
key: k,
|
||||
oldVal: oldVal,
|
||||
newVal: newVal,
|
||||
display: '+ ' + k + '=' + newVal
|
||||
});
|
||||
}
|
||||
});
|
||||
return tagDiff;
|
||||
|
||||
@@ -99,10 +99,10 @@ export function validationOutdatedTags() {
|
||||
.attr('class', 'tagDiff-row')
|
||||
.append('td')
|
||||
.attr('class', function(d) {
|
||||
var klass = d.charAt(0) === '+' ? 'add' : 'remove';
|
||||
var klass = d.type === '+' ? 'add' : 'remove';
|
||||
return 'tagDiff-cell tagDiff-cell-' + klass;
|
||||
})
|
||||
.text(function(d) { return d; });
|
||||
.text(function(d) { return d.display; });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -107,10 +107,10 @@ export function validationPrivateData() {
|
||||
.attr('class', 'tagDiff-row')
|
||||
.append('td')
|
||||
.attr('class', function(d) {
|
||||
var klass = d.charAt(0) === '+' ? 'add' : 'remove';
|
||||
var klass = d.type === '+' ? 'add' : 'remove';
|
||||
return 'tagDiff-cell tagDiff-cell-' + klass;
|
||||
})
|
||||
.text(function(d) { return d; });
|
||||
.text(function(d) { return d.display; });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+12
-4
@@ -58,10 +58,18 @@ describe('iD.util', function() {
|
||||
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('- b=two'); // delete-modify
|
||||
expect(diff[1]).to.eql('+ b=three'); // insert-modify
|
||||
expect(diff[2]).to.eql('- c=three'); // delete
|
||||
expect(diff[3]).to.eql('+ d=four'); // insert
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user