Merge "ES6ify /gr-account-info/*"
This commit is contained in:
@@ -60,25 +60,25 @@
|
|||||||
'_statusChanged(_account.status)',
|
'_statusChanged(_account.status)',
|
||||||
],
|
],
|
||||||
|
|
||||||
loadData: function() {
|
loadData() {
|
||||||
var promises = [];
|
const promises = [];
|
||||||
|
|
||||||
this._loading = true;
|
this._loading = true;
|
||||||
|
|
||||||
promises.push(this.$.restAPI.getConfig().then(function(config) {
|
promises.push(this.$.restAPI.getConfig().then(config => {
|
||||||
this._serverConfig = config;
|
this._serverConfig = config;
|
||||||
}.bind(this)));
|
}));
|
||||||
|
|
||||||
promises.push(this.$.restAPI.getAccount().then(function(account) {
|
promises.push(this.$.restAPI.getAccount().then(account => {
|
||||||
this._account = account;
|
this._account = account;
|
||||||
}.bind(this)));
|
}));
|
||||||
|
|
||||||
return Promise.all(promises).then(function() {
|
return Promise.all(promises).then(() => {
|
||||||
this._loading = false;
|
this._loading = false;
|
||||||
}.bind(this));
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
save: function() {
|
save() {
|
||||||
if (!this.hasUnsavedChanges) {
|
if (!this.hasUnsavedChanges) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
@@ -88,45 +88,45 @@
|
|||||||
// Must be done in sequence to avoid race conditions (@see Issue 5721)
|
// Must be done in sequence to avoid race conditions (@see Issue 5721)
|
||||||
return this._maybeSetName()
|
return this._maybeSetName()
|
||||||
.then(this._maybeSetStatus.bind(this))
|
.then(this._maybeSetStatus.bind(this))
|
||||||
.then(function() {
|
.then(() => {
|
||||||
this._hasNameChange = false;
|
this._hasNameChange = false;
|
||||||
this._hasStatusChange = false;
|
this._hasStatusChange = false;
|
||||||
this._saving = false;
|
this._saving = false;
|
||||||
this.fire('account-detail-update');
|
this.fire('account-detail-update');
|
||||||
}.bind(this));
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_maybeSetName: function() {
|
_maybeSetName() {
|
||||||
return this._hasNameChange && this.mutable ?
|
return this._hasNameChange && this.mutable ?
|
||||||
this.$.restAPI.setAccountName(this._account.name) :
|
this.$.restAPI.setAccountName(this._account.name) :
|
||||||
Promise.resolve();
|
Promise.resolve();
|
||||||
},
|
},
|
||||||
|
|
||||||
_maybeSetStatus: function() {
|
_maybeSetStatus() {
|
||||||
return this._hasStatusChange ?
|
return this._hasStatusChange ?
|
||||||
this.$.restAPI.setAccountStatus(this._account.status) :
|
this.$.restAPI.setAccountStatus(this._account.status) :
|
||||||
Promise.resolve();
|
Promise.resolve();
|
||||||
},
|
},
|
||||||
|
|
||||||
_computeHasUnsavedChanges: function(name, status) {
|
_computeHasUnsavedChanges(name, status) {
|
||||||
return name || status;
|
return name || status;
|
||||||
},
|
},
|
||||||
|
|
||||||
_computeMutable: function(config) {
|
_computeMutable(config) {
|
||||||
return config.auth.editable_account_fields.indexOf('FULL_NAME') !== -1;
|
return config.auth.editable_account_fields.includes('FULL_NAME');
|
||||||
},
|
},
|
||||||
|
|
||||||
_statusChanged: function() {
|
_statusChanged() {
|
||||||
if (this._loading) { return; }
|
if (this._loading) { return; }
|
||||||
this._hasStatusChange = true;
|
this._hasStatusChange = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
_nameChanged: function() {
|
_nameChanged() {
|
||||||
if (this._loading) { return; }
|
if (this._loading) { return; }
|
||||||
this._hasNameChange = true;
|
this._hasNameChange = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
_handleKeydown: function(e) {
|
_handleKeydown(e) {
|
||||||
if (e.keyCode === 13) { // Enter
|
if (e.keyCode === 13) { // Enter
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
this.save();
|
this.save();
|
||||||
|
@@ -33,16 +33,16 @@ limitations under the License.
|
|||||||
</test-fixture>
|
</test-fixture>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
suite('gr-account-info tests', function() {
|
suite('gr-account-info tests', () => {
|
||||||
var element;
|
let element;
|
||||||
var account;
|
let account;
|
||||||
var config;
|
let config;
|
||||||
var sandbox;
|
let sandbox;
|
||||||
|
|
||||||
function valueOf(title) {
|
function valueOf(title) {
|
||||||
var sections = Polymer.dom(element.root).querySelectorAll('section');
|
const sections = Polymer.dom(element.root).querySelectorAll('section');
|
||||||
var titleEl;
|
let titleEl;
|
||||||
for (var i = 0; i < sections.length; i++) {
|
for (let i = 0; i < sections.length; i++) {
|
||||||
titleEl = sections[i].querySelector('.title');
|
titleEl = sections[i].querySelector('.title');
|
||||||
if (titleEl.textContent === title) {
|
if (titleEl.textContent === title) {
|
||||||
return sections[i].querySelector('.value');
|
return sections[i].querySelector('.value');
|
||||||
@@ -50,7 +50,7 @@ limitations under the License.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setup(function(done) {
|
setup(done => {
|
||||||
sandbox = sinon.sandbox.create();
|
sandbox = sinon.sandbox.create();
|
||||||
account = {
|
account = {
|
||||||
_account_id: 123,
|
_account_id: 123,
|
||||||
@@ -62,22 +62,22 @@ limitations under the License.
|
|||||||
config = {auth: {editable_account_fields: []}};
|
config = {auth: {editable_account_fields: []}};
|
||||||
|
|
||||||
stub('gr-rest-api-interface', {
|
stub('gr-rest-api-interface', {
|
||||||
getAccount: function() { return Promise.resolve(account); },
|
getAccount() { return Promise.resolve(account); },
|
||||||
getConfig: function() { return Promise.resolve(config); },
|
getConfig() { return Promise.resolve(config); },
|
||||||
getPreferences: function() {
|
getPreferences() {
|
||||||
return Promise.resolve({time_format: 'HHMM_12'});
|
return Promise.resolve({time_format: 'HHMM_12'});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
element = fixture('basic');
|
element = fixture('basic');
|
||||||
// Allow the element to render.
|
// Allow the element to render.
|
||||||
element.loadData().then(function() { flush(done); });
|
element.loadData().then(() => { flush(done); });
|
||||||
});
|
});
|
||||||
|
|
||||||
teardown(function() {
|
teardown(() => {
|
||||||
sandbox.restore();
|
sandbox.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('basic account info render', function() {
|
test('basic account info render', () => {
|
||||||
assert.isFalse(element._loading);
|
assert.isFalse(element._loading);
|
||||||
|
|
||||||
assert.equal(valueOf('ID').textContent, account._account_id);
|
assert.equal(valueOf('ID').textContent, account._account_id);
|
||||||
@@ -85,10 +85,10 @@ limitations under the License.
|
|||||||
assert.equal(valueOf('Username').textContent, account.username);
|
assert.equal(valueOf('Username').textContent, account.username);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('user name render (immutable)', function() {
|
test('user name render (immutable)', () => {
|
||||||
var section = element.$.nameSection;
|
const section = element.$.nameSection;
|
||||||
var displaySpan = section.querySelectorAll('.value')[0];
|
const displaySpan = section.querySelectorAll('.value')[0];
|
||||||
var inputSpan = section.querySelectorAll('.value')[1];
|
const inputSpan = section.querySelectorAll('.value')[1];
|
||||||
|
|
||||||
assert.isFalse(element.mutable);
|
assert.isFalse(element.mutable);
|
||||||
assert.isFalse(displaySpan.hasAttribute('hidden'));
|
assert.isFalse(displaySpan.hasAttribute('hidden'));
|
||||||
@@ -96,13 +96,13 @@ limitations under the License.
|
|||||||
assert.isTrue(inputSpan.hasAttribute('hidden'));
|
assert.isTrue(inputSpan.hasAttribute('hidden'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('user name render (mutable)', function() {
|
test('user name render (mutable)', () => {
|
||||||
element.set('_serverConfig',
|
element.set('_serverConfig',
|
||||||
{auth: {editable_account_fields: ['FULL_NAME']}});
|
{auth: {editable_account_fields: ['FULL_NAME']}});
|
||||||
|
|
||||||
var section = element.$.nameSection;
|
const section = element.$.nameSection;
|
||||||
var displaySpan = section.querySelectorAll('.value')[0];
|
const displaySpan = section.querySelectorAll('.value')[0];
|
||||||
var inputSpan = section.querySelectorAll('.value')[1];
|
const inputSpan = section.querySelectorAll('.value')[1];
|
||||||
|
|
||||||
assert.isTrue(element.mutable);
|
assert.isTrue(element.mutable);
|
||||||
assert.isTrue(displaySpan.hasAttribute('hidden'));
|
assert.isTrue(displaySpan.hasAttribute('hidden'));
|
||||||
@@ -110,25 +110,25 @@ limitations under the License.
|
|||||||
assert.isFalse(inputSpan.hasAttribute('hidden'));
|
assert.isFalse(inputSpan.hasAttribute('hidden'));
|
||||||
});
|
});
|
||||||
|
|
||||||
suite('account info edit', function() {
|
suite('account info edit', () => {
|
||||||
var nameChangedSpy;
|
let nameChangedSpy;
|
||||||
var statusChangedSpy;
|
let statusChangedSpy;
|
||||||
var nameStub;
|
let nameStub;
|
||||||
var statusStub;
|
let statusStub;
|
||||||
|
|
||||||
setup(function() {
|
setup(() => {
|
||||||
nameChangedSpy = sandbox.spy(element, '_nameChanged');
|
nameChangedSpy = sandbox.spy(element, '_nameChanged');
|
||||||
statusChangedSpy = sandbox.spy(element, '_statusChanged');
|
statusChangedSpy = sandbox.spy(element, '_statusChanged');
|
||||||
element.set('_serverConfig',
|
element.set('_serverConfig',
|
||||||
{auth: {editable_account_fields: ['FULL_NAME']}});
|
{auth: {editable_account_fields: ['FULL_NAME']}});
|
||||||
|
|
||||||
nameStub = sandbox.stub(element.$.restAPI, 'setAccountName',
|
nameStub = sandbox.stub(element.$.restAPI, 'setAccountName', name =>
|
||||||
function(name) { return Promise.resolve(); });
|
Promise.resolve());
|
||||||
statusStub = sandbox.stub(element.$.restAPI, 'setAccountStatus',
|
statusStub = sandbox.stub(element.$.restAPI, 'setAccountStatus',
|
||||||
function(status) { return Promise.resolve(); });
|
status => Promise.resolve());
|
||||||
});
|
});
|
||||||
|
|
||||||
test('name', function(done) {
|
test('name', done => {
|
||||||
assert.isTrue(element.mutable);
|
assert.isTrue(element.mutable);
|
||||||
assert.isFalse(element.hasUnsavedChanges);
|
assert.isFalse(element.hasUnsavedChanges);
|
||||||
|
|
||||||
@@ -142,13 +142,13 @@ limitations under the License.
|
|||||||
|
|
||||||
assert.isTrue(nameStub.called);
|
assert.isTrue(nameStub.called);
|
||||||
assert.isFalse(statusStub.called);
|
assert.isFalse(statusStub.called);
|
||||||
nameStub.lastCall.returnValue.then(function() {
|
nameStub.lastCall.returnValue.then(() => {
|
||||||
assert.equal(nameStub.lastCall.args[0], 'new name');
|
assert.equal(nameStub.lastCall.args[0], 'new name');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('status', function(done) {
|
test('status', done => {
|
||||||
assert.isTrue(element.mutable);
|
assert.isTrue(element.mutable);
|
||||||
assert.isFalse(element.hasUnsavedChanges);
|
assert.isFalse(element.hasUnsavedChanges);
|
||||||
|
|
||||||
@@ -158,10 +158,10 @@ limitations under the License.
|
|||||||
assert.isTrue(statusChangedSpy.called);
|
assert.isTrue(statusChangedSpy.called);
|
||||||
assert.isTrue(element.hasUnsavedChanges);
|
assert.isTrue(element.hasUnsavedChanges);
|
||||||
|
|
||||||
element.save().then(function() {
|
element.save().then(() => {
|
||||||
assert.isTrue(statusStub.called);
|
assert.isTrue(statusStub.called);
|
||||||
assert.isFalse(nameStub.called);
|
assert.isFalse(nameStub.called);
|
||||||
statusStub.lastCall.returnValue.then(function() {
|
statusStub.lastCall.returnValue.then(() => {
|
||||||
assert.equal(statusStub.lastCall.args[0], 'new status');
|
assert.equal(statusStub.lastCall.args[0], 'new status');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -169,25 +169,25 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
suite('edit name and status', function() {
|
suite('edit name and status', () => {
|
||||||
var nameChangedSpy;
|
let nameChangedSpy;
|
||||||
var statusChangedSpy;
|
let statusChangedSpy;
|
||||||
var nameStub;
|
let nameStub;
|
||||||
var statusStub;
|
let statusStub;
|
||||||
|
|
||||||
setup(function() {
|
setup(() => {
|
||||||
nameChangedSpy = sandbox.spy(element, '_nameChanged');
|
nameChangedSpy = sandbox.spy(element, '_nameChanged');
|
||||||
statusChangedSpy = sandbox.spy(element, '_statusChanged');
|
statusChangedSpy = sandbox.spy(element, '_statusChanged');
|
||||||
element.set('_serverConfig',
|
element.set('_serverConfig',
|
||||||
{auth: {editable_account_fields: ['FULL_NAME']}});
|
{auth: {editable_account_fields: ['FULL_NAME']}});
|
||||||
|
|
||||||
nameStub = sandbox.stub(element.$.restAPI, 'setAccountName',
|
nameStub = sandbox.stub(element.$.restAPI, 'setAccountName', name =>
|
||||||
function(name) { return Promise.resolve(); });
|
Promise.resolve());
|
||||||
statusStub = sandbox.stub(element.$.restAPI, 'setAccountStatus',
|
statusStub = sandbox.stub(element.$.restAPI, 'setAccountStatus',
|
||||||
function(status) { return Promise.resolve(); });
|
status => Promise.resolve());
|
||||||
});
|
});
|
||||||
|
|
||||||
test('set name and status', function(done) {
|
test('set name and status', done => {
|
||||||
assert.isTrue(element.mutable);
|
assert.isTrue(element.mutable);
|
||||||
assert.isFalse(element.hasUnsavedChanges);
|
assert.isFalse(element.hasUnsavedChanges);
|
||||||
|
|
||||||
@@ -201,7 +201,7 @@ limitations under the License.
|
|||||||
|
|
||||||
assert.isTrue(element.hasUnsavedChanges);
|
assert.isTrue(element.hasUnsavedChanges);
|
||||||
|
|
||||||
element.save().then(function() {
|
element.save().then(() => {
|
||||||
assert.isTrue(statusStub.called);
|
assert.isTrue(statusStub.called);
|
||||||
assert.isTrue(nameStub.called);
|
assert.isTrue(nameStub.called);
|
||||||
|
|
||||||
@@ -214,23 +214,23 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
suite('set status but read name', function() {
|
suite('set status but read name', () => {
|
||||||
var statusChangedSpy;
|
let statusChangedSpy;
|
||||||
var statusStub;
|
let statusStub;
|
||||||
|
|
||||||
setup(function() {
|
setup(() => {
|
||||||
statusChangedSpy = sandbox.spy(element, '_statusChanged');
|
statusChangedSpy = sandbox.spy(element, '_statusChanged');
|
||||||
element.set('_serverConfig',
|
element.set('_serverConfig',
|
||||||
{auth: {editable_account_fields: []}});
|
{auth: {editable_account_fields: []}});
|
||||||
|
|
||||||
statusStub = sandbox.stub(element.$.restAPI, 'setAccountStatus',
|
statusStub = sandbox.stub(element.$.restAPI, 'setAccountStatus',
|
||||||
function(status) { return Promise.resolve(); });
|
status => Promise.resolve());
|
||||||
});
|
});
|
||||||
|
|
||||||
test('read full name but set status', function(done) {
|
test('read full name but set status', done => {
|
||||||
var section = element.$.nameSection;
|
const section = element.$.nameSection;
|
||||||
var displaySpan = section.querySelectorAll('.value')[0];
|
const displaySpan = section.querySelectorAll('.value')[0];
|
||||||
var inputSpan = section.querySelectorAll('.value')[1];
|
const inputSpan = section.querySelectorAll('.value')[1];
|
||||||
|
|
||||||
assert.isFalse(element.mutable);
|
assert.isFalse(element.mutable);
|
||||||
|
|
||||||
@@ -246,9 +246,9 @@ limitations under the License.
|
|||||||
|
|
||||||
assert.isTrue(element.hasUnsavedChanges);
|
assert.isTrue(element.hasUnsavedChanges);
|
||||||
|
|
||||||
element.save().then(function() {
|
element.save().then(() => {
|
||||||
assert.isTrue(statusStub.called);
|
assert.isTrue(statusStub.called);
|
||||||
statusStub.lastCall.returnValue.then(function() {
|
statusStub.lastCall.returnValue.then(() => {
|
||||||
assert.equal(statusStub.lastCall.args[0], 'new status');
|
assert.equal(statusStub.lastCall.args[0], 'new status');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user