Refactor wallet connect, automatically propose network
This commit is contained in:
@@ -3,37 +3,90 @@ import { setupRenderingTest } from 'ember-qunit';
|
||||
import { render } from '@ember/test-helpers';
|
||||
import hbs from 'htmlbars-inline-precompile';
|
||||
|
||||
function stubWalletApi () {
|
||||
window.ethereum = {
|
||||
on: function() { return true; },
|
||||
request: function() { return Promise.resolve(); }
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
test('Unknown user without wallet', async function(assert) {
|
||||
await render(hbs`<TopbarAccountPanel />`);
|
||||
|
||||
assert.ok(this.element.textContent.trim().match(/^Anonymous/));
|
||||
assert.ok(
|
||||
this.element.textContent.trim().match(/^Anonymous/),
|
||||
'shows current user as anonymous'
|
||||
);
|
||||
assert.equal(
|
||||
this.element.querySelectorAll('button#signup').length, 1,
|
||||
'signup button is visible'
|
||||
);
|
||||
assert.equal(
|
||||
this.element.querySelectorAll('button#connect').length, 0,
|
||||
'connect button is not visible'
|
||||
);
|
||||
});
|
||||
|
||||
test('unknown user with Ethereum wallet', async function(assert) {
|
||||
test('Unknown user with disconnected wallet', async function(assert) {
|
||||
stubWalletApi();
|
||||
let service = this.owner.lookup('service:kredits');
|
||||
service.set('currentUserAccounts', []);
|
||||
await render(hbs`<TopbarAccountPanel />`);
|
||||
|
||||
assert.ok(
|
||||
this.element.textContent.trim().match(/^Anonymous/),
|
||||
'shows current user as anonymous'
|
||||
);
|
||||
assert.equal(
|
||||
this.element.querySelectorAll('button#signup').length, 1,
|
||||
'signup button is visible'
|
||||
);
|
||||
assert.equal(
|
||||
this.element.querySelectorAll('button#connect').length, 1,
|
||||
'connect button is visible'
|
||||
);
|
||||
});
|
||||
|
||||
test('Unknown user with connected wallet', async function(assert) {
|
||||
stubWalletApi();
|
||||
let service = this.owner.lookup('service:kredits');
|
||||
service.set('currentUserAccounts', [{ foo: 'bar' }]);
|
||||
await render(hbs`<TopbarAccountPanel />`);
|
||||
|
||||
assert.ok(this.element.textContent.trim().match(/^Anonymous/));
|
||||
assert.ok(
|
||||
this.element.textContent.trim().match(/^Anonymous/),
|
||||
'shows current user as anonymous'
|
||||
);
|
||||
assert.equal(
|
||||
this.element.querySelectorAll('button#signup').length, 1,
|
||||
'signup button is visible'
|
||||
);
|
||||
assert.equal(
|
||||
this.element.querySelectorAll('button#connect').length, 0,
|
||||
'connect button is not visible'
|
||||
);
|
||||
});
|
||||
|
||||
test('known contributor', async function(assert) {
|
||||
test('Known contributor', async function(assert) {
|
||||
stubWalletApi();
|
||||
let service = this.owner.lookup('service:kredits');
|
||||
service.set('currentUserAccounts', [{ foo: 'bar' }]);
|
||||
service.set('currentUser', {
|
||||
name: 'Dorian Nakamoto',
|
||||
isCore: false
|
||||
});
|
||||
service.set('currentUser', { name: 'Dorian Nakamoto', isCore: false });
|
||||
await render(hbs`<TopbarAccountPanel />`);
|
||||
|
||||
assert.dom(this.element).hasText('Dorian Nakamoto');
|
||||
|
||||
service.set('currentUser.isCore', true);
|
||||
await render(hbs`<TopbarAccountPanel />`);
|
||||
|
||||
assert.equal(this.element.querySelectorAll('span.core-flag').length, 1);
|
||||
assert.dom(this.element).hasText(
|
||||
'Dorian Nakamoto', 'shows current user\'s name'
|
||||
);
|
||||
assert.equal(
|
||||
this.element.querySelectorAll('button#signup').length, 0,
|
||||
'signup button is not visible'
|
||||
);
|
||||
assert.equal(
|
||||
this.element.querySelectorAll('button#connect').length, 0,
|
||||
'connect button is not visible'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user