ES6ify /gr-registration-dialog/*

Bug: Issue 6179
Change-Id: Icaa90f8f83ab0c3c54334153179186e810712739
This commit is contained in:
Kasper Nilsson
2017-05-15 17:42:46 -07:00
parent 00363faafc
commit 6ff0a3b25e
2 changed files with 35 additions and 35 deletions

View File

@@ -38,39 +38,39 @@
role: 'dialog',
},
attached: function() {
this.$.restAPI.getAccount().then(function(account) {
attached() {
this.$.restAPI.getAccount().then(account => {
this._account = account;
}.bind(this));
});
},
_handleNameKeydown: function(e) {
_handleNameKeydown(e) {
if (e.keyCode === 13) { // Enter
e.stopPropagation();
this._save();
}
},
_save: function() {
_save() {
this._saving = true;
var promises = [
const promises = [
this.$.restAPI.setAccountName(this.$.name.value),
this.$.restAPI.setPreferredAccountEmail(this.$.email.value),
];
return Promise.all(promises).then(function() {
return Promise.all(promises).then(() => {
this._saving = false;
this.fire('account-detail-update');
}.bind(this));
});
},
_handleSave: function(e) {
_handleSave(e) {
e.preventDefault();
this._save().then(function() {
this._save().then(() => {
this.fire('close');
}.bind(this));
});
},
_handleClose: function(e) {
_handleClose(e) {
e.preventDefault();
this._saving = true; // disable buttons indefinitely
this.fire('close');

View File

@@ -39,12 +39,12 @@ limitations under the License.
</test-fixture>
<script>
suite('gr-registration-dialog tests', function() {
var element;
var account;
var _listeners;
suite('gr-registration-dialog tests', () => {
let element;
let account;
let _listeners;
setup(function(done) {
setup(done => {
_listeners = {};
account = {
@@ -57,16 +57,16 @@ limitations under the License.
};
stub('gr-rest-api-interface', {
getAccount: function() {
// Once the account is resolved, we can let the test proceed.
getAccount() {
// Once the account is resolved, we can let the test proceed.
flush(done);
return Promise.resolve(account);
},
setAccountName: function(name) {
setAccountName(name) {
account.name = name;
return Promise.resolve();
},
setPreferredAccountEmail: function(email) {
setPreferredAccountEmail(email) {
account.email = email;
return Promise.resolve();
},
@@ -75,8 +75,8 @@ limitations under the License.
element = fixture('basic');
});
teardown(function() {
for (var eventType in _listeners) {
teardown(() => {
for (const eventType in _listeners) {
if (_listeners.hasOwnProperty(eventType)) {
element.removeEventListener(eventType, _listeners[eventType]);
}
@@ -84,14 +84,14 @@ limitations under the License.
});
function listen(eventType) {
return new Promise(function(resolve) {
return new Promise(resolve => {
_listeners[eventType] = function() { resolve(); };
element.addEventListener(eventType, _listeners[eventType]);
});
}
function save(opt_action) {
var promise = listen('account-detail-update');
const promise = listen('account-detail-update');
if (opt_action) {
opt_action();
} else {
@@ -101,7 +101,7 @@ limitations under the License.
}
function close(opt_action) {
var promise = listen('close');
const promise = listen('close');
if (opt_action) {
opt_action();
} else {
@@ -110,18 +110,18 @@ limitations under the License.
return promise;
}
test('fires the close event on close', function(done) {
test('fires the close event on close', done => {
close().then(done);
});
test('fires the close event on save', function(done) {
close(function() {
test('fires the close event on save', done => {
close(() => {
MockInteractions.tap(element.$.saveButton);
}).then(done);
});
test('saves name and preferred email', function(done) {
flush(function() {
test('saves name and preferred email', done => {
flush(() => {
element.$.name.value = 'new name';
element.$.email.value = 'email3';
@@ -130,18 +130,18 @@ limitations under the License.
assert.equal(account.email, 'email');
// Save and verify new values are committed.
save().then(function() {
save().then(() => {
assert.equal(account.name, 'new name');
assert.equal(account.email, 'email3');
}).then(done);
});
});
test('pressing enter saves name', function(done) {
test('pressing enter saves name', done => {
element.$.name.value = 'entered name';
save(function() {
save(() => {
MockInteractions.pressAndReleaseKeyOn(element.$.name, 13); // 'enter'
}).then(function() {
}).then(() => {
assert.equal(account.name, 'entered name');
}).then(done);
});