WA-232 Refactor code avoiding DRY

This commit is contained in:
apanizo 2018-07-02 12:22:07 +02:00
parent 624b39717f
commit 1cdbf2b2f7
4 changed files with 27 additions and 33 deletions

View File

@ -1,18 +1,14 @@
// @flow
import * as React from 'react'
import { type Store } from 'redux'
import TestUtils from 'react-dom/test-utils'
import { Provider } from 'react-redux'
import { ConnectedRouter } from 'react-router-redux'
import SafeView from '~/routes/safe/component/Safe'
import { aNewStore, history, type GlobalState } from '~/store'
import { aNewStore, type GlobalState } from '~/store'
import { sleep } from '~/utils/timer'
import { getWeb3 } from '~/wallets/getWeb3'
import AppRoutes from '~/routes'
import { SAFELIST_ADDRESS } from '~/routes/routes'
import { promisify } from '~/utils/promisify'
import { addEtherTo } from '~/test/utils/tokenMovements'
import { aMinedSafe } from '~/test/builder/safe.redux.builder'
import { travelToSafe } from '~/test/builder/safe.dom.utils'
export type DomSafe = {
address: string,
@ -34,14 +30,7 @@ export const renderSafeInDom = async (
// have available accounts
const accounts = await promisify(cb => getWeb3().eth.getAccounts(cb))
// navigate to SAFE route
history.push(`${SAFELIST_ADDRESS}/${address}`)
const SafeDom = TestUtils.renderIntoDocument((
<Provider store={store}>
<ConnectedRouter history={history}>
<AppRoutes />
</ConnectedRouter>
</Provider>
))
const SafeDom = travelToSafe(store, address)
// add funds to safe
await addEtherTo(address, '0.1')

View File

@ -1,10 +1,15 @@
// @flow
import * as React from 'react'
import TestUtils from 'react-dom/test-utils'
import ListItemText from '~/components/List/ListItemText/index'
import { SEE_MULTISIG_BUTTON_TEXT } from '~/routes/safe/component/Safe/MultisigTx'
import fetchTransactions from '~/routes/safe/store/actions/fetchTransactions'
import { sleep } from '~/utils/timer'
import { type GlobalState } from '~/store/index'
import { Provider } from 'react-redux'
import { ConnectedRouter } from 'react-router-redux'
import AppRoutes from '~/routes'
import { SAFELIST_ADDRESS } from '~/routes/routes'
import { history, type GlobalState } from '~/store'
export const EXPAND_BALANCE_INDEX = 0
export const EXPAND_OWNERS_INDEX = 1
@ -85,3 +90,16 @@ export const refreshTransactions = async (store: Store<GlobalState>) => {
await store.dispatch(fetchTransactions())
await sleep(1500)
}
export const travelToSafe = (store: Store, address: string): React$Component<{}> => {
history.push(`${SAFELIST_ADDRESS}/${address}`)
const SafeDom = TestUtils.renderIntoDocument((
<Provider store={store}>
<ConnectedRouter history={history}>
<AppRoutes />
</ConnectedRouter>
</Provider>
))
return SafeDom
}

View File

@ -11,7 +11,7 @@ import { sendWithdrawForm, checkMinedWithdrawTx } from '~/test/utils/transaction
import { processTransaction } from '~/routes/safe/component/Transactions/processTransactions'
import { checkBalanceOf } from '~/test/utils/tokenMovements'
describe('DOM > Feature > SAFE MULTISIG TX 1 Owner 1 Threshold', () => {
describe('DOM > Feature > SAFE MULTISIG Transactions', () => {
let domSafe: DomSafe
it('mines correctly all multisig txs in a 1 owner & 1 threshold safe', async () => {
// GIVEN one safe with 1 owner and 1 threshold

View File

@ -4,11 +4,11 @@ import { BALANCE_REDUCER_ID } from '~/routes/safe/store/reducer/balances'
import * as fetchBalancesAction from '~/routes/safe/store/actions/fetchBalances'
import { aNewStore } from '~/store'
import { aMinedSafe } from '~/test/builder/safe.redux.builder'
import { type Balance, makeBalance } from '~/routes/safe/store/model/balance'
import addBalances from '~/routes/safe/store/actions/addBalances'
import { type Balance } from '~/routes/safe/store/model/balance'
import { addEtherTo, addTknTo } from '~/test/utils/tokenMovements'
import { dispatchTknBalance } from '~/test/utils/transactions/moveTokens.helper'
describe('Safe Actions[fetchBalance]', () => {
describe('Safe - redux balance property', () => {
let store
let address: string
beforeEach(async () => {
@ -62,20 +62,7 @@ describe('Safe Actions[fetchBalance]', () => {
const tokenAddress = await addTknTo(address, numTokens)
// WHEN
const fetchBalancesMock = jest.spyOn(fetchBalancesAction, 'fetchBalances')
const funds = await fetchBalancesAction.calculateBalanceOf(tokenAddress, address)
const balances: Map<string, Balance> = Map().set('TKN', makeBalance({
address: tokenAddress,
name: 'Token',
symbol: 'TKN',
decimals: 18,
logoUrl: 'https://github.com/TrustWallet/tokens/blob/master/images/0x6810e776880c02933d47db1b9fc05908e5386b96.png?raw=true',
funds,
}))
fetchBalancesMock.mockImplementation(() => store.dispatch(addBalances(address, balances)))
await store.dispatch(fetchBalancesAction.fetchBalances(address))
fetchBalancesMock.mockRestore()
await dispatchTknBalance(store, tokenAddress, address)
// THEN
const safeBalances = store.getState()[BALANCE_REDUCER_ID].get(address)