2020-08-18 21:18:25 +02:00
|
|
|
import assert from 'assert'
|
2020-01-30 20:34:45 +01:00
|
|
|
import React from 'react'
|
|
|
|
import { Provider } from 'react-redux'
|
|
|
|
import sinon from 'sinon'
|
|
|
|
import configureMockStore from 'redux-mock-store'
|
|
|
|
import { mountWithRouter } from '../../../../../test/lib/render-helpers'
|
2020-08-19 18:27:05 +02:00
|
|
|
import AddToken from '..'
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('Add Token', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
let wrapper
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
metamask: {
|
|
|
|
tokens: [],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
const store = configureMockStore()(state)
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const props = {
|
|
|
|
history: {
|
2020-08-14 13:47:02 +02:00
|
|
|
push: sinon.stub().callsFake(() => undefined),
|
2020-01-30 20:34:45 +01:00
|
|
|
},
|
|
|
|
setPendingTokens: sinon.spy(),
|
|
|
|
clearPendingTokens: sinon.spy(),
|
|
|
|
tokens: [],
|
|
|
|
identities: {},
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage: '/',
|
2020-01-30 20:34:45 +01:00
|
|
|
}
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('Add Token', function () {
|
|
|
|
before(function () {
|
|
|
|
wrapper = mountWithRouter(
|
|
|
|
<Provider store={store}>
|
|
|
|
<AddToken.WrappedComponent {...props} />
|
2020-11-03 00:41:28 +01:00
|
|
|
</Provider>,
|
|
|
|
store,
|
2020-02-11 17:51:13 +01:00
|
|
|
)
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
wrapper.find({ name: 'customToken' }).simulate('click')
|
|
|
|
})
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
afterEach(function () {
|
|
|
|
props.history.push.reset()
|
|
|
|
})
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('next button is disabled when no fields are populated', function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const nextButton = wrapper.find(
|
|
|
|
'.button.btn-secondary.page-container__footer-button',
|
|
|
|
)
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(nextButton.props().disabled, true)
|
2020-01-30 20:34:45 +01:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('edits token address', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
const tokenAddress = '0x617b3f8050a0BD94b6b1da02B4384eE5B4DF13F4'
|
|
|
|
const event = { target: { value: tokenAddress } }
|
|
|
|
const customAddress = wrapper.find('input#custom-address')
|
|
|
|
|
|
|
|
customAddress.simulate('change', event)
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper.find('AddToken').instance().state.customAddress,
|
|
|
|
tokenAddress,
|
|
|
|
)
|
2020-01-30 20:34:45 +01:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('edits token symbol', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
const tokenSymbol = 'META'
|
|
|
|
const event = { target: { value: tokenSymbol } }
|
|
|
|
const customAddress = wrapper.find('#custom-symbol')
|
|
|
|
customAddress.last().simulate('change', event)
|
|
|
|
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper.find('AddToken').instance().state.customSymbol,
|
|
|
|
tokenSymbol,
|
|
|
|
)
|
2020-01-30 20:34:45 +01:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('edits token decimal precision', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
const tokenPrecision = '2'
|
|
|
|
const event = { target: { value: tokenPrecision } }
|
|
|
|
const customAddress = wrapper.find('#custom-decimals')
|
|
|
|
customAddress.last().simulate('change', event)
|
|
|
|
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper.find('AddToken').instance().state.customDecimals,
|
|
|
|
tokenPrecision,
|
|
|
|
)
|
2020-01-30 20:34:45 +01:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('next', function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const nextButton = wrapper.find(
|
|
|
|
'.button.btn-secondary.page-container__footer-button',
|
|
|
|
)
|
2020-01-30 20:34:45 +01:00
|
|
|
nextButton.simulate('click')
|
|
|
|
|
|
|
|
assert(props.setPendingTokens.calledOnce)
|
|
|
|
assert(props.history.push.calledOnce)
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
|
|
|
props.history.push.getCall(0).args[0],
|
|
|
|
'/confirm-add-token',
|
|
|
|
)
|
2020-01-30 20:34:45 +01:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('cancels', function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
const cancelButton = wrapper.find(
|
|
|
|
'button.btn-default.page-container__footer-button',
|
|
|
|
)
|
2020-01-30 20:34:45 +01:00
|
|
|
cancelButton.simulate('click')
|
|
|
|
|
|
|
|
assert(props.clearPendingTokens.calledOnce)
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(props.history.push.getCall(0).args[0], '/')
|
2020-01-30 20:34:45 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|