add fillAndSUbmitSendFunds form util function for tests
This commit is contained in:
parent
1674d74de0
commit
03153438c9
|
@ -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
|
git clone https://github.com/gnosis/safe-contracts.git
|
||||||
cd safe-contracts
|
cd safe-contracts
|
||||||
yarn
|
yarn
|
||||||
ganache-cli -l 7000000
|
ganache-cli -l 7000000 -d
|
||||||
npx truffle migrate
|
npx truffle migrate
|
||||||
```
|
```
|
||||||
2. Migrate Token Contracts for the tests:
|
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 '@testing-library/jest-dom/extend-expect'
|
||||||
import updateSafe from '~/routes/safe/store/actions/updateSafe'
|
import updateSafe from '~/routes/safe/store/actions/updateSafe'
|
||||||
import { BALANCE_ROW_TEST_ID } from '~/routes/safe/components/Balances'
|
import { BALANCE_ROW_TEST_ID } from '~/routes/safe/components/Balances'
|
||||||
|
import { fillAndSubmitSendFundsForm } from './utils/transactions'
|
||||||
|
|
||||||
afterEach(cleanup)
|
afterEach(cleanup)
|
||||||
|
|
||||||
describe('DOM > Feature > Funds', () => {
|
describe('DOM > Feature > Sending Funds', () => {
|
||||||
let store
|
let store
|
||||||
let safeAddress: string
|
let safeAddress: string
|
||||||
let accounts
|
let accounts
|
||||||
|
@ -44,19 +45,7 @@ describe('DOM > Feature > Funds', () => {
|
||||||
const sendButton = SafeDom.getByTestId('balance-send-btn')
|
const sendButton = SafeDom.getByTestId('balance-send-btn')
|
||||||
fireEvent.click(sendButton)
|
fireEvent.click(sendButton)
|
||||||
|
|
||||||
// Fill first send funds screen
|
await fillAndSubmitSendFundsForm(SafeDom, sendButton, ethAmount, accounts[0])
|
||||||
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)
|
|
||||||
|
|
||||||
// THEN
|
// THEN
|
||||||
const safeFunds = await getBalanceInEtherOf(safeAddress)
|
const safeFunds = await getBalanceInEtherOf(safeAddress)
|
||||||
|
@ -97,21 +86,8 @@ describe('DOM > Feature > Funds', () => {
|
||||||
expect(balanceRows.length).toBe(2)
|
expect(balanceRows.length).toBe(2)
|
||||||
const sendButtons = SafeDom.getAllByTestId('balance-send-btn')
|
const sendButtons = SafeDom.getAllByTestId('balance-send-btn')
|
||||||
expect(sendButtons.length).toBe(2)
|
expect(sendButtons.length).toBe(2)
|
||||||
fireEvent.click(sendButtons[1])
|
|
||||||
|
|
||||||
// Fill first send funds screen
|
await fillAndSubmitSendFundsForm(SafeDom, sendButtons[1], tokensAmount, tokenReceiver)
|
||||||
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)
|
|
||||||
|
|
||||||
// THEN
|
// THEN
|
||||||
const safeFunds = await calculateBalanceOf(tokenAddress, safeAddress, 18)
|
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
|
// @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 { 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 (
|
export const fillAndSubmitSendFundsForm = async (
|
||||||
SafeDom: React.Component<any, any>,
|
SafeDom: any,
|
||||||
expandBalance: React.Component<any, any>,
|
sendButton: React.Component<any, any>,
|
||||||
value: string,
|
value: string,
|
||||||
destination: string,
|
recipient: string,
|
||||||
) => {
|
) => {
|
||||||
// load add multisig form component
|
// load add multisig form component
|
||||||
TestUtils.Simulate.click(expandBalance)
|
fireEvent.click(sendButton)
|
||||||
// give time to re-render it
|
// give time to re-render it
|
||||||
await sleep(400)
|
await sleep(400)
|
||||||
|
|
||||||
const ethList = TestUtils.findRenderedDOMComponentWithClass(SafeDom, 'ETH')
|
// Fill first send funds screen
|
||||||
if (!ethList) throw new Error()
|
const recipientInput = SafeDom.getByPlaceholderText('Recipient*')
|
||||||
const ethButton = ethList.getElementsByTagName('button')
|
const amountInput = SafeDom.getByPlaceholderText('Amount*')
|
||||||
TestUtils.Simulate.click(ethButton[0])
|
const reviewBtn = SafeDom.getByTestId('review-tx-btn')
|
||||||
await sleep(450)
|
fireEvent.change(recipientInput, { target: { value: recipient } })
|
||||||
|
fireEvent.change(amountInput, { target: { value } })
|
||||||
|
await sleep(200)
|
||||||
|
fireEvent.click(reviewBtn)
|
||||||
|
|
||||||
// fill the form
|
// Submit the tx (Review Tx screen)
|
||||||
const inputs = TestUtils.scryRenderedDOMComponentsWithTag(SafeDom, 'input')
|
const submitBtn = SafeDom.getByTestId('submit-tx-btn')
|
||||||
const destinationInput = inputs[0]
|
fireEvent.click(submitBtn)
|
||||||
const amountInEthInput = inputs[1]
|
await sleep(1000)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue