2017-01-31 12:21:50 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
|
|
|
// 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/>.
|
|
|
|
|
2017-04-19 18:00:05 +02:00
|
|
|
import BigNumber from 'bignumber.js';
|
2017-01-31 12:21:50 +01:00
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import React from 'react';
|
2017-05-05 15:14:05 +02:00
|
|
|
import sinon from 'sinon';
|
2017-01-31 12:21:50 +01:00
|
|
|
|
2017-04-21 11:40:22 +02:00
|
|
|
import apiutil from '@parity/api/util';
|
2017-01-31 12:21:50 +01:00
|
|
|
|
2017-05-05 15:14:05 +02:00
|
|
|
import Balance from './balance';
|
|
|
|
|
|
|
|
const ADDRESS = '0x123456789abcdef0123456789abcdef0123456789abcdef';
|
2017-04-19 18:00:05 +02:00
|
|
|
|
|
|
|
const TOKENS = {
|
|
|
|
'eth': { tag: 'ETH' },
|
|
|
|
'gav': { tag: 'GAV', format: 1 },
|
|
|
|
'tst': { tag: 'TST', format: 1 }
|
|
|
|
};
|
2017-01-31 12:21:50 +01:00
|
|
|
|
|
|
|
const BALANCE = {
|
2017-04-19 18:00:05 +02:00
|
|
|
'eth': new BigNumber(122),
|
|
|
|
'gav': new BigNumber(345),
|
|
|
|
'tst': new BigNumber(0)
|
2017-01-31 12:21:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
let api;
|
2017-05-05 15:14:05 +02:00
|
|
|
let store;
|
2017-01-31 12:21:50 +01:00
|
|
|
let component;
|
|
|
|
|
2017-05-05 15:14:05 +02:00
|
|
|
function createStore () {
|
|
|
|
store = {
|
|
|
|
dispatch: sinon.stub(),
|
|
|
|
subscribe: sinon.stub(),
|
|
|
|
getState: () => {
|
|
|
|
return {
|
|
|
|
balances: {
|
|
|
|
[ADDRESS]: BALANCE
|
|
|
|
},
|
|
|
|
tokens: TOKENS
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return store;
|
|
|
|
}
|
|
|
|
|
2017-01-31 12:21:50 +01:00
|
|
|
function createApi () {
|
|
|
|
api = {
|
|
|
|
dappsUrl: 'http://testDapps:1234/',
|
|
|
|
util: apiutil
|
|
|
|
};
|
|
|
|
|
|
|
|
return api;
|
|
|
|
}
|
|
|
|
|
|
|
|
function render (props = {}) {
|
|
|
|
component = shallow(
|
|
|
|
<Balance
|
2017-05-05 15:14:05 +02:00
|
|
|
address={ ADDRESS }
|
2017-01-31 12:21:50 +01:00
|
|
|
className='testClass'
|
|
|
|
{ ...props }
|
|
|
|
/>,
|
|
|
|
{
|
2017-05-05 15:14:05 +02:00
|
|
|
context: {
|
|
|
|
api: createApi(),
|
|
|
|
store: createStore()
|
|
|
|
}
|
2017-01-31 12:21:50 +01:00
|
|
|
}
|
2017-05-05 15:14:05 +02:00
|
|
|
).find('Balance').shallow();
|
|
|
|
console.log(component.debug());
|
2017-01-31 12:21:50 +01:00
|
|
|
|
|
|
|
return component;
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('ui/Balance', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
render();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders defaults', () => {
|
|
|
|
expect(component).to.be.ok;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('passes the specified className', () => {
|
|
|
|
expect(component.hasClass('testClass')).to.be.true;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders all the non-zero balances', () => {
|
2017-05-05 15:14:05 +02:00
|
|
|
expect(component.find('TokenImage')).to.have.length(2);
|
2017-01-31 12:21:50 +01:00
|
|
|
});
|
|
|
|
});
|