Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #19 from Thoughtscript/test/fixing-tests
Browse files Browse the repository at this point in the history
Issue #15 - test: fixing tests
  • Loading branch information
n1c01a5 authored Mar 16, 2018
2 parents dc90464 + 2563d86 commit 61c4083
Show file tree
Hide file tree
Showing 19 changed files with 180 additions and 171 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
TODO
See kleros.md.
3 changes: 1 addition & 2 deletions src/bootstrap/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Contract from '../containers/contract'
import Profile from '../containers/profile'
import KlerosGitter from '../components/kleros-gitter'


import Initializer from './initializer'

import './app.css'
Expand All @@ -34,7 +33,7 @@ const App = ({ store, history, testElement }) => (
path="/contracts/:contractAddress"
component={Contract}
/>
<Route exact path="/evidences/new" component={NewEvidence} />
<Route exact path="/evidences/new" component={NewEvidence} />
</Switch>
{testElement}
<KlerosGitter />
Expand Down
1 change: 0 additions & 1 deletion src/bootstrap/dapp-api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Eth from 'ethjs'

import { Kleros } from 'kleros-api'

let ethInstance
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/setup-integration-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { mount } from 'enzyme'
import { mount, shallow } from 'enzyme'

import configureStore from './configure-store'
import App from './app'
Expand Down
9 changes: 3 additions & 6 deletions src/components/kleros-gitter/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react'
import PropTypes from 'prop-types'

import './kleros-gitter.css'
import logo from './logo_kleros.png'
Expand All @@ -9,11 +8,9 @@ const KlerosGitter = () => (
<a
target="_blank"
href="https://gitter.im/kleros/Lobby"
alt="Gitter kleros">
<img
className="Kleros-gitter-logo"
src={logo}
alt="Logo Kleros Gitter" />
alt="Gitter kleros"
>
<img className="Kleros-gitter-logo" src={logo} alt="Logo Kleros Gitter" />
</a>
</div>
)
Expand Down
14 changes: 10 additions & 4 deletions src/components/textarea-input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const TextareaInput = ({
input: { value, type, onChange },
meta: { valid, touched, error },
placeholder,
rows = 7,
cols = 50,
rows,
cols,
...rest
}) => (
<div className="TextareaInput" {...rest}>
Expand All @@ -27,6 +27,11 @@ const TextareaInput = ({
</div>
)

TextareaInput.defaultProps = {
rows: 7,
cols: 50
}

TextareaInput.propTypes = {
// Redux Form
input: PropTypes.shape({
Expand All @@ -38,10 +43,11 @@ TextareaInput.propTypes = {
touched: PropTypes.bool,
error: PropTypes.string
}).isRequired,

// State
placeholder: PropTypes.oneOfType([PropTypes.element, PropTypes.string])
.isRequired
.isRequired,
rows: PropTypes.number,
cols: PropTypes.number
}

export default TextareaInput
4 changes: 4 additions & 0 deletions src/containers/contract/contract.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ let integration = {
beforeEach(() => {
integration = setupIntegrationTest({ router: { location: '/contract' } })
})

it('Contract test', async () => {
expect(true)
})
66 changes: 33 additions & 33 deletions src/containers/contract/evidence-form/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import Button from '../../../components/button'

import './new-evidence.css'
import { CreateContractForm } from '../../../forms/contract'

const FINAL_STEP = 2

Expand Down Expand Up @@ -48,53 +49,54 @@ class NewEvidence extends PureComponent {
if (event.key === 'Enter') {
event.preventDefault()
const { submitCreateEvidenceForm } = this.props
const { step } = this.state
submitCreateEvidenceForm()
this.setState({ step: this.state.step + 1 })
this.setState({ step: step + 1 })
}
}

nextStep = event => {
event.preventDefault()
const { submitCreateEvidenceForm } = this.props
const { step } = this.state
submitCreateEvidenceForm()
this.setState({ step: this.state.step + 1 })
this.setState({ step: step + 1 })
}

isUrl = url => {
var re = /^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/g
const re = /^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/g
return re.test(String(url).toLowerCase())
}

isFieldOk = () => {
switch (this.state.step) {
isFieldOk = step => {
const { form } = this.props
switch (step) {
case 0:
if (
this.props.form &&
this.props.form.createEvidenceFormKey &&
this.props.form.createEvidenceFormKey.values &&
this.props.form.createEvidenceFormKey.values.name != '' &&
this.props.form.createEvidenceFormKey.values.name != null
return (
form &&
form.createEvidenceFormKey &&
form.createEvidenceFormKey.values &&
form.createEvidenceFormKey.values.name !== '' &&
form.createEvidenceFormKey.values.name != null
)
return true
case 1:
if (
this.props.form &&
this.props.form.createEvidenceFormKey &&
this.props.form.createEvidenceFormKey.values &&
this.props.form.createEvidenceFormKey.values.description != '' &&
this.props.form.createEvidenceFormKey.values.description != null
return (
form &&
form.createEvidenceFormKey &&
form.createEvidenceFormKey.values &&
form.createEvidenceFormKey.values.description !== '' &&
form.createEvidenceFormKey.values.description != null
)
return true
case 2:
if (
this.props.form &&
this.props.form.createEvidenceFormKey &&
this.props.form.createEvidenceFormKey.values &&
this.isUrl(this.props.form.createEvidenceFormKey.values.url)
return (
form &&
form.createEvidenceFormKey &&
form.createEvidenceFormKey.values &&
this.isUrl(form.createEvidenceFormKey.values.url)
)
return true
default:
return false
}
return false
}

render() {
Expand Down Expand Up @@ -129,24 +131,22 @@ class NewEvidence extends PureComponent {
initialValues={{ addressContract: contract.data.address }}
/>
{step === FINAL_STEP &&
this.isFieldOk() && (
this.isFieldOk(step) && (
<div
className="NewContract-form-release"
onClick={submitCreateEvidenceForm}
>
Add the evidence
</div>
)
}
)}
</div>
{this.isFieldOk() &&
step != FINAL_STEP && (
{this.isFieldOk(step) &&
step !== FINAL_STEP && (
<div onClick={this.nextStep} className="arrow-container">
<div className="arrow-container-arrow" />
<div className="arrow-container-arrow arrow-container-arrow-animation" />
</div>
)
}
)}
</div>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/containers/contract/evidence-form/new-evidence.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ let integration = {
beforeEach(() => {
integration = setupIntegrationTest({ router: { location: '/' } })
})

it('New evidence test', async () => {
expect(true)
})
91 changes: 44 additions & 47 deletions src/containers/contract/form/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,21 @@ class NewContract extends PureComponent {
this.setState({ hasPrevPage, hasNextPage })

handleKeyPress = event => {
if (event.key === 'Enter' && this.state.step !== FINAL_STEP) {
const { step } = this.state
if (event.key === 'Enter' && step !== FINAL_STEP) {
event.preventDefault()
const { submitCreateContractForm } = this.props
submitCreateContractForm()
this.setState({ step: this.state.step + 1 })
this.setState({ step: step + 1 })
}
}

nextStep = event => {
event.preventDefault()
const { submitCreateContractForm } = this.props
const { step } = this.state
submitCreateContractForm()
this.setState({ step: this.state.step + 1 })
this.setState({ step: step + 1 })
}

isAddress = address => {
Expand Down Expand Up @@ -97,57 +99,54 @@ class NewContract extends PureComponent {
}

isEmail = email => {
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
return re.test(String(email).toLowerCase())
}

isFieldOk = () => {
switch (this.state.step) {
isFieldOk = step => {
const { form } = this.props
switch (step) {
case 0:
if (
this.props.form &&
this.props.form.createContractFormKey &&
this.props.form.createContractFormKey.values &&
this.props.form.createContractFormKey.values.title != '' &&
this.props.form.createContractFormKey.values.title != null
return (
form &&
form.createContractFormKey &&
form.createContractFormKey.values &&
form.createContractFormKey.values.title !== '' &&
form.createContractFormKey.values.title != null
)
return true
case 1:
if (
this.props.form &&
this.props.form.createContractFormKey &&
this.props.form.createContractFormKey.values &&
this.isAddress(this.props.form.createContractFormKey.values.partyB)
return (
form &&
form.createContractFormKey &&
form.createContractFormKey.values &&
this.isAddress(form.createContractFormKey.values.partyB)
)
return true
case 2:
if (
this.props.form &&
this.props.form.createContractFormKey &&
this.props.form.createContractFormKey.values &&
!isNaN(this.props.form.createContractFormKey.values.payment) &&
this.props.form.createContractFormKey.values.payment > 0
return (
form &&
form.createContractFormKey &&
form.createContractFormKey.values &&
!isNaN(form.createContractFormKey.values.payment) &&
form.createContractFormKey.values.payment > 0
)
return true
case 3:
if (
this.props.form &&
this.props.form.createContractFormKey &&
this.props.form.createContractFormKey.values &&
this.isEmail(this.props.form.createContractFormKey.values.email)
return (
form &&
form.createContractFormKey &&
form.createContractFormKey.values &&
this.isEmail(form.createContractFormKey.values.email)
)
return true
case 4:
if (
this.props.form &&
this.props.form.createContractFormKey &&
this.props.form.createContractFormKey.values &&
this.props.form.createContractFormKey.values.description != '' &&
this.props.form.createContractFormKey.values.description != null
return (
form &&
form.createContractFormKey &&
form.createContractFormKey.values &&
form.createContractFormKey.values.description !== '' &&
form.createContractFormKey.values.description != null
)
return true
default:
return false
}
return false
}

render() {
Expand Down Expand Up @@ -182,24 +181,22 @@ class NewContract extends PureComponent {
onSubmit={createContract}
/>
{step === FINAL_STEP &&
this.isFieldOk() && (
this.isFieldOk(step) && (
<div
className="NewContract-form-release"
onClick={submitCreateContractForm}
>
Release the contract
</div>
)
}
)}
</div>
{this.isFieldOk() &&
step != FINAL_STEP && (
{this.isFieldOk(step) &&
step !== FINAL_STEP && (
<div onClick={this.nextStep} className="arrow-container">
<div className="arrow-container-arrow" />
<div className="arrow-container-arrow arrow-container-arrow-animation" />
</div>
)
}
)}
</div>
</div>
<div className="flex-container-main-footer">
Expand Down
4 changes: 4 additions & 0 deletions src/containers/contract/form/new-contract.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ let integration = {
beforeEach(() => {
integration = setupIntegrationTest({ router: { location: '/' } })
})

it('New contract test', async () => {
expect(true)
})
Loading

0 comments on commit 61c4083

Please sign in to comment.