Fixes bug in gr-account-list#_filterSuggestion

There was a bug in the `_filterSuggestion` method where the account was
being compared with itself. This change captures the behavior in unit
tests and applies a fix.

Change-Id: I943f7587cc777cee689a7e81a81878266198e3ed
This commit is contained in:
Wyatt Allen 2016-07-26 09:41:33 -07:00
parent a008aa9428
commit a831714376
2 changed files with 57 additions and 1 deletions

View File

@ -91,9 +91,12 @@
},
_filterSuggestion: function(reviewer) {
// If the reviewer is already on the change.
if (!this.$.entry.notOwnerOrReviewer(reviewer)) {
return false;
}
// If the reviewer is in the pending list to be added to the change.
for (var i = 0; i < this.accounts.length; i++) {
var account = this.accounts[i];
if (!account._pendingAdd) {
@ -104,10 +107,11 @@
return false;
}
if (reviewer.account && !account._group &&
account._account_id === account._account_id) {
reviewer.account._account_id === account._account_id) {
return false;
}
}
return true;
},

View File

@ -232,5 +232,57 @@ limitations under the License.
},
]);
});
suite('_filterSuggestion', function() {
var notOwnerOrReviewerStub;
setup(function() {
notOwnerOrReviewerStub = sinon.stub(element.$.entry,
'notOwnerOrReviewer');
});
teardown(function() {
notOwnerOrReviewerStub.restore();
});
test('_filterSuggestion owner or reviewer', function() {
notOwnerOrReviewerStub.returns(false);
var reviewer = {account: makeAccount()};
var result = element._filterSuggestion(reviewer);
assert.isFalse(result);
});
test('_filterSuggestion new', function() {
notOwnerOrReviewerStub.returns(true);
var reviewer = {account: makeAccount()};
var result = element._filterSuggestion(reviewer);
assert.isTrue(result);
});
test('_filterSuggestion pending', function() {
notOwnerOrReviewerStub.returns(true);
var reviewer = {account: element.accounts[1]};
element.accounts[1]._pendingAdd = true;
var result = element._filterSuggestion(reviewer);
assert.isFalse(result);
});
test('_filterSuggestion new with pending', function() {
notOwnerOrReviewerStub.returns(true);
var reviewer = {account: makeAccount()};
element.accounts[1]._pendingAdd = true;
var result = element._filterSuggestion(reviewer);
assert.isTrue(result);
});
});
});
</script>