Move topbar account info to component, add tests

Adds a failing test for users with wallet, but no known contributor
account, where it currently shows no name at all.
This commit is contained in:
2019-07-18 19:26:16 +02:00
parent aa9c3648c0
commit c7d046aa46
4 changed files with 62 additions and 11 deletions
@@ -0,0 +1,10 @@
import Component from '@ember/component';
import { inject as service } from '@ember/service';
export default Component.extend({
tagName: '',
kredits: service(),
});
@@ -0,0 +1,12 @@
<section id="user-account">
{{#if kredits.hasAccounts }}
{{#if kredits.currentUser}}
{{kredits.currentUser.name}}
{{#if kredits.currentUserIsCore}}
<span class="core-flag">(core)</span>
{{/if}}
{{/if}}
{{else}}
Anonymous
{{/if}}
</section>
+1 -11
View File
@@ -1,16 +1,6 @@
<header id="topbar"> <header id="topbar">
<h1>{{link-to "Kosmos Kredits" "dashboard"}}</h1> <h1>{{link-to "Kosmos Kredits" "dashboard"}}</h1>
{{topbar-account-panel}}
<section id="user-account">
{{#if kredits.hasAccounts }}
{{#if kredits.currentUser}}
{{kredits.currentUser.name}}
{{#if kredits.currentUserIsCore}}(core){{/if}}
{{/if}}
{{else}}
Anonymous
{{/if}}
</section>
</header> </header>
{{outlet}} {{outlet}}
@@ -0,0 +1,39 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
module('Integration | Component | topbar-account-panel', function(hooks) {
setupRenderingTest(hooks);
test('unknown user without wallet (or no permission to get wallet/account info)', async function(assert) {
await render(hbs`<TopbarAccountPanel />`);
assert.equal(this.element.textContent.trim(), 'Anonymous');
});
test('unknown user with Ethereum wallet', async function(assert) {
let service = this.owner.lookup('service:kredits');
service.set('currentUserAccounts', [{ foo: 'bar' }]);
await render(hbs`<TopbarAccountPanel />`);
assert.equal(this.element.textContent.trim(), 'Anonymous');
});
test('known contributor', async function(assert) {
let service = this.owner.lookup('service:kredits');
service.set('currentUserAccounts', [{ foo: 'bar' }]);
service.set('currentUser', {
name: 'Dorian Nakamoto',
isCore: false
});
await render(hbs`<TopbarAccountPanel />`);
assert.equal(this.element.textContent.trim(), 'Dorian Nakamoto');
service.set('currentUser.isCore', true);
await render(hbs`<TopbarAccountPanel />`);
assert.equal(this.element.querySelectorAll('span.core-flag').length, 1);
});
});