add fillAndSUbmitSendFunds form util function for tests
This commit is contained in:
parent
36aff894d5
commit
556b085745
|
@ -42,7 +42,7 @@ To run the test, you'll need to migrate contracts `safe-contracts` to the local
|
|||
git clone https://github.com/gnosis/safe-contracts.git
|
||||
cd safe-contracts
|
||||
yarn
|
||||
ganache-cli -l 7000000
|
||||
ganache-cli -l 7000000 -d
|
||||
npx truffle migrate
|
||||
```
|
||||
2. Migrate Token Contracts for the tests:
|
||||
|
|
|
@ -14,10 +14,11 @@ 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 { fillAndSubmitSendFundsForm } from './utils/transactions'
|
||||
|
||||
afterEach(cleanup)
|
||||
|
||||
describe('DOM > Feature > Funds', () => {
|
||||
describe('DOM > Feature > Sending Funds', () => {
|
||||
let store
|
||||
let safeAddress: string
|
||||
let accounts
|
||||
|
@ -44,19 +45,7 @@ describe('DOM > Feature > Funds', () => {
|
|||
const sendButton = SafeDom.getByTestId('balance-send-btn')
|
||||
fireEvent.click(sendButton)
|
||||
|
||||
// Fill first send funds screen
|
||||
const recipientInput = SafeDom.getByPlaceholderText('Recipient*')
|
||||
const amountInput = SafeDom.getByPlaceholderText('Amount*')
|
||||
const reviewBtn = SafeDom.getByTestId('review-tx-btn')
|
||||
fireEvent.change(recipientInput, { target: { value: accounts[0] } })
|
||||
fireEvent.change(amountInput, { target: { value: ethAmount } })
|
||||
await sleep(200)
|
||||
fireEvent.click(reviewBtn)
|
||||
|
||||
// Submit the tx (Review Tx screen)
|
||||
const submitBtn = SafeDom.getByTestId('submit-tx-btn')
|
||||
fireEvent.click(submitBtn)
|
||||
await sleep(1000)
|
||||
await fillAndSubmitSendFundsForm(SafeDom, sendButton, ethAmount, accounts[0])
|
||||
|
||||
// THEN
|
||||
const safeFunds = await getBalanceInEtherOf(safeAddress)
|
||||
|
@ -97,21 +86,8 @@ describe('DOM > Feature > Funds', () => {
|
|||
expect(balanceRows.length).toBe(2)
|
||||
const sendButtons = SafeDom.getAllByTestId('balance-send-btn')
|
||||
expect(sendButtons.length).toBe(2)
|
||||
fireEvent.click(sendButtons[1])
|
||||
|
||||
// Fill first send funds screen
|
||||
const recipientInput = SafeDom.getByPlaceholderText('Recipient*')
|
||||
const amountInput = SafeDom.getByPlaceholderText('Amount*')
|
||||
const reviewBtn = SafeDom.getByTestId('review-tx-btn')
|
||||
fireEvent.change(recipientInput, { target: { value: tokenReceiver } })
|
||||
fireEvent.change(amountInput, { target: { value: tokensAmount } })
|
||||
await sleep(200)
|
||||
fireEvent.click(reviewBtn)
|
||||
|
||||
// Submit the tx (Review Tx screen)
|
||||
const submitBtn = SafeDom.getByTestId('submit-tx-btn')
|
||||
fireEvent.click(submitBtn)
|
||||
await sleep(1000)
|
||||
await fillAndSubmitSendFundsForm(SafeDom, sendButtons[1], tokensAmount, tokenReceiver)
|
||||
|
||||
// THEN
|
||||
const safeFunds = await calculateBalanceOf(tokenAddress, safeAddress, 18)
|
|
@ -0,0 +1,4 @@
|
|||
// @flow
|
||||
export * from './moveFunds.helper'
|
||||
export * from './moveTokens.helper'
|
||||
export * from './threshold.helper'
|
|
@ -1,52 +1,30 @@
|
|||
// @flow
|
||||
import TestUtils from 'react-dom/test-utils'
|
||||
import * as React from 'react'
|
||||
import { fireEvent } from '@testing-library/react'
|
||||
import { sleep } from '~/utils/timer'
|
||||
import { checkMinedTx, checkPendingTx } from '~/test/builder/safe.dom.utils'
|
||||
import SendToken from '~/routes/safe/components/SendToken'
|
||||
import { whenExecuted } from '~/test/utils/logTransactions'
|
||||
|
||||
export const sendMoveFundsForm = async (
|
||||
SafeDom: React.Component<any, any>,
|
||||
expandBalance: React.Component<any, any>,
|
||||
export const fillAndSubmitSendFundsForm = async (
|
||||
SafeDom: any,
|
||||
sendButton: React.Component<any, any>,
|
||||
value: string,
|
||||
destination: string,
|
||||
recipient: string,
|
||||
) => {
|
||||
// load add multisig form component
|
||||
TestUtils.Simulate.click(expandBalance)
|
||||
fireEvent.click(sendButton)
|
||||
// give time to re-render it
|
||||
await sleep(400)
|
||||
|
||||
const ethList = TestUtils.findRenderedDOMComponentWithClass(SafeDom, 'ETH')
|
||||
if (!ethList) throw new Error()
|
||||
const ethButton = ethList.getElementsByTagName('button')
|
||||
TestUtils.Simulate.click(ethButton[0])
|
||||
await sleep(450)
|
||||
// Fill first send funds screen
|
||||
const recipientInput = SafeDom.getByPlaceholderText('Recipient*')
|
||||
const amountInput = SafeDom.getByPlaceholderText('Amount*')
|
||||
const reviewBtn = SafeDom.getByTestId('review-tx-btn')
|
||||
fireEvent.change(recipientInput, { target: { value: recipient } })
|
||||
fireEvent.change(amountInput, { target: { value } })
|
||||
await sleep(200)
|
||||
fireEvent.click(reviewBtn)
|
||||
|
||||
// fill the form
|
||||
const inputs = TestUtils.scryRenderedDOMComponentsWithTag(SafeDom, 'input')
|
||||
const destinationInput = inputs[0]
|
||||
const amountInEthInput = inputs[1]
|
||||
TestUtils.Simulate.change(amountInEthInput, { target: { value } })
|
||||
TestUtils.Simulate.change(destinationInput, { target: { value: destination } })
|
||||
// $FlowFixMe
|
||||
const form = TestUtils.findRenderedDOMComponentWithTag(SafeDom, 'form')
|
||||
|
||||
// submit it
|
||||
TestUtils.Simulate.submit(form)
|
||||
TestUtils.Simulate.submit(form)
|
||||
|
||||
return whenExecuted(SafeDom, SendToken)
|
||||
}
|
||||
|
||||
export const checkMinedMoveFundsTx = (Transaction: React.Component<any, any>, name: string) => {
|
||||
checkMinedTx(Transaction, name)
|
||||
}
|
||||
|
||||
export const checkPendingMoveFundsTx = async (
|
||||
Transaction: React.Component<any, any>,
|
||||
safeThreshold: number,
|
||||
name: string,
|
||||
statusses: string[],
|
||||
) => {
|
||||
await checkPendingTx(Transaction, safeThreshold, name, statusses)
|
||||
// Submit the tx (Review Tx screen)
|
||||
const submitBtn = SafeDom.getByTestId('submit-tx-btn')
|
||||
fireEvent.click(submitBtn)
|
||||
await sleep(1000)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue