diff --git a/src/routes/safe/test/testMultisig.js b/src/routes/safe/test/testMultisig.js new file mode 100644 index 00000000..0278af92 --- /dev/null +++ b/src/routes/safe/test/testMultisig.js @@ -0,0 +1,80 @@ +// @flow +import TestUtils from 'react-dom/test-utils' +import { sleep } from '~/utils/timer' +import { getBalanceInEtherOf } from '~/wallets/getWeb3' +import Button from '~/components/layout/Button' +import { ADD_MULTISIG_BUTTON_TEXT, SEE_MULTISIG_BUTTON_TEXT } from '~/routes/safe/component/Safe/MultisigTx' +import { addEtherTo } from '~/test/addEtherTo' +import SafeView from '~/routes/safe/component/Safe' +import TransactionsComponent from '~/routes/safe/component/Transactions' +import TransactionComponent from '~/routes/safe/component/Transactions/Transaction' + +export const createMultisigTxFilling = async (SafeDom, AddTransactionComponent, store) => { + // Get AddTransaction form component + const AddTransaction = TestUtils.findRenderedComponentWithType(SafeDom, AddTransactionComponent) + + // $FlowFixMe + const inputs = TestUtils.scryRenderedDOMComponentsWithTag(AddTransaction, 'input') + const name = inputs[0] + const destination = inputs[1] + const amountInEth = inputs[2] + TestUtils.Simulate.change(name, { target: { value: 'Buying betteries' } }) + TestUtils.Simulate.change(amountInEth, { target: { value: '0.01' } }) + TestUtils.Simulate.change(destination, { target: { value: store.getState().providers.account } }) + + // $FlowFixMe + const form = TestUtils.findRenderedDOMComponentWithTag(AddTransaction, 'form') + + TestUtils.Simulate.submit(form) // fill the form + TestUtils.Simulate.submit(form) // confirming data + return sleep(4000) +} + +export const checkBalanceOf = async (addressToTest: string, value: string) => { + const safeBalance = await getBalanceInEtherOf(addressToTest) + expect(safeBalance).toBe(value) +} + +export const addFundsTo = async (SafeDom, destination: string) => { + // add funds to safe + await addEtherTo(destination, '0.1') + const Safe = TestUtils.findRenderedComponentWithType(SafeDom, SafeView) + + // $FlowFixMe + const buttons = TestUtils.scryRenderedComponentsWithType(Safe, Button) + const addTxButton = buttons[1] + expect(addTxButton.props.children).toEqual(ADD_MULTISIG_BUTTON_TEXT) + await sleep(1800) // Give time to enable Add button + TestUtils.Simulate.click(TestUtils.scryRenderedDOMComponentsWithTag(addTxButton, 'button')[0]) +} + +export const listTxsOf = (SafeDom) => { + const Safe = TestUtils.findRenderedComponentWithType(SafeDom, SafeView) + + // $FlowFixMe + const buttons = TestUtils.scryRenderedComponentsWithType(Safe, Button) + const seeTx = buttons[2] + expect(seeTx.props.children).toEqual(SEE_MULTISIG_BUTTON_TEXT) + TestUtils.Simulate.click(TestUtils.scryRenderedDOMComponentsWithTag(seeTx, 'button')[0]) +} + +export const getTagFromTransaction = (SafeDom, tag: string) => { + 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) +} + +export const expandTransactionOf = async (SafeDom, numOwners) => { + const paragraphs = getTagFromTransaction(SafeDom, 'p') + TestUtils.Simulate.click(paragraphs[2]) // expanded + await sleep(1000) // Time to expand + const paragraphsExpanded = getTagFromTransaction(SafeDom, 'p') + const threshold = paragraphsExpanded[5] + expect(threshold.innerHTML).toContain(`confirmation${numOwners === 1 ? 's' : ''} needed`) + TestUtils.Simulate.click(threshold) // expanded + await sleep(1000) // Time to expand + expect(paragraphsExpanded.length).toBe(paragraphs.length + numOwners) +}