mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-27 12:56:01 +01:00
df85ab6e10
A new page has been created for viewing assets. This replaces the old `selectedToken` state, which previously would augment the home page to show token-specific information. The new asset page shows the standard token overview as seen previously on the home page, plus a history filtered to show just transactions relevant to that token. The actions that were available in the old token list menu have been moved to a "Token Options" menu that mirrors the "Account Options" menu. The `selectedTokenAddress` state has been removed, as it is no longer being used for anything. `getMetaMetricState` has been renamed to `getBackgroundMetaMetricState` because its sole purpose is extracting data from the background state to send metrics from the background. It's not really a selector, but it was convenient for it to use the same selectors the UI uses to extract background data, so I left it there for now. A new Redux store has been added to track state related to browser history. The most recent "overview" page (i.e. the home page or the asset page) is currently being tracked, so that actions taken from the asset page can return the user back to the asset page when the action has finished.
98 lines
2.9 KiB
JavaScript
98 lines
2.9 KiB
JavaScript
import React from 'react'
|
|
import { Provider } from 'react-redux'
|
|
import assert from 'assert'
|
|
import sinon from 'sinon'
|
|
import configureMockStore from 'redux-mock-store'
|
|
import { mountWithRouter } from '../../../../../test/lib/render-helpers'
|
|
import AddToken from '../index'
|
|
|
|
describe('Add Token', function () {
|
|
let wrapper
|
|
|
|
const state = {
|
|
metamask: {
|
|
tokens: [],
|
|
},
|
|
}
|
|
|
|
const store = configureMockStore()(state)
|
|
|
|
const props = {
|
|
history: {
|
|
push: sinon.stub().callsFake(() => {}),
|
|
},
|
|
setPendingTokens: sinon.spy(),
|
|
clearPendingTokens: sinon.spy(),
|
|
tokens: [],
|
|
identities: {},
|
|
mostRecentOverviewPage: '/',
|
|
}
|
|
|
|
describe('Add Token', function () {
|
|
before(function () {
|
|
wrapper = mountWithRouter(
|
|
<Provider store={store}>
|
|
<AddToken.WrappedComponent {...props} />
|
|
</Provider>, store
|
|
)
|
|
|
|
wrapper.find({ name: 'customToken' }).simulate('click')
|
|
})
|
|
|
|
afterEach(function () {
|
|
props.history.push.reset()
|
|
})
|
|
|
|
it('next button is disabled when no fields are populated', function () {
|
|
const nextButton = wrapper.find('.button.btn-secondary.page-container__footer-button')
|
|
|
|
assert.equal(nextButton.props().disabled, true)
|
|
})
|
|
|
|
it('edits token address', function () {
|
|
const tokenAddress = '0x617b3f8050a0BD94b6b1da02B4384eE5B4DF13F4'
|
|
const event = { target: { value: tokenAddress } }
|
|
const customAddress = wrapper.find('input#custom-address')
|
|
|
|
customAddress.simulate('change', event)
|
|
assert.equal(wrapper.find('AddToken').instance().state.customAddress, tokenAddress)
|
|
})
|
|
|
|
|
|
it('edits token symbol', function () {
|
|
const tokenSymbol = 'META'
|
|
const event = { target: { value: tokenSymbol } }
|
|
const customAddress = wrapper.find('#custom-symbol')
|
|
customAddress.last().simulate('change', event)
|
|
|
|
assert.equal(wrapper.find('AddToken').instance().state.customSymbol, tokenSymbol)
|
|
})
|
|
|
|
it('edits token decimal precision', function () {
|
|
const tokenPrecision = '2'
|
|
const event = { target: { value: tokenPrecision } }
|
|
const customAddress = wrapper.find('#custom-decimals')
|
|
customAddress.last().simulate('change', event)
|
|
|
|
assert.equal(wrapper.find('AddToken').instance().state.customDecimals, tokenPrecision)
|
|
})
|
|
|
|
it('next', function () {
|
|
const nextButton = wrapper.find('.button.btn-secondary.page-container__footer-button')
|
|
nextButton.simulate('click')
|
|
|
|
assert(props.setPendingTokens.calledOnce)
|
|
assert(props.history.push.calledOnce)
|
|
assert.equal(props.history.push.getCall(0).args[0], '/confirm-add-token')
|
|
})
|
|
|
|
it('cancels', function () {
|
|
const cancelButton = wrapper.find('button.btn-default.page-container__footer-button')
|
|
cancelButton.simulate('click')
|
|
|
|
assert(props.clearPendingTokens.calledOnce)
|
|
assert.equal(props.history.push.getCall(0).args[0], '/')
|
|
})
|
|
})
|
|
})
|