1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-05 07:24:56 +01:00
metamask-extension/ui/components/app/token-cell/token-cell.test.js

91 lines
2.1 KiB
JavaScript
Raw Normal View History

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
import Identicon from '../../ui/identicon';
import TokenCell from '.';
2018-09-24 18:28:04 +02:00
describe('Token Cell', () => {
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,
preferences: {},
provider: {
chainId: '0x1',
ticker: 'ETH',
type: 'mainnet',
},
2018-09-24 18:28:04 +02:00
},
};
2018-09-24 18:28:04 +02:00
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
const store = mockStore(state);
2018-09-24 18:28:04 +02:00
let onClick;
beforeEach(() => {
onClick = sinon.stub();
2018-09-24 18:28:04 +02:00
wrapper = mount(
<Provider store={store}>
<MemoryRouter>
<TokenCell
address="0xAnotherToken"
symbol="TEST"
string="5.000"
currentCurrency="usd"
image="./test-image"
onClick={onClick}
/>
</MemoryRouter>
</Provider>,
);
});
2018-09-24 18:28:04 +02:00
afterEach(() => {
sinon.restore();
});
it('renders Identicon with props from token cell', () => {
expect(wrapper.find(Identicon).prop('address')).toStrictEqual(
'0xAnotherToken',
);
expect(wrapper.find(Identicon).prop('image')).toStrictEqual('./test-image');
});
2018-09-24 18:28:04 +02:00
it('renders token balance', () => {
expect(wrapper.find('.asset-list-item__token-value').text()).toStrictEqual(
'5.000',
);
});
it('renders token symbol', () => {
expect(wrapper.find('.asset-list-item__token-symbol').text()).toStrictEqual(
'TEST',
);
});
2018-09-24 18:28:04 +02:00
it('renders converted fiat amount', () => {
expect(wrapper.find('.list-item__subheading').text()).toStrictEqual(
'$0.52 USD',
);
});
2018-09-24 18:28:04 +02:00
it('calls onClick when clicked', () => {
expect(!onClick.called).toStrictEqual(true);
wrapper.simulate('click');
expect(onClick.called).toStrictEqual(true);
});
});