WA-234 Fix tests

This commit is contained in:
apanizo 2018-06-15 10:36:59 +02:00
parent b1eeab65e7
commit c0a0f96af0
7 changed files with 58 additions and 44 deletions

View File

@ -1,6 +1,6 @@
// @flow
import * as React from 'react'
import ListItemText from '@material-ui/core/ListItemText'
import MuiListItemText from '@material-ui/core/ListItemText'
import { withStyles } from '@material-ui/core/styles'
import { type WithStyles } from '~/theme/mui'
@ -18,21 +18,26 @@ const styles = {
},
}
const GnoListItemText = ({
primary, secondary, classes, cut = false,
}: Props) => {
const cutStyle = cut ? {
secondary: classes.itemTextSecondary,
} : undefined
class ListItemText extends React.PureComponent<Props> {
render() {
const {
primary, secondary, classes, cut = false,
} = this.props
return (
<ListItemText
classes={cutStyle}
inset
primary={primary}
secondary={secondary}
/>
)
const cutStyle = cut ? {
secondary: classes.itemTextSecondary,
} : undefined
return (
<MuiListItemText
classes={cutStyle}
inset
primary={primary}
secondary={secondary}
/>
)
}
}
export default withStyles(styles)(GnoListItemText)
export default withStyles(styles)(ListItemText)

View File

@ -111,16 +111,16 @@ export const createTransaction = async (
await gnosisSafe.execTransactionIfApproved(txDest, valueInWei, data, CALL, nonce, { from: user, gas, gasPrice })
await checkReceiptStatus(txHash.tx)
const executedConfirmations: List<Confirmation> = buildExecutedConfirmationFrom(safe.get('owners'), user)
return storeTransaction(txName, nonce, txDest, txValue, user, executedConfirmations, txHash, safeAddress, safe.get('threshold'), data)
return storeTransaction(txName, nonce, txDest, txValue, user, executedConfirmations, txHash.tx, safeAddress, safe.get('threshold'), data)
}
const txData = gnosisSafe.contract.approveTransactionWithParameters.getData(txDest, valueInWei, data, CALL, nonce)
const gas = await calculateGasOf(txData, user, safeAddress)
const txConfirmationHash = await gnosisSafe
.approveTransactionWithParameters(txDest, valueInWei, txData, CALL, nonce, { from: user, gas, gasPrice })
await checkReceiptStatus(txConfirmationHash)
.approveTransactionWithParameters(txDest, valueInWei, data, CALL, nonce, { from: user, gas, gasPrice })
await checkReceiptStatus(txConfirmationHash.tx)
const confirmations: List<Confirmation> = buildConfirmationsFrom(safe.get('owners'), user, txConfirmationHash)
const confirmations: List<Confirmation> = buildConfirmationsFrom(safe.get('owners'), user, txConfirmationHash.tx)
return storeTransaction(txName, nonce, txDest, txValue, user, confirmations, '', safeAddress, safe.get('threshold'), data)
}

View File

