Supply.js : update test

This commit is contained in:
dennis00010011b 2018-08-06 01:22:07 -07:00
parent d871c0f3ba
commit c184ee25e3
7 changed files with 134 additions and 79 deletions

View File

@ -151,7 +151,8 @@
"e2eDutchWhitelist": "nps test.e2e.DutchWhitelist",
"e2eDutchMincap": "nps test.e2e.DutchMincap",
"stop": "nps test.e2e.stop",
"c": "jest --env=jsdom processWhitelist.spec.js "
"c": "jest --env=jsdom Supply.spec.js ",
"r": "jest --env=jsdom TokenSupply.spec.js "
},
"jest": {
"collectCoverageFrom": [

View File

@ -4,6 +4,7 @@ import { Form } from 'react-final-form'
import Adapter from 'enzyme-adapter-react-15'
import { configure, mount, shallow } from 'enzyme'
import renderer from 'react-test-renderer'
import { VALIDATION_MESSAGES } from "../../../src/utils/constants";
configure({ adapter: new Adapter() })
const DECRIPTION = `Minimum amount of tokens to buy. Not the minimal amount for every transaction: if minCap is 1
@ -11,7 +12,7 @@ const DECRIPTION = `Minimum amount of tokens to buy. Not the minimal amount for
const LABEL = `Contributor min cap`
describe('MinCap ', () => {
it(`should render MinCap component`, () => {
it.skip(`should render MinCap component`, () => {
let input = {
name: 'MinCap',
disabled: false,
@ -28,7 +29,7 @@ describe('MinCap ', () => {
)
expect(wrapper).toMatchSnapshot()
})
it(`should be label ${LABEL}`, () => {
it.skip(`should be label ${LABEL}`, () => {
const wrapper = mount(
<Form
onSubmit={jest.fn()} component={MinCap} validate={{}}
@ -37,7 +38,7 @@ describe('MinCap ', () => {
let lab = wrapper.find('label')
expect(lab.text()).toBe(LABEL)
})
it(`should be decription ${DECRIPTION}`, () => {
it.skip(`should be decription ${DECRIPTION}`, () => {
const wrapper = mount(
<Form
onSubmit={jest.fn()} component={MinCap} validate={{}}
@ -46,7 +47,36 @@ describe('MinCap ', () => {
let lab = wrapper.find('p[className="description"]')
expect(lab.text()).toBe(DECRIPTION)
})
it(`should give error if empty`, () => {})
it(`should give error if empty`, () => {
const val = {
tiers: [
{
supply: '150'
}
]
}
const wrapper = mount(
<Form
onSubmit={ jest.fn() }
component={MinCap}
errorStyle={{ color: 'red', fontWeight: 'bold' }}
name="mincap"
values={val}
decimals={18}
index={0}
disabled={false}
/>
)
const input = wrapper.find('input[name="mincap"]')
input.simulate('change', { target: { value: '10' } })
console.log(wrapper.find('InputField2').props())
//console.log(wrapper.find('InputField2').props().meta.error);
expect(wrapper.find('InputField2').props().meta.error).toBe('Please enter a valid number greater or equal than 0')
})
it(`should give error if negative`, () => {})
it(`should give error if decimals place greater than given`, () => {})
it(`should give error if greater tier's supply`, () => {})

View File

@ -4,6 +4,7 @@ import { Form } from 'react-final-form'
import Adapter from 'enzyme-adapter-react-15'
import { configure, mount, shallow } from 'enzyme'
import renderer from 'react-test-renderer'
import { VALIDATION_MESSAGES } from "../../../src/utils/constants";
configure({ adapter: new Adapter() })
const DECRIPTION = `How many tokens will be sold on this tier. Cap of crowdsale equals to sum of supply of all tiers`
@ -20,33 +21,68 @@ describe('Supply ', () => {
onSubmit={jest.fn()}
component={Supply}
disabled={false}
validate={{}}
input={input}
/>
)
expect(wrapper).toMatchSnapshot()
})
it(`should be label ${LABEL}`, () => {
it(`should be proper label `, () => {
const wrapper = mount(
<Form
onSubmit={jest.fn()} component={Supply} validate={{}}
onSubmit={jest.fn()} component={Supply} name='supply'
/>
)
let lab = wrapper.find('label')
expect(lab.text()).toBe(LABEL)
})
it(`should be decription ${DECRIPTION}`, () => {
it(`should be proper decription`, () => {
const wrapper = mount(
<Form
onSubmit={jest.fn()} component={Supply} validate={{}}
onSubmit={jest.fn()} component={Supply} name='supply'
/>
)
let lab = wrapper.find('p[className="description"]')
expect(lab.text()).toBe(DECRIPTION)
})
it(`should give error if empty`, () => {})
it(`should give error if not positive`, () => {})
it(`should give error if not integer`, () => {})
it(`should give error if greater than 1e18`, () => {})
it(`should give error if not numberic`, () => {})
it(`should give error if field is empty`, () => {
const wrapper = mount(
<Form
onSubmit={jest.fn()} component={Supply} name='supply'
/>
)
const input = wrapper.find('input[name="supply"]')
input.simulate('change', { target: { value: '' } })
expect(wrapper.find('InputField2').props().meta.error).toBe(VALIDATION_MESSAGES.POSITIVE);
})
it(`should give error if value is not positive`, () => {
const wrapper = mount(
<Form
onSubmit={jest.fn()} component={Supply} name='supply'
/>
)
const input = wrapper.find('input[name="supply"]')
input.simulate('change', { target: { value: '-10' } })
expect(wrapper.find('InputField2').props().meta.error).toBe(VALIDATION_MESSAGES.POSITIVE);
})
it(`should give error if value is not numberic`, () => {
const wrapper = mount(
<Form
onSubmit={jest.fn()} component={Supply} name='supply'
/>
)
const input = wrapper.find('input[name="supply"]')
input.simulate('change', { target: { value: 'absde' } })
expect(wrapper.find('InputField2').props().meta.error).toBe(VALIDATION_MESSAGES.POSITIVE);
})
it(`shouldn't give error if value is correct`, () => {
const wrapper = mount(
<Form
onSubmit={jest.fn()} component={Supply} name='supply'
/>
)
const input = wrapper.find('input[name="supply"]')
input.simulate('change', { target: { value: '10' } })
expect(wrapper.find('InputField2').props().meta.error).toBe(undefined);
})
})

View File

@ -1,5 +1,5 @@
import React from 'react'
import { TokenDecimals } from '../../../src/components/Common/TokenDecimals'
import { TokenSupply } from '../../../src/components/Common/TokenSupply'
import { Form } from 'react-final-form'
import renderer from 'react-test-renderer'
import Adapter from 'enzyme-adapter-react-15'
@ -8,26 +8,26 @@ import { VALIDATION_MESSAGES } from '../../../src/utils/constants'
configure({ adapter: new Adapter() })
describe('TokenDecimals', () => {
describe('TokenSupply', () => {
it(`should render TokenDecimals component`, () => {
const wrapper = renderer.create(
<Form onSubmit={jest.fn()} component={TokenDecimals} errorStyle={{ color: 'red', fontWeight: 'bold' }} />
<Form onSubmit={jest.fn()} component={TokenSupply} errorStyle={{ color: 'red', fontWeight: 'bold' }} />
)
expect(wrapper).toMatchSnapshot()
})
it(`should render TokenDecimals component and its children`, () => {
it(`should render TokenSupply component and its children`, () => {
const wrapper = renderer.create(
<Form onSubmit={jest.fn()} component={TokenDecimals} errorStyle={{ color: 'red', fontWeight: 'bold' }} />
<Form onSubmit={jest.fn()} component={TokenSupply} errorStyle={{ color: 'red', fontWeight: 'bold' }} />
)
expect(wrapper).toMatchSnapshot()
})
it(`should render TokenDecimals component and its children, with input field disabled`, () => {
it(`should render TokenSupply component and its children, with input field disabled`, () => {
const wrapper = mount(
<Form
onSubmit={jest.fn()}
component={TokenDecimals}
component={TokenSupply}
errorStyle={{ color: 'red', fontWeight: 'bold' }}
disabled={true}
/>
@ -35,27 +35,18 @@ describe('TokenDecimals', () => {
expect(wrapper).toMatchSnapshot()
})
it(`should give error if decimals is empty`, () => {
it(`should give error if value is negative`, () => {
const wrapper = mount(
<Form onSubmit={jest.fn()} component={TokenDecimals} errorStyle={{ color: 'red', fontWeight: 'bold' }} />
<Form onSubmit={jest.fn()} component={TokenSupply} errorStyle={{ color: 'red', fontWeight: 'bold' }} />
)
const input = wrapper.find('input[name="decimals"]')
input.simulate('change', { target: { value: '10' } })
expect(wrapper.find('InputField2').prop('meta').error).toBeFalsy()
const input = wrapper.find('input[name="supply"]')
input.simulate('change', { target: { value: '-10' } })
expect(wrapper.find('InputField2').prop('meta').error).toBe(VALIDATION_MESSAGES.POSITIVE)
input.simulate('change', { target: { value: '' } })
expect(wrapper.find('InputField2').prop('meta').error).toBe(VALIDATION_MESSAGES.REQUIRED)
expect(wrapper.find('InputField2').prop('meta').error).toBe(VALIDATION_MESSAGES.POSITIVE)
})
it(`should give error if decimals is greater than 18`, () => {
const wrapper = mount(
<Form onSubmit={jest.fn()} component={TokenDecimals} errorStyle={{ color: 'red', fontWeight: 'bold' }} />
)
const input = wrapper.find('input[name="decimals"]')
input.simulate('change', { target: { value: '21' } })
expect(wrapper.find('.error').text()).toBe('Should not be greater than 18')
})
})

View File

@ -1,21 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`TokenDecimals should render TokenDecimals component 1`] = `
exports[`TokenSupply should render TokenDecimals component 1`] = `
<div
className="left"
className="right"
>
<label
className="label"
htmlFor="decimals"
htmlFor="supply"
>
Decimals
Supply
</label>
<input
autoComplete="off"
className="input"
disabled={undefined}
id="decimals"
name="decimals"
id="supply"
name="supply"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
@ -26,7 +26,7 @@ exports[`TokenDecimals should render TokenDecimals component 1`] = `
<p
className="description"
>
Refers to how divisible a token can be, from 0 (not at all divisible) to 18 (pretty much continuous).
The total supply of the token
</p>
<span>
<p
@ -42,22 +42,22 @@ exports[`TokenDecimals should render TokenDecimals component 1`] = `
</div>
`;
exports[`TokenDecimals should render TokenDecimals component and its children 1`] = `
exports[`TokenSupply should render TokenSupply component and its children 1`] = `
<div
className="left"
className="right"
>
<label
className="label"
htmlFor="decimals"
htmlFor="supply"
>
Decimals
Supply
</label>
<input
autoComplete="off"
className="input"
disabled={undefined}
id="decimals"
name="decimals"
id="supply"
name="supply"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
@ -68,7 +68,7 @@ exports[`TokenDecimals should render TokenDecimals component and its children 1`
<p
className="description"
>
Refers to how divisible a token can be, from 0 (not at all divisible) to 18 (pretty much continuous).
The total supply of the token
</p>
<span>
<p
@ -84,7 +84,7 @@ exports[`TokenDecimals should render TokenDecimals component and its children 1`
</div>
`;
exports[`TokenDecimals should render TokenDecimals component and its children, with input field disabled 1`] = `
exports[`TokenSupply should render TokenSupply component and its children, with input field disabled 1`] = `
<ReactFinalForm
component={[Function]}
disabled={true}
@ -96,7 +96,7 @@ exports[`TokenDecimals should render TokenDecimals component and its children, w
}
onSubmit={[Function]}
>
<TokenDecimals
<TokenSupply
__versions={
Object {
"final-form": "4.6.1",
@ -117,7 +117,7 @@ exports[`TokenDecimals should render TokenDecimals component and its children, w
}
errors={
Object {
"decimals": "This field is required",
"supply": "Please enter a valid number greater than 0",
}
}
focus={[Function]}
@ -155,7 +155,7 @@ exports[`TokenDecimals should render TokenDecimals component and its children, w
submitting={false}
touched={
Object {
"decimals": false,
"supply": false,
}
}
valid={false}
@ -163,14 +163,13 @@ exports[`TokenDecimals should render TokenDecimals component and its children, w
values={Object {}}
visited={
Object {
"decimals": false,
"supply": false,
}
}
>
<Field
component={[Function]}
description="Refers to how divisible a token can be, from 0 (not at all divisible) to 18 (pretty much continuous)."
disabled={true}
description="The total supply of the token"
errorStyle={
Object {
"color": "red",
@ -178,16 +177,15 @@ exports[`TokenDecimals should render TokenDecimals component and its children, w
}
}
format={[Function]}
label="Decimals"
name="decimals"
label="Supply"
name="supply"
parse={[Function]}
side="left"
side="right"
type="text"
validate={[Function]}
>
<InputField2
description="Refers to how divisible a token can be, from 0 (not at all divisible) to 18 (pretty much continuous)."
disabled={true}
description="The total supply of the token"
errorStyle={
Object {
"color": "red",
@ -196,21 +194,21 @@ exports[`TokenDecimals should render TokenDecimals component and its children, w
}
input={
Object {
"name": "decimals",
"name": "supply",
"onBlur": [Function],
"onChange": [Function],
"onFocus": [Function],
"value": "",
}
}
label="Decimals"
label="Supply"
meta={
Object {
"active": false,
"data": Object {},
"dirty": false,
"dirtySinceLastSubmit": false,
"error": "This field is required",
"error": "Please enter a valid number greater than 0",
"initial": undefined,
"invalid": true,
"pristine": true,
@ -222,24 +220,23 @@ exports[`TokenDecimals should render TokenDecimals component and its children, w
"visited": false,
}
}
side="left"
side="right"
type="text"
>
<div
className="left"
className="right"
>
<label
className="label"
htmlFor="decimals"
htmlFor="supply"
>
Decimals
Supply
</label>
<input
autoComplete="off"
className="input"
disabled={true}
id="decimals"
name="decimals"
id="supply"
name="supply"
onBlur={[Function]}
onChange={[Function]}
onFocus={[Function]}
@ -249,7 +246,7 @@ exports[`TokenDecimals should render TokenDecimals component and its children, w
<p
className="description"
>
Refers to how divisible a token can be, from 0 (not at all divisible) to 18 (pretty much continuous).
The total supply of the token
</p>
<Error
errorStyle={
@ -258,11 +255,11 @@ exports[`TokenDecimals should render TokenDecimals component and its children, w
"fontWeight": "bold",
}
}
name="decimals"
name="supply"
>
<Field
format={[Function]}
name="decimals"
name="supply"
parse={[Function]}
render={[Function]}
subscription={
@ -290,6 +287,6 @@ exports[`TokenDecimals should render TokenDecimals component and its children, w
</div>
</InputField2>
</Field>
</TokenDecimals>
</TokenSupply>
</ReactFinalForm>
`;

View File

@ -5,7 +5,7 @@ exports[`ContributeForm Should set as disabled the contribute button if isTierSo
contributeStore={ContributeStore {}}
tokenStore={
TokenStore {
"decimals": undefined,
"decimals": 18,
"name": undefined,
"reservedTokensInput": Object {},
"supply": 0,
@ -149,7 +149,7 @@ exports[`ContributeForm Should set as disabled the contribute button if isTierSo
submitting={false}
tokenStore={
TokenStore {
"decimals": undefined,
"decimals": 18,
"name": undefined,
"reservedTokensInput": Object {},
"supply": 0,