diff options
author | Paladox none <thomasmulhall410@yahoo.com> | 2019-03-08 15:03:49 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-03-08 15:03:49 +0000 |
commit | 4355c3ddc32f566490387124127c5e98ab420b83 (patch) | |
tree | 12908ce83030260e2e275c31e7ea7a53117fc984 | |
parent | 674db51505352c31368fbd57efc5ade47f35790e (diff) | |
parent | 0ee62135f2f91a500fc15953b14b99e74d95abb4 (diff) |
Merge "Fix avatars not showing correctly" into stable-2.16
-rw-r--r-- | polygerrit-ui/app/elements/shared/gr-avatar/gr-avatar.js | 21 | ||||
-rw-r--r-- | polygerrit-ui/app/elements/shared/gr-avatar/gr-avatar_test.html | 70 |
2 files changed, 78 insertions, 13 deletions
diff --git a/polygerrit-ui/app/elements/shared/gr-avatar/gr-avatar.js b/polygerrit-ui/app/elements/shared/gr-avatar/gr-avatar.js index f32e940b3f..bf563823ac 100644 --- a/polygerrit-ui/app/elements/shared/gr-avatar/gr-avatar.js +++ b/polygerrit-ui/app/elements/shared/gr-avatar/gr-avatar.js @@ -41,25 +41,30 @@ attached() { Promise.all([ - this.$.restAPI.getConfig(), + this._getConfig(), Gerrit.awaitPluginsLoaded(), ]).then(([cfg]) => { this._hasAvatars = !!(cfg && cfg.plugin && cfg.plugin.has_avatars); - if (this._hasAvatars && this.account) { - // src needs to be set if avatar becomes visible - this._updateAvatarURL(); - } else { - this.hidden = true; - } + + this._updateAvatarURL(); }); }, + _getConfig() { + return this.$.restAPI.getConfig(); + }, + _accountChanged(account) { this._updateAvatarURL(); }, _updateAvatarURL() { - if (this.hidden || !this._hasAvatars) { return; } + if (!this._hasAvatars || !this.account) { + this.hidden = true; + return; + } + this.hidden = false; + const url = this._buildAvatarURL(this.account); if (url) { this.style.backgroundImage = 'url("' + url + '")'; diff --git a/polygerrit-ui/app/elements/shared/gr-avatar/gr-avatar_test.html b/polygerrit-ui/app/elements/shared/gr-avatar/gr-avatar_test.html index f137c7fa01..5ce17c05b9 100644 --- a/polygerrit-ui/app/elements/shared/gr-avatar/gr-avatar_test.html +++ b/polygerrit-ui/app/elements/shared/gr-avatar/gr-avatar_test.html @@ -35,14 +35,17 @@ limitations under the License. <script> suite('gr-avatar tests', () => { let element; + let sandbox; setup(() => { - stub('gr-rest-api-interface', { - getConfig() { return Promise.resolve({plugin: {has_avatars: true}}); }, - }); + sandbox = sinon.sandbox.create(); element = fixture('basic'); }); + teardown(() => { + sandbox.restore(); + }); + test('methods', () => { assert.equal(element._buildAvatarURL( { @@ -94,22 +97,32 @@ limitations under the License. ], }), '/accounts/123/avatar?s=16'); + assert.equal(element._buildAvatarURL(undefined), ''); }); test('dom for existing account', () => { assert.isFalse(element.hasAttribute('hidden')); + + sandbox.stub(element, '_getConfig', () => { + return Promise.resolve({plugin: {has_avatars: true}}); + }); + element.imageSize = 64; element.account = { _account_id: 123, }; + assert.strictEqual(element.style.backgroundImage, ''); + // Emulate plugins loaded. Gerrit._setPluginsPending([]); - return Promise.all([ + + Promise.all([ element.$.restAPI.getConfig(), Gerrit.awaitPluginsLoaded(), ]).then(() => { assert.isFalse(element.hasAttribute('hidden')); + assert.isTrue( element.style.backgroundImage.includes('/accounts/123/avatar?s=64')); }); @@ -117,10 +130,57 @@ limitations under the License. test('dom for non available account', () => { assert.isFalse(element.hasAttribute('hidden')); - element.account = null; + + sandbox.stub(element, '_getConfig', () => { + return Promise.resolve({plugin: {has_avatars: true}}); + }); + + // Emulate plugins loaded. + Gerrit._setPluginsPending([]); + + return Promise.all([ + element.$.restAPI.getConfig(), + Gerrit.awaitPluginsLoaded(), + ]).then(() => { + assert.isTrue(element.hasAttribute('hidden')); + + assert.strictEqual(element.style.backgroundImage, ''); + }); + }); + + test('avatar config not set and account not set', () => { + assert.isFalse(element.hasAttribute('hidden')); + + sandbox.stub(element, '_getConfig', () => { + return Promise.resolve({}); + }); + + // Emulate plugins loaded. + Gerrit._setPluginsPending([]); + + return Promise.all([ + element.$.restAPI.getConfig(), + Gerrit.awaitPluginsLoaded(), + ]).then(() => { + assert.isTrue(element.hasAttribute('hidden')); + }); + }); + + test('avatar config not set and account set', () => { assert.isFalse(element.hasAttribute('hidden')); + + sandbox.stub(element, '_getConfig', () => { + return Promise.resolve({}); + }); + + element.imageSize = 64; + element.account = { + _account_id: 123, + }; + // Emulate plugins loaded. Gerrit._setPluginsPending([]); + return Promise.all([ element.$.restAPI.getConfig(), Gerrit.awaitPluginsLoaded(), |