add tests for enabling/disabling tokens, fix sending funds test

This commit is contained in:
Mikhail Mikheev 2019-06-05 17:45:05 +04:00
parent ca81ff73fa
commit 96da5f8e85
5 changed files with 41 additions and 21 deletions

View File

@ -14,6 +14,8 @@ import { type Token } from '~/logic/tokens/store/model/token'
import actions, { type Actions } from './actions'
import { styles } from './style'
export const MANAGE_TOKENS_MODAL_CLOSE_BUTTON_TEST_ID = 'manage-tokens-close-modal-btn'
type Props = Actions & {
onClose: () => void,
classes: Object,
@ -43,7 +45,7 @@ const Tokens = (props: Props) => {
<Paragraph className={classes.manage} noMargin>
Manage Tokens
</Paragraph>
<IconButton onClick={onClose} disableRipple>
<IconButton onClick={onClose} disableRipple data-testid={MANAGE_TOKENS_MODAL_CLOSE_BUTTON_TEST_ID}>
<Close className={classes.close} />
</IconButton>
</Row>

View File

@ -72,6 +72,7 @@ export const aMinedSafe = async (
store: Store<GlobalState>,
owners: number = 1,
threshold: number = 1,
startAccountPosition: number = 0,
): Promise<string> => {
const provider = await getProviderInfo()
const walletRecord = makeProvider(provider)
@ -84,7 +85,7 @@ export const aMinedSafe = async (
[FIELD_OWNERS]: `${owners}`,
}
for (let i = 0; i < owners; i += 1) {
for (let i = startAccountPosition; i < owners; i += 1) {
form[getOwnerNameBy(i)] = `Adol ${i + 1} Eth Account`
form[getOwnerAddressBy(i)] = accounts[i]
}

View File

@ -23,7 +23,8 @@ describe('DOM > Feature > Funds', () => {
let accounts
beforeEach(async () => {
store = aNewStore()
safeAddress = await aMinedSafe(store)
// using 4th account because other accounts were used in other tests and paid gas
safeAddress = await aMinedSafe(store, 1, 1, 4)
accounts = await getWeb3().eth.getAccounts()
})

View File

@ -1,24 +1,23 @@
// @flow
import { List } from 'immutable'
import { getWeb3 } from '~/logic/wallets/getWeb3'
import Checkbox from '@material-ui/core/Checkbox'
import { getFirstTokenContract, getSecondTokenContract } from '~/test/utils/tokenMovements'
import { aNewStore } from '~/store'
import { aMinedSafe } from '~/test/builder/safe.redux.builder'
import { renderSafeView } from '~/test/builder/safe.dom.utils'
import { sleep } from '~/utils/timer'
import { testToken } from '~/test/builder/tokens.dom.utils'
import saveTokens from '~/logic/tokens/store/actions/saveTokens'
import { clickOnManageTokens, toggleToken } from './utils/DOMNavigation'
import { clickOnManageTokens, toggleToken, closeManageTokensModal } from './utils/DOMNavigation'
import { BALANCE_ROW_TEST_ID } from '~/routes/safe/components/Balances'
import { makeToken } from '~/logic/tokens/store/model/token'
import 'jest-dom/extend-expect'
describe('DOM > Feature > Enable and disable default tokens', () => {
let web3
let accounts
let firstErc20Token
let secondErc20Token
let tokens
let testTokens
beforeAll(async () => {
web3 = getWeb3()
@ -26,7 +25,7 @@ describe('DOM > Feature > Enable and disable default tokens', () => {
firstErc20Token = await getFirstTokenContract(web3, accounts[0])
secondErc20Token = await getSecondTokenContract(web3, accounts[0])
tokens = List([
testTokens = List([
makeToken({
address: firstErc20Token.address,
name: 'First Token Example',
@ -48,30 +47,38 @@ describe('DOM > Feature > Enable and disable default tokens', () => {
// GIVEN
const store = aNewStore()
const safeAddress = await aMinedSafe(store)
await store.dispatch(saveTokens(tokens))
await store.dispatch(saveTokens(testTokens))
// WHEN
const TokensDom = await renderSafeView(store, safeAddress)
await sleep(400)
// Check if only ETH is enabled
TokensDom.getAllByTestId(BALANCE_ROW_TEST_ID)
console.log(store.getState().tokens.toJS())
let balanceRows = TokensDom.getAllByTestId(BALANCE_ROW_TEST_ID)
expect(balanceRows.length).toBe(1)
// THEN
clickOnManageTokens(TokensDom)
toggleToken(TokensDom, 'FTE', firstErc20Token.address)
toggleToken(TokensDom, 'STE', secondErc20Token.address)
toggleToken(TokensDom, 'FTE')
toggleToken(TokensDom, 'STE')
closeManageTokensModal(TokensDom)
const tokens = TestUtils.scryRenderedComponentsWithType(TokensDom, TokenComponent)
expect(tokens.length).toBe(3)
// Check if tokens were enabled
balanceRows = TokensDom.getAllByTestId(BALANCE_ROW_TEST_ID)
expect(balanceRows.length).toBe(3)
expect(balanceRows[1]).toHaveTextContent('FTE')
expect(balanceRows[2]).toHaveTextContent('STE')
testToken(tokens[0].props.token, 'FTE', false)
testToken(tokens[1].props.token, 'STE', false)
testToken(tokens[2].props.token, 'ETH', true)
// disable tokens
clickOnManageTokens(TokensDom)
toggleToken(TokensDom, 'FTE')
toggleToken(TokensDom, 'STE')
closeManageTokensModal(TokensDom)
// check if tokens were disabled
balanceRows = TokensDom.getAllByTestId(BALANCE_ROW_TEST_ID)
expect(balanceRows.length).toBe(1)
expect(balanceRows[0]).toHaveTextContent('ETH')
const ethCheckbox = TestUtils.findRenderedComponentWithType(tokens[2], Checkbox)
if (!ethCheckbox) throw new Error()
expect(ethCheckbox.props.disabled).toBe(true)
})
})

View File

@ -2,6 +2,7 @@
import { fireEvent } from '@testing-library/react'
import { MANAGE_TOKENS_BUTTON_TEST_ID } from '~/routes/safe/components/Balances'
import { ADD_CUSTOM_TOKEN_BUTTON_TEST_ID, TOGGLE_TOKEN_TEST_ID } from '~/routes/safe/components/Balances/Tokens/screens/TokenList'
import { MANAGE_TOKENS_MODAL_CLOSE_BUTTON_TEST_ID } from '~/routes/safe/components/Balances/Tokens'
export const clickOnManageTokens = (dom: any): void => {
const btn = dom.getByTestId(MANAGE_TOKENS_BUTTON_TEST_ID)
@ -17,4 +18,12 @@ export const clickOnAddCustomToken = (dom: any): void => {
export const toggleToken = (dom: any, symbol: string): void => {
const btn = dom.getByTestId(`${symbol}_${TOGGLE_TOKEN_TEST_ID}`)
fireEvent.click(btn)
}
export const closeManageTokensModal = (dom: any) => {
const btn = dom.getByTestId(MANAGE_TOKENS_MODAL_CLOSE_BUTTON_TEST_ID)
fireEvent.click(btn)
}