Add check for removability before removing accounts in UI

Bug: Issue 4964
Change-Id: I31756865b5dab090f1a83669fb8e9798e28c0f7c
This commit is contained in:
Kasper Nilsson
2016-11-18 16:07:39 -08:00
parent 214726d5ce
commit 67d66ec598
2 changed files with 12 additions and 2 deletions

View File

@@ -94,6 +94,7 @@
},
_removeAccount: function(toRemove) {
if (!toRemove || !this._computeRemovable(toRemove)) { return; }
for (var i = 0; i < this.accounts.length; i++) {
var matches;
var account = this.accounts[i];
@@ -119,7 +120,7 @@
}
switch (e.detail.keyCode) {
case 8: // Backspace
this.splice('accounts', this.accounts.length - 1, 1);
this._removeAccount(this.accounts[this.accounts.length - 1]);
break;
case 37: // Left arrow
var chips = this.accountChips;

View File

@@ -80,7 +80,7 @@ limitations under the License.
test('addition and removal of account/group chips', function() {
flushAsynchronousOperations();
sandbox.stub(element, '_computeRemovable').returns(true);
// Existing accounts are listed.
var chips = getChips();
assert.equal(chips.length, 2);
@@ -235,12 +235,21 @@ limitations under the License.
]);
});
test('removeAccount fails if account is not removable', function() {
element.readonly = true;
var acct = makeAccount();
element.accounts = [acct];
element._removeAccount(acct);
assert.equal(element.accounts.length, 1);
});
suite('keyboard interactions', function() {
test('backspace at text input start removes last account', function() {
var input = element.$.entry.$.input;
sandbox.stub(element.$.entry, '_getReviewerSuggestions');
sandbox.stub(input, '_updateSuggestions');
sandbox.stub(element, '_computeRemovable').returns(true);
// Next line is a workaround for Firefix not moving cursor
// on input field update
assert.equal(input.$.input.selectionStart, 0);