WA-232 Created safeHelper test class for fetching safe from store

This commit is contained in:
apanizo 2018-07-05 16:01:50 +02:00
parent 4a4701c444
commit 6467a1a0d6
4 changed files with 60 additions and 50 deletions

View File

@ -34,43 +34,47 @@ export const MOVE_FUNDS_BUTTON_TEXT = 'Move'
const BalanceComponent = openHoc(({ const BalanceComponent = openHoc(({
open, toggle, balances, classes, onMoveFunds, open, toggle, balances, classes, onMoveFunds,
}: Props) => ( }: Props) => {
<React.Fragment> const hasBalances = balances.count() > 0
<ListItem onClick={toggle}>
<Avatar>
<AccountBalance />
</Avatar>
<ListItemText primary="Balance" secondary="List of different token balances" />
<ListItemIcon>
{open
? <IconButton disableRipple><ExpandLess /></IconButton>
: <IconButton disabled={balances.count() === 0} disableRipple><ExpandMore /></IconButton>
}
</ListItemIcon>
</ListItem>
<Collapse in={open} timeout="auto">
<List component="div" disablePadding>
{balances.valueSeq().map((balance: Balance) => {
const symbol = balance.get('symbol')
const name = balance.get('name')
const disabled = Number(balance.get('funds')) === 0
const onMoveFundsClick = () => onMoveFunds(balance)
return ( return (
<ListItem key={symbol} className={classNames(classes.nested, symbol)}> <React.Fragment>
<ListItemIcon> <ListItem onClick={hasBalances ? toggle : undefined}>
<Img src={balance.get('logoUrl')} height={30} alt={name} /> <Avatar>
</ListItemIcon> <AccountBalance />
<ListItemText primary={name} secondary={`${balance.get('funds')} ${symbol}`} /> </Avatar>
<Button variant="raised" color="primary" onClick={onMoveFundsClick} disabled={disabled}> <ListItemText primary="Balance" secondary="List of different token balances" />
{MOVE_FUNDS_BUTTON_TEXT} <ListItemIcon>
</Button> {open
</ListItem> ? <IconButton disableRipple><ExpandLess /></IconButton>
) : <IconButton disabled={!hasBalances} disableRipple><ExpandMore /></IconButton>
})} }
</List> </ListItemIcon>
</Collapse> </ListItem>
</React.Fragment> <Collapse in={open} timeout="auto">
)) <List component="div" disablePadding>
{balances.valueSeq().map((balance: Balance) => {
const symbol = balance.get('symbol')
const name = balance.get('name')
const disabled = Number(balance.get('funds')) === 0
const onMoveFundsClick = () => onMoveFunds(balance)
return (
<ListItem key={symbol} className={classNames(classes.nested, symbol)}>
<ListItemIcon>
<Img src={balance.get('logoUrl')} height={30} alt={name} />
</ListItemIcon>
<ListItemText primary={name} secondary={`${balance.get('funds')} ${symbol}`} />
<Button variant="raised" color="primary" onClick={onMoveFundsClick} disabled={disabled}>
{MOVE_FUNDS_BUTTON_TEXT}
</Button>
</ListItem>
)
})}
</List>
</Collapse>
</React.Fragment>
)
})
export default withStyles(styles)(BalanceComponent) export default withStyles(styles)(BalanceComponent)

View File

@ -11,6 +11,8 @@ type Props = Actions & SelectorProps & {
granted: boolean, granted: boolean,
} }
const TIMEOUT = process.env.NODE_ENV === 'test' ? 1500 : 15000
class SafeView extends React.PureComponent<Props> { class SafeView extends React.PureComponent<Props> {
componentDidMount() { componentDidMount() {
this.intervalId = setInterval(() => { this.intervalId = setInterval(() => {
@ -21,7 +23,7 @@ class SafeView extends React.PureComponent<Props> {
const safeAddress = safe.get('address') const safeAddress = safe.get('address')
fetchBalances(safeAddress) fetchBalances(safeAddress)
fetchSafe(safe) fetchSafe(safe)
}, 15000) }, TIMEOUT)
} }
componentDidUpdate(prevProps) { componentDidUpdate(prevProps) {

View File

@ -1,14 +1,11 @@
// @flow // @flow
import { aNewStore } from '~/store' import { aNewStore } from '~/store'
import { getWeb3 } from '~/wallets/getWeb3' import { getWeb3 } from '~/wallets/getWeb3'
import { type Match } from 'react-router-dom'
import { promisify } from '~/utils/promisify' import { promisify } from '~/utils/promisify'
import { processTransaction } from '~/routes/safe/component/Transactions/processTransactions' import { processTransaction } from '~/routes/safe/component/Transactions/processTransactions'
import { confirmationsTransactionSelector, safeSelector } from '~/routes/safe/store/selectors/index' import { confirmationsTransactionSelector } from '~/routes/safe/store/selectors/index'
import { getTransactionFromReduxStore } from '~/routes/safe/test/testMultisig' import { getTransactionFromReduxStore } from '~/routes/safe/test/testMultisig'
import { buildMathPropsFrom } from '~/test/utils/buildReactRouterProps'
import fetchTransactions from '~/routes/safe/store/actions/fetchTransactions' import fetchTransactions from '~/routes/safe/store/actions/fetchTransactions'
import { type GlobalState } from '~/store/index'
import { type Safe } from '~/routes/safe/store/model/safe' import { type Safe } from '~/routes/safe/store/model/safe'
import { getGnosisSafeInstanceAt } from '~/wallets/safeContracts' import { getGnosisSafeInstanceAt } from '~/wallets/safeContracts'
import { aMinedSafe } from '~/test/builder/safe.redux.builder' import { aMinedSafe } from '~/test/builder/safe.redux.builder'
@ -17,14 +14,7 @@ import { addOwner } from '~/routes/safe/component/AddOwner/index'
import fetchSafe from '~/routes/safe/store/actions/fetchSafe' import fetchSafe from '~/routes/safe/store/actions/fetchSafe'
import { removeOwner, shouldDecrease, initialValuesFrom } from '~/routes/safe/component/RemoveOwner' import { removeOwner, shouldDecrease, initialValuesFrom } from '~/routes/safe/component/RemoveOwner'
import { DECREASE_PARAM } from '~/routes/safe/component/RemoveOwner/RemoveOwnerForm/index' import { DECREASE_PARAM } from '~/routes/safe/component/RemoveOwner/RemoveOwnerForm/index'
import { getSafeFrom } from '~/test/utils/safeHelper'
const getSafeFrom = (state: GlobalState, safeAddress: string): Safe => {
const match: Match = buildMathPropsFrom(safeAddress)
const safe = safeSelector(state, { match })
if (!safe) throw new Error()
return safe
}
describe('React DOM TESTS > Add and remove owners', () => { describe('React DOM TESTS > Add and remove owners', () => {
const processOwnerModification = async (store, safeAddress, executor) => { const processOwnerModification = async (store, safeAddress, executor) => {

View File

@ -0,0 +1,14 @@
// @flow
import { buildMathPropsFrom } from '~/test/utils/buildReactRouterProps'
import { safeSelector } from '~/routes/safe/store/selectors/index'
import { type Match } from 'react-router-dom'
import { type GlobalState } from '~/store'
import { type Safe } from '~/routes/safe/store/model/safe'
export const getSafeFrom = (state: GlobalState, safeAddress: string): Safe => {
const match: Match = buildMathPropsFrom(safeAddress)
const safe = safeSelector(state, { match })
if (!safe) throw new Error()
return safe
}