2018-09-24 18:28:04 +02:00
|
|
|
import React from 'react'
|
|
|
|
import assert from 'assert'
|
|
|
|
import thunk from 'redux-thunk'
|
|
|
|
import { Provider } from 'react-redux'
|
|
|
|
import configureMockStore from 'redux-mock-store'
|
|
|
|
import { mount } from 'enzyme'
|
2020-03-25 22:24:14 +01:00
|
|
|
import sinon from 'sinon'
|
2018-09-24 18:28:04 +02:00
|
|
|
|
2020-03-25 19:56:48 +01:00
|
|
|
import TokenCell from '.'
|
|
|
|
import Identicon from '../../ui/identicon'
|
2018-09-24 18:28:04 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('Token Cell', function () {
|
2018-09-24 18:28:04 +02:00
|
|
|
let wrapper
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
metamask: {
|
|
|
|
currentCurrency: 'usd',
|
|
|
|
selectedAddress: '0xAddress',
|
|
|
|
contractExchangeRates: {
|
|
|
|
'0xAnotherToken': 0.015,
|
|
|
|
},
|
|
|
|
conversionRate: 7.00,
|
|
|
|
},
|
|
|
|
appState: {
|
|
|
|
sidebar: {
|
|
|
|
isOpen: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const middlewares = [thunk]
|
|
|
|
const mockStore = configureMockStore(middlewares)
|
|
|
|
const store = mockStore(state)
|
|
|
|
|
2020-03-25 22:24:14 +01:00
|
|
|
let onClick
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
beforeEach(function () {
|
2020-03-25 22:24:14 +01:00
|
|
|
onClick = sinon.stub()
|
2018-09-24 18:28:04 +02:00
|
|
|
wrapper = mount(
|
|
|
|
<Provider store={store}>
|
|
|
|
<TokenCell
|
2019-11-18 16:08:47 +01:00
|
|
|
address="0xAnotherToken"
|
|
|
|
symbol="TEST"
|
|
|
|
string="5.000"
|
|
|
|
currentCurrency="usd"
|
|
|
|
image="./test-image"
|
2020-03-25 22:24:14 +01:00
|
|
|
onClick={onClick}
|
2018-09-24 18:28:04 +02:00
|
|
|
/>
|
|
|
|
</Provider>
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-03-25 22:24:14 +01:00
|
|
|
afterEach(function () {
|
|
|
|
sinon.restore()
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('renders Identicon with props from token cell', function () {
|
2018-09-24 18:28:04 +02:00
|
|
|
assert.equal(wrapper.find(Identicon).prop('address'), '0xAnotherToken')
|
|
|
|
assert.equal(wrapper.find(Identicon).prop('image'), './test-image')
|
|
|
|
})
|
|
|
|
|
2020-06-03 19:50:12 +02:00
|
|
|
it('renders token balance and symbol', function () {
|
|
|
|
assert.equal(wrapper.find('.list-item__heading').text(), '5.000 TEST ')
|
2018-09-24 18:28:04 +02:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('renders converted fiat amount', function () {
|
2020-06-03 19:50:12 +02:00
|
|
|
assert.equal(wrapper.find('.list-item__subheading').text(), '$0.52 USD')
|
2018-09-24 18:28:04 +02:00
|
|
|
})
|
|
|
|
|
2020-03-25 22:24:14 +01:00
|
|
|
it('calls onClick when clicked', function () {
|
|
|
|
assert.ok(!onClick.called)
|
|
|
|
wrapper.simulate('click')
|
|
|
|
assert.ok(onClick.called)
|
|
|
|
})
|
2018-09-24 18:28:04 +02:00
|
|
|
})
|