2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2017-01-05 12:06:35 +01:00
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import BigNumber from 'bignumber.js';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import React from 'react';
|
|
|
|
|
2017-05-09 12:01:44 +02:00
|
|
|
import { ETH_TOKEN } from '@parity/shared/util/tokens';
|
2017-04-19 18:00:05 +02:00
|
|
|
|
2017-01-05 12:06:35 +01:00
|
|
|
import Header from './';
|
|
|
|
|
|
|
|
const ACCOUNT = {
|
|
|
|
address: '0x0123456789012345678901234567890123456789',
|
|
|
|
meta: {
|
|
|
|
description: 'the description',
|
|
|
|
tags: ['taga', 'tagb']
|
|
|
|
},
|
|
|
|
uuid: '0xabcdef'
|
|
|
|
};
|
2017-04-19 18:00:05 +02:00
|
|
|
const subscriptions = {};
|
2017-01-05 12:06:35 +01:00
|
|
|
|
|
|
|
let component;
|
|
|
|
let instance;
|
|
|
|
|
2017-04-19 18:00:05 +02:00
|
|
|
const api = {
|
|
|
|
subscribe: (method, callback) => {
|
|
|
|
subscriptions[method] = (subscriptions[method] || []).concat(callback);
|
|
|
|
return Promise.resolve(0);
|
|
|
|
},
|
|
|
|
eth: {
|
|
|
|
getTransactionCount: () => Promise.resolve(new BigNumber(1))
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function reduxStore () {
|
|
|
|
const getState = () => ({
|
|
|
|
balances: {},
|
|
|
|
tokens: {
|
|
|
|
[ETH_TOKEN.id]: ETH_TOKEN
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
getState,
|
|
|
|
dispatch: () => null,
|
|
|
|
subscribe: () => null
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-01-05 12:06:35 +01:00
|
|
|
function render (props = {}) {
|
|
|
|
if (props && !props.account) {
|
|
|
|
props.account = ACCOUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
component = shallow(
|
2017-04-19 18:00:05 +02:00
|
|
|
<Header { ...props } />,
|
|
|
|
{ context: { api } }
|
2017-01-05 12:06:35 +01:00
|
|
|
);
|
|
|
|
instance = component.instance();
|
|
|
|
|
|
|
|
return component;
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('views/Account/Header', () => {
|
|
|
|
describe('rendering', () => {
|
|
|
|
it('renders defaults', () => {
|
|
|
|
expect(render()).to.be.ok;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders null with no account', () => {
|
|
|
|
expect(render(null).find('div')).to.have.length(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders when no account meta', () => {
|
|
|
|
expect(render({ account: { address: ACCOUNT.address } })).to.be.ok;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders when no account description', () => {
|
|
|
|
expect(render({ account: { address: ACCOUNT.address, meta: { tags: [] } } })).to.be.ok;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders when no account tags', () => {
|
|
|
|
expect(render({ account: { address: ACCOUNT.address, meta: { description: 'something' } } })).to.be.ok;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('sections', () => {
|
2017-01-27 21:55:20 +01:00
|
|
|
describe('Balance', () => {
|
|
|
|
let balance;
|
2017-01-05 12:06:35 +01:00
|
|
|
|
2017-01-27 21:55:20 +01:00
|
|
|
beforeEach(() => {
|
2017-04-19 18:00:05 +02:00
|
|
|
render();
|
|
|
|
balance = component.find('Connect(Balance)')
|
|
|
|
.shallow({ context: { store: reduxStore() } });
|
2017-01-27 21:55:20 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders', () => {
|
|
|
|
expect(balance).to.have.length(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('passes the account', () => {
|
2017-04-19 18:00:05 +02:00
|
|
|
expect(balance.props().address).to.deep.equal(ACCOUNT.address);
|
2017-01-27 21:55:20 +01:00
|
|
|
});
|
2017-01-05 12:06:35 +01:00
|
|
|
});
|
|
|
|
|
2017-01-27 21:55:20 +01:00
|
|
|
describe('Certifications', () => {
|
|
|
|
let certs;
|
2017-01-05 12:06:35 +01:00
|
|
|
|
2017-01-27 21:55:20 +01:00
|
|
|
beforeEach(() => {
|
|
|
|
render();
|
|
|
|
certs = component.find('Connect(Certifications)');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders', () => {
|
|
|
|
expect(certs).to.have.length(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('passes the address', () => {
|
|
|
|
expect(certs.props().address).to.deep.equal(ACCOUNT.address);
|
|
|
|
});
|
2017-01-05 12:06:35 +01:00
|
|
|
});
|
|
|
|
|
2017-01-27 21:55:20 +01:00
|
|
|
describe('IdentityIcon', () => {
|
|
|
|
let icon;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
render();
|
2017-05-05 15:14:05 +02:00
|
|
|
icon = component.find('IdentityIcon');
|
2017-01-27 21:55:20 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders', () => {
|
|
|
|
expect(icon).to.have.length(1);
|
|
|
|
});
|
2017-01-05 12:06:35 +01:00
|
|
|
|
2017-01-27 21:55:20 +01:00
|
|
|
it('passes the address', () => {
|
|
|
|
expect(icon.props().address).to.deep.equal(ACCOUNT.address);
|
|
|
|
});
|
2017-01-05 12:06:35 +01:00
|
|
|
});
|
|
|
|
|
2017-01-27 21:55:20 +01:00
|
|
|
describe('QrCode', () => {
|
|
|
|
let qr;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
render();
|
|
|
|
qr = component.find('QrCode');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders', () => {
|
|
|
|
expect(qr).to.have.length(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('passes the address', () => {
|
|
|
|
expect(qr.props().value).to.deep.equal(ACCOUNT.address);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Tags', () => {
|
|
|
|
let tags;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
render();
|
|
|
|
tags = component.find('Tags');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders', () => {
|
|
|
|
expect(tags).to.have.length(1);
|
|
|
|
});
|
2017-01-05 12:06:35 +01:00
|
|
|
|
2017-01-27 21:55:20 +01:00
|
|
|
it('passes the tags', () => {
|
|
|
|
expect(tags.props().tags).to.deep.equal(ACCOUNT.meta.tags);
|
|
|
|
});
|
2017-01-05 12:06:35 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('renderName', () => {
|
|
|
|
it('renders null with hideName', () => {
|
|
|
|
render({ hideName: true });
|
|
|
|
expect(instance.renderName()).to.be.null;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the name', () => {
|
|
|
|
render();
|
|
|
|
expect(instance.renderName()).not.to.be.null;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders when no address specified', () => {
|
|
|
|
render({ account: {} });
|
|
|
|
expect(instance.renderName()).to.be.ok;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('renderTxCount', () => {
|
2017-04-19 18:00:05 +02:00
|
|
|
it('renders null when txCount is null', () => {
|
|
|
|
render();
|
2017-01-05 12:06:35 +01:00
|
|
|
expect(instance.renderTxCount()).to.be.null;
|
|
|
|
});
|
|
|
|
|
2017-04-19 18:00:05 +02:00
|
|
|
it('renders null when contract', () => {
|
|
|
|
render({ isContract: true });
|
2017-01-05 12:06:35 +01:00
|
|
|
|
2017-04-19 18:00:05 +02:00
|
|
|
subscriptions['eth_blockNumber'].forEach((callback) => {
|
|
|
|
callback();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(instance.renderTxCount()).to.be.null;
|
|
|
|
});
|
|
|
|
});
|
2017-01-05 12:06:35 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the tx count', () => {
|
2017-04-19 18:00:05 +02:00
|
|
|
render();
|
|
|
|
|
|
|
|
subscriptions['eth_blockNumber'].forEach((callback) => {
|
|
|
|
callback();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(instance.renderTxCount()).not.to.be.null;
|
|
|
|
});
|
|
|
|
});
|
2017-01-05 12:06:35 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('renderUuid', () => {
|
|
|
|
it('renders null with no uuid', () => {
|
|
|
|
render({ account: Object.assign({}, ACCOUNT, { uuid: null }) });
|
|
|
|
expect(instance.renderUuid()).to.be.null;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the uuid', () => {
|
|
|
|
render();
|
|
|
|
expect(instance.renderUuid()).not.to.be.null;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|