Change utilTagDiff to return an object with details

This commit is contained in:
Bryan Housel
2019-05-02 22:59:41 -04:00
parent 61819058d3
commit 7b4a9a43b0
4 changed files with 30 additions and 10 deletions
+14 -2
View File
@@ -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;
+2 -2
View File
@@ -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; });
}
}
+2 -2
View File
@@ -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
View File
@@ -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() {