Reset state flags on loadData calls
In some cases, bound values were setting the flags tracking changes in
gr-account-info. Resetting the flags when loadData is called ensures no
false positives occur.
In addition, upgrades the _usernameChanged logic to compare to the
existing account username value, as opposed to just setting the flag to
true on any modification.
Bug: Issue 7893
Bug: Issue 8287
Change-Id: I75a3cda93bb065a7b9640d4b40905a5e21042bb5
(cherry picked from commit 5cb34e7fa3
)
This commit is contained in:
parent
79f8561402
commit
525c98bf3d
@ -41,18 +41,9 @@
|
||||
'_hasUsernameChange, _hasStatusChange)',
|
||||
},
|
||||
|
||||
_hasNameChange: {
|
||||
type: Boolean,
|
||||
value: false,
|
||||
},
|
||||
_hasUsernameChange: {
|
||||
type: Boolean,
|
||||
value: false,
|
||||
},
|
||||
_hasStatusChange: {
|
||||
type: Boolean,
|
||||
value: false,
|
||||
},
|
||||
_hasNameChange: Boolean,
|
||||
_hasUsernameChange: Boolean,
|
||||
_hasStatusChange: Boolean,
|
||||
_loading: {
|
||||
type: Boolean,
|
||||
value: false,
|
||||
@ -85,6 +76,9 @@
|
||||
}));
|
||||
|
||||
promises.push(this.$.restAPI.getAccount().then(account => {
|
||||
this._hasNameChange = false;
|
||||
this._hasUsernameChange = false;
|
||||
this._hasStatusChange = false;
|
||||
// Provide predefined value for username to trigger computation of
|
||||
// username mutability.
|
||||
account.username = account.username || '';
|
||||
@ -154,8 +148,9 @@
|
||||
},
|
||||
|
||||
_usernameChanged() {
|
||||
if (this._loading) { return; }
|
||||
this._hasUsernameChange = true;
|
||||
if (this._loading || !this._account) { return; }
|
||||
this._hasUsernameChange =
|
||||
(this._account.username || '') !== (this._username || '');
|
||||
},
|
||||
|
||||
_nameChanged() {
|
||||
|
@ -311,5 +311,23 @@ limitations under the License.
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('_usernameChanged compares usernames with loose equality', () => {
|
||||
element._account = {};
|
||||
element._username = '';
|
||||
element._hasUsernameChange = false;
|
||||
element._loading = false;
|
||||
// _usernameChanged is an observer, but call it here after setting
|
||||
// _hasUsernameChange in the test to force recomputation.
|
||||
element._usernameChanged();
|
||||
flushAsynchronousOperations();
|
||||
|
||||
assert.isFalse(element._hasUsernameChange);
|
||||
|
||||
element.set('_username', 'test');
|
||||
flushAsynchronousOperations();
|
||||
|
||||
assert.isTrue(element._hasUsernameChange);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user