Transaction list test for owner settings transactions

This commit is contained in:
Germán Martínez 2019-07-20 20:11:04 +02:00
parent f754fa0d8f
commit 034c15d1f3
2 changed files with 69 additions and 0 deletions

View File

@ -5,6 +5,11 @@ import { aMinedSafe } from '~/test/builder/safe.redux.builder'
import { renderSafeView } from '~/test/builder/safe.dom.utils'
import { sleep } from '~/utils/timer'
import '@testing-library/jest-dom/extend-expect'
import {
checkRegisteredTxAddOwner,
checkRegisteredTxRemoveOwner,
checkRegisteredTxReplaceOwner,
} from './utils/transactions'
import { SETTINGS_TAB_BTN_TEST_ID } from '~/routes/safe/components/Layout'
import { OWNERS_SETTINGS_TAB_TEST_ID } from '~/routes/safe/components/Settings'
import {
@ -121,6 +126,9 @@ describe('DOM > Feature > Settings - Manage owners', () => {
expect(ownerRows.length).toBe(1)
expect(ownerRows[0]).toHaveTextContent('Adol 1 Eth Account')
expect(ownerRows[0]).toHaveTextContent('0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1')
// Check that the transaction was registered
await checkRegisteredTxRemoveOwner(SafeDom, '0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0')
})
it('Adds a new owner', async () => {
@ -171,6 +179,9 @@ describe('DOM > Feature > Settings - Manage owners', () => {
expect(ownerRows[0]).toHaveTextContent('0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1')
expect(ownerRows[1]).toHaveTextContent(NEW_OWNER_NAME)
expect(ownerRows[1]).toHaveTextContent(NEW_OWNER_ADDRESS)
// Check that the transaction was registered
await checkRegisteredTxAddOwner(SafeDom, NEW_OWNER_ADDRESS)
})
it('Replaces an owner', async () => {
@ -224,5 +235,8 @@ describe('DOM > Feature > Settings - Manage owners', () => {
expect(ownerRows[0]).toHaveTextContent('0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1')
expect(ownerRows[1]).toHaveTextContent(NEW_OWNER_NAME)
expect(ownerRows[1]).toHaveTextContent(NEW_OWNER_ADDRESS)
// Check that the transaction was registered
await checkRegisteredTxReplaceOwner(SafeDom, '0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0', NEW_OWNER_ADDRESS)
})
})

View File

@ -0,0 +1,55 @@
// @flow
import { fireEvent } from '@testing-library/react'
import { sleep } from '~/utils/timer'
import { shortVersionOf } from '~/logic/wallets/ethAddresses'
import { TRANSACTIONS_TAB_BTN_TEST_ID } from '~/routes/safe/components/Layout'
import { TRANSACTION_ROW_TEST_ID } from '~/routes/safe/components/TransactionsNew/TxsTable'
import {
TRANSACTIONS_DESC_ADD_OWNER_TEST_ID,
TRANSACTIONS_DESC_REMOVE_OWNER_TEST_ID,
} from '~/routes/safe/components/TransactionsNew/TxsTable/ExpandedTx/TxDescription'
export const getLastTransaction = async (SafeDom: React.Component<any, any>) => {
// Travel to transactions
const transactionsBtn = SafeDom.getByTestId(TRANSACTIONS_TAB_BTN_TEST_ID)
fireEvent.click(transactionsBtn)
await sleep(200)
// Check the last transaction was registered
const transactionRows = SafeDom.getAllByTestId(TRANSACTION_ROW_TEST_ID)
expect(transactionRows.length).toBe(1)
fireEvent.click(transactionRows[0])
}
export const checkRegisteredTxAddOwner = async (
SafeDom: React.Component<any, any>,
ownerAddress: string,
) => {
await getLastTransaction(SafeDom)
const txDescription = SafeDom.getAllByTestId(TRANSACTIONS_DESC_ADD_OWNER_TEST_ID)[0]
expect(txDescription).toHaveTextContent(`Add owner:${shortVersionOf(ownerAddress, 4)}`)
}
export const checkRegisteredTxRemoveOwner = async (
SafeDom: React.Component<any, any>,
ownerAddress: string,
) => {
await getLastTransaction(SafeDom)
const txDescription = SafeDom.getAllByTestId(TRANSACTIONS_DESC_REMOVE_OWNER_TEST_ID)[0]
expect(txDescription).toHaveTextContent(`Remove owner:${shortVersionOf(ownerAddress, 4)}`)
}
export const checkRegisteredTxReplaceOwner = async (
SafeDom: React.Component<any, any>,
oldOwnerAddress: string,
newOwnerAddress: string,
) => {
await getLastTransaction(SafeDom)
const txDescriptionRemove = SafeDom.getAllByTestId(TRANSACTIONS_DESC_REMOVE_OWNER_TEST_ID)[0]
expect(txDescriptionRemove).toHaveTextContent(`Remove owner:${shortVersionOf(oldOwnerAddress, 4)}`)
const txDescriptionAdd = SafeDom.getAllByTestId(TRANSACTIONS_DESC_ADD_OWNER_TEST_ID)[0]
expect(txDescriptionAdd).toHaveTextContent(`Add owner:${shortVersionOf(newOwnerAddress, 4)}`)
}