Merge "ES6ify /gr-http-password/*"

This commit is contained in:
Kasper Nilsson
2017-05-16 01:49:36 +00:00
committed by Gerrit Code Review
2 changed files with 30 additions and 32 deletions

View File

@@ -23,33 +23,33 @@
_passwordUrl: String,
},
loadData: function() {
var promises = [];
loadData() {
const promises = [];
promises.push(this.$.restAPI.getAccount().then(function(account) {
promises.push(this.$.restAPI.getAccount().then(account => {
this._username = account.username;
}.bind(this)));
}));
promises.push(this.$.restAPI.getConfig().then(function(info) {
promises.push(this.$.restAPI.getConfig().then(info => {
this._passwordUrl = info.auth.http_password_url || null;
}.bind(this)));
}));
return Promise.all(promises);
},
_handleGenerateTap: function() {
_handleGenerateTap() {
this._generatedPassword = 'Generating...';
this.$.generatedPasswordOverlay.open();
this.$.restAPI.generateAccountHttpPassword().then(function(newPassword) {
this.$.restAPI.generateAccountHttpPassword().then(newPassword => {
this._generatedPassword = newPassword;
}.bind(this));
});
},
_closeOverlay: function() {
_closeOverlay() {
this.$.generatedPasswordOverlay.close();
},
_generatedPasswordOverlayClosed: function() {
_generatedPasswordOverlayClosed() {
this._generatedPassword = null;
},
});

View File

@@ -33,33 +33,31 @@ limitations under the License.
</test-fixture>
<script>
suite('gr-http-password tests', function() {
var element;
var account;
var password;
var config;
suite('gr-http-password tests', () => {
let element;
let account;
let config;
setup(function(done) {
setup(done => {
account = {username: 'user name'};
config = {auth: {}};
password = 'the password';
stub('gr-rest-api-interface', {
getAccount: function() { return Promise.resolve(account); },
getConfig: function() { return Promise.resolve(config); },
getAccount() { return Promise.resolve(account); },
getConfig() { return Promise.resolve(config); },
});
element = fixture('basic');
element.loadData().then(function() { flush(done); });
element.loadData().then(() => { flush(done); });
});
test('generate password', function() {
var button = element.$.generateButton;
var nextPassword = 'the new password';
var generateResolve;
var generateStub = sinon.stub(element.$.restAPI,
'generateAccountHttpPassword', function() {
return new Promise(function(resolve) {
test('generate password', () => {
const button = element.$.generateButton;
const nextPassword = 'the new password';
let generateResolve;
const generateStub = sinon.stub(element.$.restAPI,
'generateAccountHttpPassword', () => {
return new Promise(resolve => {
generateResolve = resolve;
});
});
@@ -73,18 +71,18 @@ limitations under the License.
generateResolve(nextPassword);
generateStub.lastCall.returnValue.then(function() {
generateStub.lastCall.returnValue.then(() => {
assert.equal(element._generatedPassword, nextPassword);
});
});
test('without http_password_url', function() {
test('without http_password_url', () => {
assert.isNull(element._passwordUrl);
});
test('with http_password_url', function(done) {
test('with http_password_url', done => {
config.auth.http_password_url = 'http://example.com/';
element.loadData().then(function() {
element.loadData().then(() => {
assert.isNotNull(element._passwordUrl);
assert.equal(element._passwordUrl, config.auth.http_password_url);
done();