From 034c15d1f301f402fc4fb9b5e79b7d25a0df7079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Mart=C3=ADnez?= Date: Sat, 20 Jul 2019 20:11:04 +0200 Subject: [PATCH] Transaction list test for owner settings transactions --- src/test/safe.dom.settings.owners.test.js | 14 +++++ .../transactions/transactionList.helper.js | 55 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 src/test/utils/transactions/transactionList.helper.js diff --git a/src/test/safe.dom.settings.owners.test.js b/src/test/safe.dom.settings.owners.test.js index f117bb94..c2ddaec9 100644 --- a/src/test/safe.dom.settings.owners.test.js +++ b/src/test/safe.dom.settings.owners.test.js @@ -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) }) }) diff --git a/src/test/utils/transactions/transactionList.helper.js b/src/test/utils/transactions/transactionList.helper.js new file mode 100644 index 00000000..d54fc721 --- /dev/null +++ b/src/test/utils/transactions/transactionList.helper.js @@ -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) => { + // 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, + 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, + 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, + 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)}`) +}