@ -50,12 +50,13 @@ const execTransaction = async (
const CALL = getOperation()
const web3 = getWeb3()
const valueInWei = web3.toWei(txValue, 'ether')
const txData = await gnosisSafe.contract.execTransactionIfApproved.getData(destination, valueInWei, data, CALL, nonce)
const gas = await calculateGasOf(txData, executor, gnosisSafe.address)
const gasPrice = await calculateGasPrice()
return gnosisSafe
.execTransactionIfApproved(destination, valueInWei, txData, CALL, nonce, { from: executor, gas, gasPrice })
.execTransactionIfApproved(destination, valueInWei, data, CALL, nonce, { from: executor, gas, gasPrice })
}
const execConfirmation = async (

View File

@ -75,6 +75,7 @@ describe('React DOM TESTS > Withdrawn funds from safe', () => {
const addTransactionButtons = TestUtils.scryRenderedComponentsWithType(AddTransaction, Button)
expect(addTransactionButtons.length).toBe(1)
const visitTxsButton = addTransactionButtons[0]
expect(visitTxsButton.props.children).toEqual(SEE_TXS_BUTTON_TEXT)
// NOW it is time to check the just executed transaction

View File

@ -8,7 +8,7 @@ import { aDeployedSafe } from '~/routes/safe/store/test/builder/deployedSafe.bui
import { SAFELIST_ADDRESS } from '~/routes/routes'
import AppRoutes from '~/routes'
import AddTransactionComponent from '~/routes/safe/component/AddTransaction'
import { createMultisigTxFilling, addFundsTo, checkBalanceOf, listTxsOf, getTagFromTransaction, expandTransactionOf, getTransactionFromReduxStore, confirmOwners } from '~/routes/safe/test/testMultisig'
import { createMultisigTxFilling, addFundsTo, checkBalanceOf, listTxsOf, getListItemsFrom, expandTransactionOf, getTransactionFromReduxStore, confirmOwners } from '~/routes/safe/test/testMultisig'
import { sleep } from '~/utils/timer'
const renderSafe = localStore => (
@ -46,17 +46,17 @@ describe('React DOM TESTS > Multisig transactions from safe [3 owners & 1 thresh
await expandTransactionOf(SafeDom, 3, 1)
await confirmOwners(SafeDom, 'Adolfo 1 Eth Account [Confirmed]', 'Adolfo 2 Eth Account [Not confirmed]', 'Adolfo 3 Eth Account [Not confirmed]')
const paragraphs = getTagFromTransaction(SafeDom, 'p')
const listItems = getListItemsFrom(SafeDom)
const status = paragraphs[2].innerHTML
const status = listItems[2].props.secondary
expect(status).toBe('Already executed')
const confirmed = paragraphs[3].innerHTML
const confirmed = listItems[3].props.secondary
const tx = getTransactionFromReduxStore(store, address)
if (!tx) throw new Error()
expect(confirmed).toBe(tx.get('tx'))
const ownerTx = paragraphs[6].innerHTML
const ownerTx = listItems[6].props.secondary
expect(ownerTx).toBe('Confirmation hash: EXECUTED')
})
})

View File

@ -14,7 +14,7 @@ import AddTransactionComponent from '~/routes/safe/component/AddTransaction'
import { processTransaction } from '~/routes/safe/component/Transactions/processTransactions'
import { confirmationsTransactionSelector } from '~/routes/safe/store/selectors/index'
import fetchTransactions from '~/routes/safe/store/actions/fetchTransactions'
import { createMultisigTxFilling, addFundsTo, checkBalanceOf, listTxsOf, getTagFromTransaction, expandTransactionOf, getTransactionFromReduxStore, confirmOwners } from '~/routes/safe/test/testMultisig'
import { createMultisigTxFilling, addFundsTo, checkBalanceOf, listTxsOf, getListItemsFrom, expandTransactionOf, getTransactionFromReduxStore, confirmOwners } from '~/routes/safe/test/testMultisig'
const renderSafe = localStore => (
TestUtils.renderIntoDocument((
@ -74,12 +74,12 @@ describe('React DOM TESTS > Multisig transactions from safe [3 owners & 3 thresh
await checkBalanceOf(address, '0.1')
await listTxsOf(SafeDom)
sleep(1400)
const paragraphs = getTagFromTransaction(SafeDom, 'p')
const listItems = getListItemsFrom(SafeDom)
const status = paragraphs[2].innerHTML
const status = listItems[2].props.secondary
expect(status).toBe('1 of the 3 confirmations needed')
const confirmed = paragraphs[3].innerHTML
const confirmed = listItems[3].props.secondary
expect(confirmed).toBe('Waiting for the rest of confirmations')
await expandTransactionOf(SafeDom, 3, 3)
@ -91,12 +91,12 @@ describe('React DOM TESTS > Multisig transactions from safe [3 owners & 3 thresh
await makeConfirmation(accounts[2])
await confirmOwners(SafeDom, 'Adolfo 1 Eth Account [Confirmed]', 'Adolfo 2 Eth Account [Confirmed]', 'Adolfo 3 Eth Account [Confirmed]')
const paragraphsExecuted = getTagFromTransaction(SafeDom, 'p')
const listItemsExecuted = getListItemsFrom(SafeDom)
const statusExecuted = paragraphsExecuted[2].innerHTML
const statusExecuted = listItemsExecuted[2].props.secondary
expect(statusExecuted).toBe('Already executed')
const confirmedExecuted = paragraphsExecuted[3].innerHTML
const confirmedExecuted = listItemsExecuted[3].props.secondary
const tx = getTransactionFromReduxStore(store, address)
if (!tx) throw new Error()
expect(confirmedExecuted).toBe(tx.get('tx'))

View File

@ -10,6 +10,7 @@ import TransactionsComponent from '~/routes/safe/component/Transactions'
import TransactionComponent from '~/routes/safe/component/Transactions/Transaction'
import { safeTransactionsSelector } from '~/routes/safe/store/selectors/index'
import { type GlobalState } from '~/store/index'
import ListItemText from '~/components/List/ListItemText'
export const createMultisigTxFilling = async (
SafeDom: React$Component<any, any>,
@ -64,13 +65,13 @@ export const listTxsOf = (SafeDom: React$Component<any, any>) => {
TestUtils.Simulate.click(TestUtils.scryRenderedDOMComponentsWithTag(seeTx, 'button')[0])
}
export const getTagFromTransaction = (SafeDom: React$Component<any, any>, tag: string) => {
export const getListItemsFrom = (SafeDom: React$Component<any, any>) => {
const Transactions = TestUtils.findRenderedComponentWithType(SafeDom, TransactionsComponent)
if (!Transactions) throw new Error()
const Transaction = TestUtils.findRenderedComponentWithType(Transactions, TransactionComponent)
if (!Transaction) throw new Error()
return TestUtils.scryRenderedDOMComponentsWithTag(Transaction, tag)
return TestUtils.scryRenderedComponentsWithType(Transaction, ListItemText)
}
export const expandTransactionOf = async (
@ -78,15 +79,15 @@ export const expandTransactionOf = async (
numOwners: number,
safeThreshold: number,
) => {
const paragraphs = getTagFromTransaction(SafeDom, 'p')
TestUtils.Simulate.click(paragraphs[2]) // expanded
const listItems = getListItemsFrom(SafeDom)
TestUtils.Simulate.click(TestUtils.scryRenderedDOMComponentsWithTag(listItems[2], 'p')[0]) // expanded
await sleep(2500) // Time to expand
const paragraphsExpanded = getTagFromTransaction(SafeDom, 'p')
const threshold = paragraphsExpanded[5]
expect(threshold.innerHTML).toContain(`confirmation${safeThreshold === 1 ? '' : 's'} needed`)
TestUtils.Simulate.click(threshold) // expanded
const listItemsExpanded = getListItemsFrom(SafeDom)
const threshold = listItemsExpanded[5]
expect(threshold.props.secondary).toContain(`confirmation${safeThreshold === 1 ? '' : 's'} needed`)
TestUtils.Simulate.click(TestUtils.scryRenderedDOMComponentsWithTag(threshold, 'p')[0]) // expanded
await sleep(2500) // Time to expand
expect(paragraphsExpanded.length).toBe(paragraphs.length + numOwners)
expect(listItemsExpanded.length).toBe(listItems.length + numOwners)
}
export const getTransactionFromReduxStore = (store: Store<GlobalState>, address: string, index: number = 0) => {
@ -96,10 +97,16 @@ export const getTransactionFromReduxStore = (store: Store<GlobalState>, address:
}
export const confirmOwners = async (SafeDom: React$Component<any, any>, ...statusses: string[]) => {
const paragraphsWithOwners = getTagFromTransaction(SafeDom, 'span')
const Transactions = TestUtils.findRenderedComponentWithType(SafeDom, TransactionsComponent)
if (!Transactions) throw new Error()
const Transaction = TestUtils.findRenderedComponentWithType(Transactions, TransactionComponent)
if (!Transaction) throw new Error()
const listItems = TestUtils.scryRenderedComponentsWithType(Transaction, ListItemText)
for (let i = 0; i < statusses.length; i += 1) {
const ownerIndex = i + 6
const ownerParagraph = paragraphsWithOwners[ownerIndex].innerHTML
const ownerParagraph = listItems[ownerIndex].props.primary
expect(statusses[i]).toEqual(ownerParagraph)
}