Add check for removability before removing accounts in UI
Bug: Issue 4964 Change-Id: I31756865b5dab090f1a83669fb8e9798e28c0f7c
This commit is contained in:
@@ -94,6 +94,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
_removeAccount: function(toRemove) {
|
_removeAccount: function(toRemove) {
|
||||||
|
if (!toRemove || !this._computeRemovable(toRemove)) { return; }
|
||||||
for (var i = 0; i < this.accounts.length; i++) {
|
for (var i = 0; i < this.accounts.length; i++) {
|
||||||
var matches;
|
var matches;
|
||||||
var account = this.accounts[i];
|
var account = this.accounts[i];
|
||||||
@@ -119,7 +120,7 @@
|
|||||||
}
|
}
|
||||||
switch (e.detail.keyCode) {
|
switch (e.detail.keyCode) {
|
||||||
case 8: // Backspace
|
case 8: // Backspace
|
||||||
this.splice('accounts', this.accounts.length - 1, 1);
|
this._removeAccount(this.accounts[this.accounts.length - 1]);
|
||||||
break;
|
break;
|
||||||
case 37: // Left arrow
|
case 37: // Left arrow
|
||||||
var chips = this.accountChips;
|
var chips = this.accountChips;
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ limitations under the License.
|
|||||||
|
|
||||||
test('addition and removal of account/group chips', function() {
|
test('addition and removal of account/group chips', function() {
|
||||||
flushAsynchronousOperations();
|
flushAsynchronousOperations();
|
||||||
|
sandbox.stub(element, '_computeRemovable').returns(true);
|
||||||
// Existing accounts are listed.
|
// Existing accounts are listed.
|
||||||
var chips = getChips();
|
var chips = getChips();
|
||||||
assert.equal(chips.length, 2);
|
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() {
|
suite('keyboard interactions', function() {
|
||||||
|
|
||||||
test('backspace at text input start removes last account', function() {
|
test('backspace at text input start removes last account', function() {
|
||||||
var input = element.$.entry.$.input;
|
var input = element.$.entry.$.input;
|
||||||
sandbox.stub(element.$.entry, '_getReviewerSuggestions');
|
sandbox.stub(element.$.entry, '_getReviewerSuggestions');
|
||||||
sandbox.stub(input, '_updateSuggestions');
|
sandbox.stub(input, '_updateSuggestions');
|
||||||
|
sandbox.stub(element, '_computeRemovable').returns(true);
|
||||||
// Next line is a workaround for Firefix not moving cursor
|
// Next line is a workaround for Firefix not moving cursor
|
||||||
// on input field update
|
// on input field update
|
||||||
assert.equal(input.$.input.selectionStart, 0);
|
assert.equal(input.$.input.selectionStart, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user