From db54ad812ed778a3b5f059c04261509ac518b7aa Mon Sep 17 00:00:00 2001 From: mmv Date: Tue, 5 Nov 2019 17:58:49 +0400 Subject: [PATCH] WIP: Fixing tests, use window.web3 in test setup --- src/components/Header/index.jsx | 3 +-- src/components/Sidebar/SafeList/index.jsx | 2 +- src/logic/wallets/getWeb3.js | 4 +++- src/routes/load/container/Load.jsx | 2 +- src/routes/open/container/Open.jsx | 3 +-- src/test/builder/safe.dom.utils.js | 2 +- src/test/builder/safe.redux.builder.js | 3 ++- src/test/safe.dom.funds.threshold=1.test.js | 2 +- 8 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/components/Header/index.jsx b/src/components/Header/index.jsx index e8074cfa..032b13be 100644 --- a/src/components/Header/index.jsx +++ b/src/components/Header/index.jsx @@ -36,8 +36,7 @@ class HeaderComponent extends React.PureComponent { async componentDidMount() { const lastUsedProvider = await loadLastUsedProvider() - - if (INJECTED_PROVIDERS.includes(lastUsedProvider)) { + if (INJECTED_PROVIDERS.includes(lastUsedProvider) || process.env.NODE_ENV === 'test') { web3Connect.connectToInjected() } } diff --git a/src/components/Sidebar/SafeList/index.jsx b/src/components/Sidebar/SafeList/index.jsx index 0848c068..6f0dabd7 100644 --- a/src/components/Sidebar/SafeList/index.jsx +++ b/src/components/Sidebar/SafeList/index.jsx @@ -73,7 +73,7 @@ const SafeList = ({ {safes.map((safe) => ( diff --git a/src/logic/wallets/getWeb3.js b/src/logic/wallets/getWeb3.js index 45564cc4..45075f24 100644 --- a/src/logic/wallets/getWeb3.js +++ b/src/logic/wallets/getWeb3.js @@ -64,7 +64,9 @@ const getInfuraUrl = () => { // With some wallets from web3connect you have to use their provider instance only for signing // And our own one to fetch data -export const web3RO = new Web3(new Web3.providers.HttpProvider(getInfuraUrl())) +export const web3RO = process.env.NODE_ENV !== 'test' + ? new Web3(new Web3.providers.HttpProvider(getInfuraUrl())) + : new Web3(window.web3.currentProvider) let web3 = web3RO export const getWeb3 = () => web3 diff --git a/src/routes/load/container/Load.jsx b/src/routes/load/container/Load.jsx index 82b825e0..6303b337 100644 --- a/src/routes/load/container/Load.jsx +++ b/src/routes/load/container/Load.jsx @@ -47,7 +47,7 @@ class Load extends React.Component { await loadSafe(safeName, safeAddress, owners, addSafe) - const url = `${SAFELIST_ADDRESS}/${safeAddress}` + const url = `${SAFELIST_ADDRESS}/${safeAddress}/balances` history.push(url) } catch (error) { console.error('Error while loading the Safe', error) diff --git a/src/routes/open/container/Open.jsx b/src/routes/open/container/Open.jsx index 3d8f9734..a14cefe3 100644 --- a/src/routes/open/container/Open.jsx +++ b/src/routes/open/container/Open.jsx @@ -42,10 +42,9 @@ export const createSafe = async (values: Object, userAccount: string, addSafe: A safeProps.owners = owners addSafe(safeProps) - if (stillInOpeningView()) { const url = { - pathname: `${SAFELIST_ADDRESS}/${safeContract.address}`, + pathname: `${SAFELIST_ADDRESS}/${safeContract.address}/balances`, state: { name, tx: safe.tx, diff --git a/src/test/builder/safe.dom.utils.js b/src/test/builder/safe.dom.utils.js index ad5a195a..ae042f3c 100644 --- a/src/test/builder/safe.dom.utils.js +++ b/src/test/builder/safe.dom.utils.js @@ -102,7 +102,7 @@ const renderApp = (store: Store) => ({ export const renderSafeView = (store: Store, address: string) => { const app = renderApp(store) - const url = `${SAFELIST_ADDRESS}/${address}` + const url = `${SAFELIST_ADDRESS}/${address}/balances` history.push(url) return app diff --git a/src/test/builder/safe.redux.builder.js b/src/test/builder/safe.redux.builder.js index 23e7bd34..3157bc3b 100644 --- a/src/test/builder/safe.redux.builder.js +++ b/src/test/builder/safe.redux.builder.js @@ -1,4 +1,5 @@ // @flow +/* eslint-disable max-classes-per-file */ import SafeRecord, { type Safe } from '~/routes/safe/store/models/safe' import addSafe, { buildOwnersFrom } from '~/routes/safe/store/actions/addSafe' import { @@ -74,7 +75,7 @@ export const aMinedSafe = async ( threshold: number = 1, name: string = 'Safe Name', ): Promise => { - const provider = await getProviderInfo() + const provider = await getProviderInfo(window.web3.currentProvider) const walletRecord = makeProvider(provider) store.dispatch(addProvider(walletRecord)) diff --git a/src/test/safe.dom.funds.threshold=1.test.js b/src/test/safe.dom.funds.threshold=1.test.js index 3e708648..3c281ea0 100644 --- a/src/test/safe.dom.funds.threshold=1.test.js +++ b/src/test/safe.dom.funds.threshold=1.test.js @@ -38,7 +38,7 @@ describe('DOM > Feature > Sending Funds', () => { // WHEN const SafeDom = renderSafeView(store, safeAddress) - await sleep(1300) + await sleep(3500) // Open send funds modal const balanceRows = SafeDom.getAllByTestId(BALANCE_ROW_TEST_ID)