WA-232 remove custom ERC20 Tokens redux test
This commit is contained in:
parent
3c6264fd27
commit
3d885f0d81
|
@ -0,0 +1,97 @@
|
|||
// @flow
|
||||
import { getWeb3 } from '~/wallets/getWeb3'
|
||||
import { type Match } from 'react-router-dom'
|
||||
import { promisify } from '~/utils/promisify'
|
||||
import { getFirstTokenContract, getSecondTokenContract } from '~/test/utils/tokenMovements'
|
||||
import { aNewStore } from '~/store'
|
||||
import { aMinedSafe } from '~/test/builder/safe.redux.builder'
|
||||
import { travelToSafe } from '~/test/builder/safe.dom.utils'
|
||||
import { buildMathPropsFrom } from '~/test/utils/buildReactRouterProps'
|
||||
import { testToken } from '~/test/builder/tokens.dom.utils'
|
||||
import * as fetchTokensModule from '~/routes/tokens/store/actions/fetchTokens'
|
||||
import * as enhancedFetchModule from '~/utils/fetch'
|
||||
import { TOKEN_ADRESS_PARAM } from '~/routes/tokens/component/AddToken/FirstPage'
|
||||
import { TOKEN_NAME_PARAM, TOKEN_DECIMALS_PARAM, TOKEN_SYMBOL_PARAM, TOKEN_LOGO_URL_PARAM } from '~/routes/tokens/component/AddToken/SecondPage'
|
||||
import addToken from '~/routes/tokens/store/actions/addToken'
|
||||
import { addTokenFnc } from '~/routes/tokens/component/AddToken'
|
||||
import { activeTokensSelector, tokenListSelector } from '~/routes/tokens/store/selectors'
|
||||
import removeTokenAction from '~/routes/tokens/store/actions/removeToken'
|
||||
import { makeToken } from '~/routes/tokens/store/model/token'
|
||||
import { removeToken } from '~/routes/tokens/component/RemoveToken'
|
||||
|
||||
describe('DOM > Feature > Add new ERC 20 Tokens', () => {
|
||||
let web3
|
||||
let accounts
|
||||
let firstErc20Token
|
||||
let secondErc20Token
|
||||
|
||||
beforeAll(async () => {
|
||||
web3 = getWeb3()
|
||||
accounts = await promisify(cb => web3.eth.getAccounts(cb))
|
||||
firstErc20Token = await getFirstTokenContract(web3, accounts[0])
|
||||
secondErc20Token = await getSecondTokenContract(web3, accounts[0])
|
||||
|
||||
// $FlowFixMe
|
||||
enhancedFetchModule.enhancedFetch = jest.fn()
|
||||
enhancedFetchModule.enhancedFetch.mockImplementation(() => Promise.resolve([
|
||||
{
|
||||
address: firstErc20Token.address,
|
||||
name: 'First Token Example',
|
||||
symbol: 'FTE',
|
||||
decimals: 18,
|
||||
logoUrl: 'https://upload.wikimedia.org/wikipedia/commons/c/c0/Earth_simple_icon.png',
|
||||
},
|
||||
]))
|
||||
})
|
||||
|
||||
const checkTokensOf = (store: Store, safeAddress: string) => {
|
||||
const match: Match = buildMathPropsFrom(safeAddress)
|
||||
const activeTokenList = activeTokensSelector(store.getState(), { match })
|
||||
expect(activeTokenList.count()).toBe(1)
|
||||
testToken(activeTokenList.get(0), 'ETH', true)
|
||||
|
||||
const tokenList = tokenListSelector(store.getState(), { match })
|
||||
expect(tokenList.count()).toBe(2)
|
||||
testToken(tokenList.get(0), 'FTE', false)
|
||||
testToken(tokenList.get(1), 'ETH', true)
|
||||
}
|
||||
|
||||
it('removes custom ERC 20 including page reload', async () => {
|
||||
// GIVEN
|
||||
const store = aNewStore()
|
||||
const safeAddress = await aMinedSafe(store)
|
||||
await store.dispatch(fetchTokensModule.fetchTokens(safeAddress))
|
||||
|
||||
const values = {
|
||||
[TOKEN_ADRESS_PARAM]: secondErc20Token.address,
|
||||
[TOKEN_NAME_PARAM]: 'Custom ERC20 Token',
|
||||
[TOKEN_SYMBOL_PARAM]: 'CTS',
|
||||
[TOKEN_DECIMALS_PARAM]: '10',
|
||||
[TOKEN_LOGO_URL_PARAM]: 'https://example.com',
|
||||
}
|
||||
|
||||
const customAddTokensFn: any = (...args) => store.dispatch(addToken(...args))
|
||||
await addTokenFnc(values, customAddTokensFn, safeAddress)
|
||||
|
||||
const token = makeToken({
|
||||
address: secondErc20Token.address,
|
||||
name: 'Custom ERC20 Token',
|
||||
symbol: 'CTS',
|
||||
decimals: 10,
|
||||
logoUrl: 'https://example.com',
|
||||
status: true,
|
||||
removable: true,
|
||||
})
|
||||
const customRemoveTokensFnc: any = (...args) => store.dispatch(removeTokenAction(...args))
|
||||
await removeToken(safeAddress, token, customRemoveTokensFnc)
|
||||
checkTokensOf(store, safeAddress)
|
||||
|
||||
// WHEN
|
||||
const reloadedStore = aNewStore()
|
||||
await reloadedStore.dispatch(fetchTokensModule.fetchTokens(safeAddress))
|
||||
travelToSafe(reloadedStore, safeAddress) // reload
|
||||
|
||||
// THEN
|
||||
checkTokensOf(reloadedStore, safeAddress)
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue