WA-238 refactor update deployedSafe builder including execture withdrawn helper

This commit is contained in:
apanizo 2018-05-13 13:30:20 +02:00
parent 79ae47570f
commit aa93a8301b
2 changed files with 25 additions and 16 deletions

View File

@ -6,15 +6,15 @@ import { ConnectedRouter } from 'react-router-redux'
import Button from '~/components/layout/Button' import Button from '~/components/layout/Button'
import { aNewStore, history } from '~/store' import { aNewStore, history } from '~/store'
import { addEtherTo } from '~/test/addEtherTo' import { addEtherTo } from '~/test/addEtherTo'
import { aDeployedSafe } from '~/routes/safe/store/test/builder/deployedSafe.builder' import { aDeployedSafe, executeWithdrawnOn } from '~/routes/safe/store/test/builder/deployedSafe.builder'
import { SAFELIST_ADDRESS } from '~/routes/routes' import { SAFELIST_ADDRESS } from '~/routes/routes'
import SafeView from '~/routes/safe/component/Safe' import SafeView from '~/routes/safe/component/Safe'
import AppRoutes from '~/routes' import AppRoutes from '~/routes'
import { WITHDRAWN_BUTTON_TEXT } from '~/routes/safe/component/Safe/DailyLimit' import { WITHDRAWN_BUTTON_TEXT } from '~/routes/safe/component/Safe/DailyLimit'
import WithdrawnComponent, { SEE_TXS_BUTTON_TEXT } from '~/routes/safe/component/Withdrawn' import WithdrawnComponent, { SEE_TXS_BUTTON_TEXT } from '~/routes/safe/component/Withdrawn'
import { getBalanceInEtherOf, getProviderInfo } from '~/wallets/getWeb3' import { getBalanceInEtherOf } from '~/wallets/getWeb3'
import { sleep } from '~/utils/timer' import { sleep } from '~/utils/timer'
import withdrawn, { DESTINATION_PARAM, VALUE_PARAM, getDailyLimitFrom } from '~/routes/safe/component/Withdrawn/withdrawn' import { getDailyLimitFrom } from '~/routes/safe/component/Withdrawn/withdrawn'
describe('React DOM TESTS > Withdrawn funds from safe', () => { describe('React DOM TESTS > Withdrawn funds from safe', () => {
let SafeDom let SafeDom
@ -73,19 +73,15 @@ describe('React DOM TESTS > Withdrawn funds from safe', () => {
}) })
it('spentToday dailyLimitModule property is updated correctly', async () => { it('spentToday dailyLimitModule property is updated correctly', async () => {
const providerInfo = await getProviderInfo() // GIVEN in beforeEach
const userAddress = providerInfo.account // WHEN
await executeWithdrawnOn(address, 0.01)
const values = { await executeWithdrawnOn(address, 0.01)
[DESTINATION_PARAM]: userAddress,
[VALUE_PARAM]: '0.01',
}
await withdrawn(values, address, userAddress)
await withdrawn(values, address, userAddress)
const ethAddress = 0 const ethAddress = 0
const dailyLimit: DailyLimitProps = await getDailyLimitFrom(address, ethAddress) const dailyLimit: DailyLimitProps = await getDailyLimitFrom(address, ethAddress)
// THEN
expect(dailyLimit.value).toBe(0.5) expect(dailyLimit.value).toBe(0.5)
expect(dailyLimit.spentToday).toBe(0.02) expect(dailyLimit.spentToday).toBe(0.02)
}) })

View File

@ -11,6 +11,7 @@ import { sleep } from '~/utils/timer'
import { getProviderInfo } from '~/wallets/getWeb3' import { getProviderInfo } from '~/wallets/getWeb3'
import addProvider from '~/wallets/store/actions/addProvider' import addProvider from '~/wallets/store/actions/addProvider'
import { makeProvider } from '~/wallets/store/model/provider' import { makeProvider } from '~/wallets/store/model/provider'
import withdrawn, { DESTINATION_PARAM, VALUE_PARAM } from '~/routes/safe/component/Withdrawn/withdrawn'
export const renderSafe = async (localStore: Store<GlobalState>) => { export const renderSafe = async (localStore: Store<GlobalState>) => {
const provider = await getProviderInfo() const provider = await getProviderInfo()
@ -28,7 +29,7 @@ export const renderSafe = async (localStore: Store<GlobalState>) => {
) )
} }
const deploySafe = async (safe: React$Component<{}>) => { const deploySafe = async (safe: React$Component<{}>, dailyLimit: string) => {
const inputs = TestUtils.scryRenderedDOMComponentsWithTag(safe, 'input') const inputs = TestUtils.scryRenderedDOMComponentsWithTag(safe, 'input')
const fieldName = inputs[0] const fieldName = inputs[0]
const fieldOwners = inputs[1] const fieldOwners = inputs[1]
@ -42,7 +43,7 @@ const deploySafe = async (safe: React$Component<{}>) => {
TestUtils.Simulate.change(fieldName, { target: { value: 'Adolfo Safe' } }) TestUtils.Simulate.change(fieldName, { target: { value: 'Adolfo Safe' } })
TestUtils.Simulate.change(fieldConfirmations, { target: { value: '1' } }) TestUtils.Simulate.change(fieldConfirmations, { target: { value: '1' } })
TestUtils.Simulate.change(ownerName, { target: { value: 'Adolfo Eth Account' } }) TestUtils.Simulate.change(ownerName, { target: { value: 'Adolfo Eth Account' } })
TestUtils.Simulate.change(fieldDailyLimit, { target: { value: '0.5' } }) TestUtils.Simulate.change(fieldDailyLimit, { target: { value: dailyLimit } })
const form = TestUtils.findRenderedDOMComponentWithTag(safe, 'form') const form = TestUtils.findRenderedDOMComponentWithTag(safe, 'form')
@ -66,9 +67,21 @@ const deploySafe = async (safe: React$Component<{}>) => {
return transactionHash return transactionHash
} }
export const aDeployedSafe = async (specificStore: Store<GlobalState>) => { export const aDeployedSafe = async (specificStore: Store<GlobalState>, dailyLimit?: number = 0.5) => {
const safe: React$Component<{}> = await renderSafe(specificStore) const safe: React$Component<{}> = await renderSafe(specificStore)
const deployedSafe = await deploySafe(safe) const deployedSafe = await deploySafe(safe, `${dailyLimit}`)
return deployedSafe.logs[1].args.proxy return deployedSafe.logs[1].args.proxy
} }
export const executeWithdrawnOn = async (safeAddress: string, value: number) => {
const providerInfo = await getProviderInfo()
const userAddress = providerInfo.account
const values = {
[DESTINATION_PARAM]: userAddress,
[VALUE_PARAM]: `${value}`,
}
await withdrawn(values, safeAddress, userAddress)
}