Initialize download scheme preference

The download dialog checks the logged-in property to determine whether
it should check user preferences for a default download scheme.
Previously, however, it would check the flag before it had been
completely initialized (it starts out with a value of false) resulting
in the preferred scheme never being selected.

With this change, the download dialog reacts to changes in the logged-in
property instead of in the "attached" lifecycle method.

Bug: Issue 4203
But: Issue 5147
Change-Id: Ic412b1d9a04cc6083b090d7767172e541578e5c3
This commit is contained in:
Wyatt Allen
2016-12-15 11:49:50 -08:00
parent 8824ce1e44
commit 2345a5d19c
2 changed files with 26 additions and 9 deletions

View File

@@ -30,6 +30,7 @@
loggedIn: {
type: Boolean,
value: false,
observer: '_loggedInChanged',
},
_schemes: {
@@ -49,15 +50,6 @@
Gerrit.RESTClientBehavior,
],
attached: function() {
if (!this.loggedIn) { return; }
this.$.restAPI.getPreferences().then(function(prefs) {
if (prefs.download_scheme) {
this._selectedScheme = prefs.download_scheme;
}
}.bind(this));
},
focus: function() {
this.$.download.focus();
},
@@ -70,6 +62,15 @@
};
},
_loggedInChanged: function(loggedIn) {
if (!loggedIn) { return; }
this.$.restAPI.getPreferences().then(function(prefs) {
if (prefs.download_scheme) {
this._selectedScheme = prefs.download_scheme;
}
}.bind(this));
},
_computeDownloadCommands: function(change, patchNum, _selectedScheme) {
var commandObj;
for (var rev in change.revisions) {

View File

@@ -162,6 +162,22 @@ limitations under the License.
assert.isFalse(el.hasAttribute('selected'));
});
});
test('loads scheme from preferences w/o initial login', function(done) {
stub('gr-rest-api-interface', {
getPreferences: function() {
return Promise.resolve({download_scheme: 'repo'});
},
});
element.loggedIn = true;
assert.isTrue(element.$.restAPI.getPreferences.called);
element.$.restAPI.getPreferences.lastCall.returnValue.then(function() {
assert.equal(element._selectedScheme, 'repo');
done();
});
});
});
suite('gr-download-dialog tests', function() {