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

View File

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