Merge pull request #174 from gnosis/test/token-balance-updates

Test: Token balance updates
This commit is contained in:
Mikhail Mikheev 2019-09-18 14:02:37 +04:00 committed by GitHub
commit 910bd5c9a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 74 additions and 1 deletions

View File

@ -0,0 +1,73 @@
// @flow
import { waitForElement } from '@testing-library/react'
import { List } from 'immutable'
import { aNewStore } from '~/store'
import { sleep } from '~/utils/timer'
import { aMinedSafe } from '~/test/builder/safe.redux.builder'
import { sendTokenTo, sendEtherTo } from '~/test/utils/tokenMovements'
import { renderSafeView } from '~/test/builder/safe.dom.utils'
import { dispatchAddTokenToList } from '~/test/utils/transactions/moveTokens.helper'
import TokenBalanceRecord from '~/routes/safe/store/models/tokenBalance'
import { calculateBalanceOf } from '~/routes/safe/store/actions/fetchTokenBalances'
import updateActiveTokens from '~/routes/safe/store/actions/updateActiveTokens'
import '@testing-library/jest-dom/extend-expect'
import updateSafe from '~/routes/safe/store/actions/updateSafe'
import { BALANCE_ROW_TEST_ID } from '~/routes/safe/components/Balances'
import { getBalanceInEtherOf } from '~/logic/wallets/getWeb3'
describe('DOM > Feature > Balances', () => {
let store
let safeAddress: string
beforeEach(async () => {
store = aNewStore()
safeAddress = await aMinedSafe(store)
})
it('Updates token balances automatically', async () => {
const tokensAmount = '100'
const tokenAddress = await sendTokenTo(safeAddress, tokensAmount)
await dispatchAddTokenToList(store, tokenAddress)
const SafeDom = await renderSafeView(store, safeAddress)
// Activate token
const safeTokenBalance = await calculateBalanceOf(tokenAddress, safeAddress, 18)
expect(safeTokenBalance).toBe(tokensAmount)
const balanceAsRecord = TokenBalanceRecord({
address: tokenAddress,
balance: safeTokenBalance,
})
store.dispatch(updateActiveTokens(safeAddress, List([tokenAddress])))
store.dispatch(updateSafe({ address: safeAddress, balances: List([balanceAsRecord]) }))
await sleep(1000)
const balanceRows = SafeDom.getAllByTestId(BALANCE_ROW_TEST_ID)
expect(balanceRows.length).toBe(2)
await waitForElement(() => SafeDom.getByText(`${tokensAmount} OMG`))
await sendTokenTo(safeAddress, tokensAmount)
await waitForElement(() => SafeDom.getByText(`${parseInt(tokensAmount, 10) * 2} OMG`))
})
it('Updates ether balance automatically', async () => {
const etherAmount = '1'
await sendEtherTo(safeAddress, etherAmount)
const SafeDom = await renderSafeView(store, safeAddress)
const safeEthBalance = await getBalanceInEtherOf(safeAddress)
expect(safeEthBalance).toBe(etherAmount)
const balanceRows = SafeDom.getAllByTestId(BALANCE_ROW_TEST_ID)
expect(balanceRows.length).toBe(1)
await waitForElement(() => SafeDom.getByText(`${etherAmount} ETH`))
await sendEtherTo(safeAddress, etherAmount)
await waitForElement(() => SafeDom.getByText(`${parseInt(etherAmount, 10) * 2} ETH`))
})
})

View File

@ -24,7 +24,7 @@ export const getLastTransaction = async (SafeDom: React.Component<any, any>) =>
export const checkRegisteredTxSend = async ( export const checkRegisteredTxSend = async (
SafeDom: React.Component<any, any>, SafeDom: React.Component<any, any>,
ethAmount: number, ethAmount: number | string,
symbol: string, symbol: string,
ethAddress: string, ethAddress: string,
) => { ) => {