safe creation test wip

This commit is contained in:
mmv 2019-05-30 13:04:19 +04:00
parent ead30855a6
commit 4f54a60866
4 changed files with 27 additions and 41 deletions

View File

@ -21,6 +21,7 @@ type Props = {
onReset?: () => void, onReset?: () => void,
initialValues?: Object, initialValues?: Object,
disabledWhenValidating?: boolean, disabledWhenValidating?: boolean,
testId?: string,
} }
type State = { type State = {
@ -145,7 +146,7 @@ class GnoStepper extends React.PureComponent<Props, State> {
render() { render() {
const { const {
steps, children, classes, disabledWhenValidating = false, steps, children, classes, disabledWhenValidating = false, testId,
} = this.props } = this.props
const { page, values } = this.state const { page, values } = this.state
const activePage = this.getActivePageFrom(children) const activePage = this.getActivePageFrom(children)
@ -154,7 +155,7 @@ class GnoStepper extends React.PureComponent<Props, State> {
return ( return (
<React.Fragment> <React.Fragment>
<GnoForm onSubmit={this.handleSubmit} initialValues={values} validation={this.validate}> <GnoForm onSubmit={this.handleSubmit} initialValues={values} validation={this.validate} testId={testId}>
{(submitting: boolean, validating: boolean, ...rest: any) => { {(submitting: boolean, validating: boolean, ...rest: any) => {
const disabled = disabledWhenValidating ? submitting || validating : submitting const disabled = disabledWhenValidating ? submitting || validating : submitting
const controls = ( const controls = (

View File

@ -16,6 +16,7 @@ type Props = {
validation?: (values: Object) => Object | Promise<Object>, validation?: (values: Object) => Object | Promise<Object>,
initialValues?: Object, initialValues?: Object,
formMutators?: Object, formMutators?: Object,
testId?: string,
} }
const stylesBasedOn = (padding: number): $Shape<CSSStyleDeclaration> => ({ const stylesBasedOn = (padding: number): $Shape<CSSStyleDeclaration> => ({
@ -25,7 +26,7 @@ const stylesBasedOn = (padding: number): $Shape<CSSStyleDeclaration> => ({
}) })
const GnoForm = ({ const GnoForm = ({
onSubmit, validation, initialValues, children, padding = 0, formMutators, onSubmit, validation, initialValues, children, padding = 0, formMutators, testId = '',
}: Props) => ( }: Props) => (
<Form <Form
validate={validation} validate={validation}
@ -33,7 +34,7 @@ const GnoForm = ({
initialValues={initialValues} initialValues={initialValues}
mutators={formMutators} mutators={formMutators}
render={({ handleSubmit, ...rest }) => ( render={({ handleSubmit, ...rest }) => (
<form onSubmit={handleSubmit} style={stylesBasedOn(padding)}> <form onSubmit={handleSubmit} style={stylesBasedOn(padding)} data-testid={testId}>
{children(rest.submitting, rest.validating, rest, rest.form.mutators)} {children(rest.submitting, rest.validating, rest, rest.form.mutators)}
</form> </form>
)} )}

View File

@ -14,9 +14,7 @@ import { getOwnerNameBy, getOwnerAddressBy, FIELD_CONFIRMATIONS } from '~/routes
import { history } from '~/store' import { history } from '~/store'
import { secondary } from '~/theme/variables' import { secondary } from '~/theme/variables'
const getSteps = () => [ const getSteps = () => ['Start', 'Owners', 'Confirmations', 'Review']
'Start', 'Owners', 'Confirmations', 'Review',
]
const initialValuesFrom = (userAccount: string) => ({ const initialValuesFrom = (userAccount: string) => ({
[getOwnerNameBy(0)]: 'My Metamask (me)', [getOwnerNameBy(0)]: 'My Metamask (me)',
@ -49,37 +47,24 @@ const Layout = ({
return ( return (
<React.Fragment> <React.Fragment>
{ provider {provider ? (
? ( <Block>
<Block> <Row align="center">
<Row align="center"> <IconButton onClick={back} style={iconStyle} disableRipple>
<IconButton onClick={back} style={iconStyle} disableRipple> <ChevronLeft />
<ChevronLeft /> </IconButton>
</IconButton> <Heading tag="h2">Create New Safe</Heading>
<Heading tag="h2">Create New Safe</Heading> </Row>
</Row> <Stepper onSubmit={onCallSafeContractSubmit} steps={steps} initialValues={initialValues} testId="create-safe-form">
<Stepper <Stepper.Page>{SafeNameField}</Stepper.Page>
onSubmit={onCallSafeContractSubmit} <Stepper.Page>{SafeOwnersFields}</Stepper.Page>
steps={steps} <Stepper.Page validate={safeFieldsValidation}>{SafeThresholdField}</Stepper.Page>
initialValues={initialValues} <Stepper.Page network={network}>{Review}</Stepper.Page>
> </Stepper>
<Stepper.Page> </Block>
{ SafeNameField } ) : (
</Stepper.Page> <div>No metamask detected</div>
<Stepper.Page> )}
{ SafeOwnersFields }
</Stepper.Page>
<Stepper.Page validate={safeFieldsValidation}>
{ SafeThresholdField }
</Stepper.Page>
<Stepper.Page network={network}>
{ Review }
</Stepper.Page>
</Stepper>
</Block>
)
: <div>No metamask detected</div>
}
</React.Fragment> </React.Fragment>
) )
} }

View File

@ -1,7 +1,6 @@
// @flow // @flow
import * as React from 'react' import * as React from 'react'
import { type Store } from 'redux' import { type Store } from 'redux'
import TestUtils from 'react-dom/test-utils'
import { render, fireEvent, cleanup } from 'react-testing-library' import { render, fireEvent, cleanup } from 'react-testing-library'
import Select from '@material-ui/core/Select' import Select from '@material-ui/core/Select'
import { Provider } from 'react-redux' import { Provider } from 'react-redux'
@ -32,12 +31,12 @@ const renderOpenSafeForm = async (localStore: Store<GlobalState>) => {
) )
} }
const deploySafe = async (safe: React$Component<{}>, threshold: number, numOwners: number) => { const deploySafe = async (safe: any, threshold: number, numOwners: number) => {
const web3 = getWeb3() const web3 = getWeb3()
const accounts = await web3.eth.getAccounts() const accounts = await web3.eth.getAccounts()
expect(threshold).toBeLessThanOrEqual(numOwners) expect(threshold).toBeLessThanOrEqual(numOwners)
const form = TestUtils.findRenderedDOMComponentWithTag(safe, 'form') const form = safe.getByTestId('create-safe-form')
// Fill Safe's name // Fill Safe's name
const inputs = TestUtils.scryRenderedDOMComponentsWithTag(safe, 'input') const inputs = TestUtils.scryRenderedDOMComponentsWithTag(safe, 'input')