From 09c4a2037f7546776c70515ce75092c584a942c7 Mon Sep 17 00:00:00 2001 From: apanizo Date: Tue, 13 Nov 2018 10:27:04 +0100 Subject: [PATCH] Created load safe DOM test #75 --- src/test/safe.dom.create.test.js | 2 +- src/test/safe.dom.load.test.js | 60 ++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/test/safe.dom.load.test.js diff --git a/src/test/safe.dom.create.test.js b/src/test/safe.dom.create.test.js index e0500382..913b46c4 100644 --- a/src/test/safe.dom.create.test.js +++ b/src/test/safe.dom.create.test.js @@ -33,7 +33,7 @@ const fillOpenSafeForm = async (localStore: Store) => { const INTERVAL = 500 const MAX_TIMES_EXECUTED = 30 -const whenSafeDeployed = () => new Promise((resolve, reject) => { +export const whenSafeDeployed = (): Promise => new Promise((resolve, reject) => { let times = 0 const interval = setInterval(() => { if (times >= MAX_TIMES_EXECUTED) { diff --git a/src/test/safe.dom.load.test.js b/src/test/safe.dom.load.test.js new file mode 100644 index 00000000..5a68f214 --- /dev/null +++ b/src/test/safe.dom.load.test.js @@ -0,0 +1,60 @@ +// @flow +import * as React from 'react' +import { type Store } from 'redux' +import TestUtils from 'react-dom/test-utils' +import { Provider } from 'react-redux' +import { ConnectedRouter } from 'react-router-redux' +import Load from '~/routes/load/container/Load' +import { aNewStore, history, type GlobalState } from '~/store' +import { sleep } from '~/utils/timer' +import { getProviderInfo } from '~/logic/wallets/getWeb3' +import addProvider from '~/logic/wallets/store/actions/addProvider' +import { makeProvider } from '~/logic/wallets/store/model/provider' +import { aMinedSafe } from './builder/safe.redux.builder' +import { whenSafeDeployed } from './safe.dom.create.test' + +const travelToLoadRoute = async (localStore: Store) => { + const provider = await getProviderInfo() + const walletRecord = makeProvider(provider) + localStore.dispatch(addProvider(walletRecord)) + + return ( + TestUtils.renderIntoDocument(( + + + + + + )) + ) +} + +describe('DOM > Feature > LOAD a safe', () => { + it('load correctly a created safe', async () => { + const store = aNewStore() + const address = await aMinedSafe(store) + const LoadDom = await travelToLoadRoute(store) + + const form = TestUtils.findRenderedDOMComponentWithTag(LoadDom, 'form') + const inputs = TestUtils.scryRenderedDOMComponentsWithTag(LoadDom, 'input') + + // Fill Safe's name + const fieldName = inputs[0] + TestUtils.Simulate.change(fieldName, { target: { value: 'Adolfo Safe' } }) + TestUtils.Simulate.submit(form) + await sleep(400) + + // Fill Safe's name + const fieldAddress = inputs[1] + TestUtils.Simulate.change(fieldAddress, { target: { value: address } }) + TestUtils.Simulate.submit(form) + await sleep(400) + + // Submit + TestUtils.Simulate.submit(form) + await sleep(400) + + const deployedAddress = await whenSafeDeployed() + expect(deployedAddress).toBe(address) + }) +})