Merge "Only send changed labels with review"
This commit is contained in:
@@ -157,7 +157,16 @@
|
|||||||
|
|
||||||
var selectedVal = selectorEl.selectedItem.getAttribute('data-value');
|
var selectedVal = selectorEl.selectedItem.getAttribute('data-value');
|
||||||
selectedVal = parseInt(selectedVal, 10);
|
selectedVal = parseInt(selectedVal, 10);
|
||||||
obj.labels[label] = selectedVal;
|
|
||||||
|
// Only send the selection if the user changed it.
|
||||||
|
var prevVal = this._getVoteForAccount(this.labels, label,
|
||||||
|
this._account);
|
||||||
|
if (prevVal !== null) {
|
||||||
|
prevVal = parseInt(prevVal, 10);
|
||||||
|
}
|
||||||
|
if (selectedVal !== prevVal) {
|
||||||
|
obj.labels[label] = selectedVal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (this.draft != null) {
|
if (this.draft != null) {
|
||||||
obj.message = this.draft;
|
obj.message = this.draft;
|
||||||
@@ -280,23 +289,22 @@
|
|||||||
return Object.keys(labelsObj).sort();
|
return Object.keys(labelsObj).sort();
|
||||||
},
|
},
|
||||||
|
|
||||||
_computeIndexOfLabelValue: function(
|
_getVoteForAccount: function(labels, labelName, account) {
|
||||||
labels, permittedLabels, labelName, account) {
|
|
||||||
var t = labels[labelName];
|
|
||||||
if (!t) { return null; }
|
|
||||||
var labelValue = null;
|
|
||||||
|
|
||||||
// Is there an existing vote for the current user? If so, use that.
|
|
||||||
var votes = labels[labelName];
|
var votes = labels[labelName];
|
||||||
if (votes.all && votes.all.length > 0) {
|
if (votes.all && votes.all.length > 0) {
|
||||||
for (var i = 0; i < votes.all.length; i++) {
|
for (var i = 0; i < votes.all.length; i++) {
|
||||||
if (votes.all[i]._account_id == account._account_id) {
|
if (votes.all[i]._account_id == account._account_id) {
|
||||||
labelValue = votes.all[i].value;
|
return votes.all[i].value;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
|
||||||
|
_computeIndexOfLabelValue: function(
|
||||||
|
labels, permittedLabels, labelName, account) {
|
||||||
|
if (!labels[labelName]) { return null; }
|
||||||
|
var labelValue = this._getVoteForAccount(labels, labelName, account);
|
||||||
var len = permittedLabels[labelName] != null ?
|
var len = permittedLabels[labelName] != null ?
|
||||||
permittedLabels[labelName].length : 0;
|
permittedLabels[labelName].length : 0;
|
||||||
for (var i = 0; i < len; i++) {
|
for (var i = 0; i < len; i++) {
|
||||||
|
|||||||
@@ -380,5 +380,23 @@ limitations under the License.
|
|||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
element._chooseFocusTarget(), element.FocusTarget.BODY);
|
element._chooseFocusTarget(), element.FocusTarget.BODY);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('only send labels that have changed', function(done) {
|
||||||
|
var saveReviewStub = sinon.stub(element, '_saveReview',
|
||||||
|
function(review) {
|
||||||
|
assert.deepEqual(review.labels, {Verified: -1});
|
||||||
|
return Promise.resolve({ok: true});
|
||||||
|
});
|
||||||
|
|
||||||
|
element.addEventListener('send', function() {
|
||||||
|
saveReviewStub.restore();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
MockInteractions.tap(element.$$(
|
||||||
|
'iron-selector[data-label="Verified"] > ' +
|
||||||
|
'gr-button[data-value="-1"]'));
|
||||||
|
MockInteractions.tap(element.$$('.send'));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user