WA-232 Fixing tests

This commit is contained in:
apanizo 2018-07-19 11:04:04 +02:00
parent da6345b1cc
commit 69ef967481
7 changed files with 28 additions and 15 deletions

View File

@ -5,8 +5,8 @@ import { getHumanFriendlyToken } from '~/routes/tokens/store/actions/fetchTokens
import FirstPage, { TOKEN_ADDRESS_PARAM } from '~/routes/tokens/component/AddToken/FirstPage' import FirstPage, { TOKEN_ADDRESS_PARAM } from '~/routes/tokens/component/AddToken/FirstPage'
import SecondPage, { TOKEN_SYMBOL_PARAM, TOKEN_DECIMALS_PARAM, TOKEN_LOGO_URL_PARAM, TOKEN_NAME_PARAM } from '~/routes/tokens/component/AddToken/SecondPage' import SecondPage, { TOKEN_SYMBOL_PARAM, TOKEN_DECIMALS_PARAM, TOKEN_LOGO_URL_PARAM, TOKEN_NAME_PARAM } from '~/routes/tokens/component/AddToken/SecondPage'
import { makeToken, type Token } from '~/routes/tokens/store/model/token' import { makeToken, type Token } from '~/routes/tokens/store/model/token'
import addTokenAction from '~/routes/tokens/store/actions/addTokens' import addTokenAction from '~/routes/tokens/store/actions/addToken'
import enableTokenAction from '~/routes/tokens/store/actions/enabletoken' import enableTokenAction from '~/routes/tokens/store/actions/enableToken'
import Review from './Review' import Review from './Review'
export const getSteps = () => [ export const getSteps = () => [

View File

@ -8,7 +8,6 @@ const disableToken = createAction(
DISABLE_TOKEN, DISABLE_TOKEN,
(safeAddress: string, token: Token) => ({ (safeAddress: string, token: Token) => ({
safeAddress, safeAddress,
symbol: token.get('symbol'),
address: token.get('address'), address: token.get('address'),
}), }),
) )

View File

@ -8,7 +8,6 @@ const enableToken = createAction(
ENABLE_TOKEN, ENABLE_TOKEN,
(safeAddress: string, token: Token) => ({ (safeAddress: string, token: Token) => ({
safeAddress, safeAddress,
symbol: token.get('symbol'),
address: token.get('address'), address: token.get('address'),
}), }),
) )

View File

@ -40,20 +40,20 @@ export default handleActions({
return state.setIn([safeAddress, token.get('address')], token) return state.setIn([safeAddress, token.get('address')], token)
}, },
[DISABLE_TOKEN]: (state: State, action: ActionType<typeof disableToken>): State => { [DISABLE_TOKEN]: (state: State, action: ActionType<typeof disableToken>): State => {
const { address, safeAddress, symbol } = action.payload const { address, safeAddress } = action.payload
const activeTokens = getActiveTokenAddresses(safeAddress) const activeTokens = getActiveTokenAddresses(safeAddress)
const index = activeTokens.indexOf(address) const index = activeTokens.indexOf(address)
setActiveTokenAddresses(safeAddress, activeTokens.delete(index)) setActiveTokenAddresses(safeAddress, activeTokens.delete(index))
return state.setIn([safeAddress, symbol, 'status'], false) return state.setIn([safeAddress, address, 'status'], false)
}, },
[ENABLE_TOKEN]: (state: State, action: ActionType<typeof enableToken>): State => { [ENABLE_TOKEN]: (state: State, action: ActionType<typeof enableToken>): State => {
const { address, safeAddress, symbol } = action.payload const { address, safeAddress } = action.payload
const activeTokens = getActiveTokenAddresses(safeAddress) const activeTokens = getActiveTokenAddresses(safeAddress)
setActiveTokenAddresses(safeAddress, activeTokens.push(address)) setActiveTokenAddresses(safeAddress, activeTokens.push(address))
return state.setIn([safeAddress, symbol, 'status'], true) return state.setIn([safeAddress, address, 'status'], true)
}, },
}, Map()) }, Map())

View File

