2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import thunk from 'redux-thunk';
|
|
|
|
import { Provider } from 'react-redux';
|
|
|
|
import configureMockStore from 'redux-mock-store';
|
|
|
|
import { mount } from 'enzyme';
|
|
|
|
import sinon from 'sinon';
|
|
|
|
import { MemoryRouter } from 'react-router-dom';
|
2018-09-24 18:28:04 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
import Identicon from '../../ui/identicon';
|
|
|
|
import TokenCell from '.';
|
2018-09-24 18:28:04 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('Token Cell', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let wrapper;
|
2018-09-24 18:28:04 +02:00
|
|
|
|
|
|
|
const state = {
|
|
|
|
metamask: {
|
|
|
|
currentCurrency: 'usd',
|
|
|
|
selectedAddress: '0xAddress',
|
|
|
|
contractExchangeRates: {
|
|
|
|
'0xAnotherToken': 0.015,
|
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
conversionRate: 7.0,
|
2020-06-12 20:47:23 +02:00
|
|
|
preferences: {},
|
|
|
|
provider: {
|
2021-02-23 17:27:32 +01:00
|
|
|
chainId: '0x1',
|
2020-06-12 20:47:23 +02:00
|
|
|
ticker: 'ETH',
|
|
|
|
type: 'mainnet',
|
|
|
|
},
|
2018-09-24 18:28:04 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-09-24 18:28:04 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const middlewares = [thunk];
|
|
|
|
const mockStore = configureMockStore(middlewares);
|
|
|
|
const store = mockStore(state);
|
2018-09-24 18:28:04 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let onClick;
|
2020-03-25 22:24:14 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
beforeEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
onClick = sinon.stub();
|
2018-09-24 18:28:04 +02:00
|
|
|
wrapper = mount(
|
|
|
|
<Provider store={store}>
|
2020-06-16 20:04:51 +02:00
|
|
|
<MemoryRouter>
|
|
|
|
<TokenCell
|
|
|
|
address="0xAnotherToken"
|
|
|
|
symbol="TEST"
|
|
|
|
string="5.000"
|
|
|
|
currentCurrency="usd"
|
|
|
|
image="./test-image"
|
|
|
|
onClick={onClick}
|
|
|
|
/>
|
|
|
|
</MemoryRouter>
|
2020-07-14 17:20:41 +02:00
|
|
|
</Provider>,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2018-09-24 18:28:04 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2020-03-25 22:24:14 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('renders Identicon with props from token cell', () => {
|
|
|
|
expect(wrapper.find(Identicon).prop('address')).toStrictEqual(
|
2020-12-03 16:46:22 +01:00
|
|
|
'0xAnotherToken',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(wrapper.find(Identicon).prop('image')).toStrictEqual('./test-image');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-09-24 18:28:04 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('renders token balance', () => {
|
|
|
|
expect(wrapper.find('.asset-list-item__token-value').text()).toStrictEqual(
|
2020-12-03 16:46:22 +01:00
|
|
|
'5.000',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2020-09-01 22:13:58 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('renders token symbol', () => {
|
|
|
|
expect(wrapper.find('.asset-list-item__token-symbol').text()).toStrictEqual(
|
2020-12-03 16:46:22 +01:00
|
|
|
'TEST',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2018-09-24 18:28:04 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('renders converted fiat amount', () => {
|
|
|
|
expect(wrapper.find('.list-item__subheading').text()).toStrictEqual(
|
2020-12-03 16:46:22 +01:00
|
|
|
'$0.52 USD',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2018-09-24 18:28:04 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('calls onClick when clicked', () => {
|
|
|
|
expect(!onClick.called).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.simulate('click');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(onClick.called).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|