@ -7,6 +7,7 @@ import { type Token } from '~/routes/tokens/store/model/token'
import { TOKEN_REDUCER_ID } from '~/routes/tokens/store/reducer/tokens' import { TOKEN_REDUCER_ID } from '~/routes/tokens/store/reducer/tokens'
import { addEtherTo, addTknTo } from '~/test/utils/tokenMovements' import { addEtherTo, addTknTo } from '~/test/utils/tokenMovements'
import { dispatchTknBalance } from '~/test/utils/transactions/moveTokens.helper' import { dispatchTknBalance } from '~/test/utils/transactions/moveTokens.helper'
import { ETH_ADDRESS } from '~/utils/tokens'
describe('Safe - redux balance property', () => { describe('Safe - redux balance property', () => {
let store let store
@ -18,7 +19,16 @@ describe('Safe - redux balance property', () => {
it('reducer should return 0 to just deployed safe', async () => { it('reducer should return 0 to just deployed safe', async () => {
// GIVEN // GIVEN
const tokenList = ['WE', '<3', 'GNO', 'OMG', 'RDN'] const tokenList = [
'0x975be7f72cea31fd83d0cb2a197f9136f38696b7', // WE
'0xb3a4bc89d8517e0e2c9b66703d09d3029ffa1e6d', // <3
'0x5f92161588c6178130ede8cbdc181acec66a9731', // GNO
'0xb63d06025d580a94d59801f2513f5d309c079559', // OMG
'0x3615757011112560521536258c1E7325Ae3b48AE', // RDN
'0xc778417E063141139Fce010982780140Aa0cD5Ab', // Wrapped Ether
'0x979861dF79C7408553aAF20c01Cfb3f81CCf9341', // OLY
'0', // ETH
]
// WHEN // WHEN
await store.dispatch(fetchTokensAction.fetchTokens(address)) await store.dispatch(fetchTokensAction.fetchTokens(address))
@ -29,7 +39,7 @@ describe('Safe - redux balance property', () => {
const safeBalances: Map<string, Token> | typeof undefined = tokens.get(address) const safeBalances: Map<string, Token> | typeof undefined = tokens.get(address)
if (!safeBalances) throw new Error() if (!safeBalances) throw new Error()
expect(safeBalances.size).toBe(6) expect(safeBalances.size).toBe(8)
tokenList.forEach((token: string) => { tokenList.forEach((token: string) => {
const record = safeBalances.get(token) const record = safeBalances.get(token)
@ -49,9 +59,9 @@ describe('Safe - redux balance property', () => {
const safeBalances: Map<string, Token> | typeof undefined = tokens.get(address) const safeBalances: Map<string, Token> | typeof undefined = tokens.get(address)
if (!safeBalances) throw new Error() if (!safeBalances) throw new Error()
expect(safeBalances.size).toBe(6) expect(safeBalances.size).toBe(8)
const ethBalance = safeBalances.get('ETH') const ethBalance = safeBalances.get(ETH_ADDRESS)
if (!ethBalance) throw new Error() if (!ethBalance) throw new Error()
expect(ethBalance.get('funds')).toBe('0.03456') expect(ethBalance.get('funds')).toBe('0.03456')
}) })

View File

@ -79,12 +79,16 @@ describe('DOM > Feature > Enable and disable default tokens', () => {
await addTknTo(safeAddress, 50, firstErc20Token) await addTknTo(safeAddress, 50, firstErc20Token)
await addTknTo(safeAddress, 50, secondErc20Token) await addTknTo(safeAddress, 50, secondErc20Token)
await store.dispatch(fetchTokensModule.fetchTokens(safeAddress)) await store.dispatch(fetchTokensModule.fetchTokens(safeAddress))
const match: Match = buildMathPropsFrom(safeAddress)
let tokenList = tokenListSelector(store.getState(), { match })
expect(tokenList.count()).toBe(3)
await enableFirstToken(store, safeAddress) await enableFirstToken(store, safeAddress)
tokenList = tokenListSelector(store.getState(), { match })
expect(tokenList.count()).toBe(3) // assuring the enableToken do not add extra info
// THEN // THEN
const match: Match = buildMathPropsFrom(safeAddress)
const tokenList = tokenListSelector(store.getState(), { match })
testToken(tokenList.get(0), 'FTE', true) testToken(tokenList.get(0), 'FTE', true)
testToken(tokenList.get(1), 'STE', false) testToken(tokenList.get(1), 'STE', false)
testToken(tokenList.get(2), 'ETH', true) testToken(tokenList.get(2), 'ETH', true)

View File

@ -4,6 +4,7 @@ import logo from '~/assets/icons/icon_etherTokens.svg'
import { getBalanceInEtherOf } from '~/wallets/getWeb3' import { getBalanceInEtherOf } from '~/wallets/getWeb3'
import { makeToken, type Token } from '~/routes/tokens/store/model/token' import { makeToken, type Token } from '~/routes/tokens/store/model/token'
export const ETH_ADDRESS = '0'
export const isEther = (symbol: string) => symbol === 'ETH' export const isEther = (symbol: string) => symbol === 'ETH'
export const getSafeEthToken = async (safeAddress: string) => { export const getSafeEthToken = async (safeAddress: string) => {