-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1078 from dennis00010011b/tests-react-components
Tests react components
- Loading branch information
Showing
31 changed files
with
4,558 additions
and
96 deletions.
There are no files selected for viewing
Submodule token-wizard-test-automation
updated
25 files
+1 −1 | entity/Logger.js | |
+488 −484 | entity/User.js | |
+1 −1 | package.json | |
+13 −22 | pages/ContributionPage.js | |
+2 −2 | pages/Page.js | |
+473 −473 | pages/TierPage.js | |
+2 −2 | scenarios/scenarioE2eDutchWhitelistShort.json | |
+38 −38 | test/e2eDutch.js | |
+38 −60 | test/e2eDutchMincap.js | |
+460 −489 | test/e2eDutchWhitelist.js | |
+53 −53 | test/e2eMinted.js | |
+688 −757 | test/e2eMintedMincap.js | |
+2 −2 | test/e2eMintedRopsten.js | |
+735 −763 | test/e2eMintedWhitelist.js | |
+1 −1 | test/funcDutchRateTime.js | |
+1 −1 | test/testDecimalsDutchCap.js | |
+1 −1 | test/testDecimalsDutchWhitelist.js | |
+1 −1 | test/testDecimalsMintedCap.js | |
+19 −19 | test/testDecimalsMintedWhitelist.js | |
+1 −1 | test/testReservedHowManyMinted.js | |
+1 −1 | test/testWhitelistDutch.js | |
+1 −1 | test/testWhitelistMinted.js | |
+5 −0 | users/ropsten/user4_56B2.json | |
+773 −788 | utils/Utils.js | |
+17 −2 | utils/constants.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import React from 'react' | ||
import { CrowdsaleEndTime } from '../../../src/components/Common/CrowdsaleEndTime' | ||
import { Form } from 'react-final-form' | ||
import Adapter from 'enzyme-adapter-react-15' | ||
import { configure, mount } from 'enzyme' | ||
import renderer from 'react-test-renderer' | ||
import { VALIDATION_MESSAGES, TEXT_FIELDS, DESCRIPTION } from '../../../src/utils/constants' | ||
import MockDate from 'mockdate' | ||
|
||
configure({ adapter: new Adapter() }) | ||
const DECRIPTION = DESCRIPTION.END_TIME | ||
const LABEL = TEXT_FIELDS.END_TIME | ||
|
||
describe('CrowdsaleEndTime', () => { | ||
const TIMESTAMPS = { | ||
CURRENT_TIME: 1520852400000, | ||
PLUS_5_MINUTES: 1520852700000, | ||
PLUS_10_MINUTES: 1520853000000, | ||
PLUS_10_DAYS: 1521716400000, | ||
MINUS_5_MINUTES: 1520852100000, | ||
MINUS_10_DAYS: 1519988400000 | ||
} | ||
const crowdsale = { tiers: [{ startTime: 0, endTime: 0 }] } | ||
beforeEach(() => { | ||
MockDate.set(TIMESTAMPS.CURRENT_TIME) | ||
crowdsale.tiers[0].startTime = TIMESTAMPS.PLUS_10_MINUTES | ||
crowdsale.tiers[0].endTime = TIMESTAMPS.PLUS_10_DAYS | ||
}) | ||
afterEach(() => { | ||
MockDate.reset() | ||
crowdsale.tiers[0].startTime = 0 | ||
crowdsale.tiers[0].endTime = 0 | ||
}) | ||
|
||
describe('Rendering', () => { | ||
it(`should render CrowdsaleEndTime component`, () => { | ||
const wrapper = renderer.create( | ||
<Form | ||
onSubmit={jest.fn()} | ||
initialValues={crowdsale} | ||
render={() => ( | ||
<CrowdsaleEndTime | ||
name="tiers[0].endTime" | ||
index="0" | ||
disabled={false} | ||
errorStyle={{ color: 'red', fontWeight: 'bold' }} | ||
/> | ||
)} | ||
/> | ||
) | ||
expect(wrapper).toMatchSnapshot() | ||
}) | ||
|
||
it(`should render CrowdsaleEndTime component if field is disabled`, () => { | ||
const wrapper = renderer.create( | ||
<Form | ||
onSubmit={jest.fn()} | ||
initialValues={crowdsale} | ||
render={() => ( | ||
<CrowdsaleEndTime | ||
name="tiers[0].endTime" | ||
index="0" | ||
disabled={true} | ||
errorStyle={{ color: 'red', fontWeight: 'bold' }} | ||
/> | ||
)} | ||
/> | ||
) | ||
expect(wrapper).toMatchSnapshot() | ||
}) | ||
|
||
it(`should be proper label and description`, () => { | ||
const wrapper = mount( | ||
<Form | ||
onSubmit={jest.fn()} | ||
initialValues={crowdsale} | ||
render={() => ( | ||
<CrowdsaleEndTime | ||
name="tiers[0].endTime" | ||
index="0" | ||
disabled={false} | ||
errorStyle={{ color: 'red', fontWeight: 'bold' }} | ||
/> | ||
)} | ||
/> | ||
) | ||
const label = wrapper.find('label') | ||
expect(label.text()).toBe(LABEL) | ||
const descript = wrapper.find('p[className="description"]') | ||
expect(descript.text()).toBe(DECRIPTION) | ||
}) | ||
}) | ||
|
||
describe('Date validations', () => { | ||
let wrapper = undefined | ||
|
||
beforeEach(() => { | ||
wrapper = mount( | ||
<Form | ||
onSubmit={jest.fn()} | ||
initialValues={crowdsale} | ||
render={() => ( | ||
<CrowdsaleEndTime | ||
name="tiers[0].endTime" | ||
index="0" | ||
disabled={false} | ||
errorStyle={{ color: 'red', fontWeight: 'bold' }} | ||
/> | ||
)} | ||
/> | ||
) | ||
}) | ||
|
||
it(`shouldn't be errors if value is correct`, () => { | ||
const input = wrapper.find('input[name="tiers[0].endTime"]') | ||
input.simulate('change', { target: { value: TIMESTAMPS.PLUS_10_DAYS } }) | ||
const inputProps = wrapper.find('InputField2').props() | ||
expect(inputProps.meta.error).toBeUndefined() | ||
}) | ||
it(`should fail if value is empty`, () => { | ||
const input = wrapper.find('input[name="tiers[0].endTime"]') | ||
input.simulate('change', { target: { value: '' } }) | ||
const inputProps = wrapper.find('InputField2').props() | ||
expect(inputProps.meta.error[0]).toBe(VALIDATION_MESSAGES.REQUIRED) | ||
}) | ||
it(`should fail if endTime is previous than current time`, () => { | ||
const input = wrapper.find('input[name="tiers[0].endTime"]') | ||
input.simulate('change', { target: { value: TIMESTAMPS.MINUS_5_MINUTES } }) | ||
const inputProps = wrapper.find('InputField2').props() | ||
expect(inputProps.meta.error[0]).toBe(VALIDATION_MESSAGES.DATE_IN_FUTURE) | ||
}) | ||
|
||
it(`should fail if endTime is earlier than startTime`, () => { | ||
const input = wrapper.find('input[name="tiers[0].endTime"]') | ||
input.simulate('change', { target: { value: TIMESTAMPS.PLUS_5_MINUTES } }) | ||
const inputProps = wrapper.find('InputField2').props() | ||
expect(inputProps.meta.error[0]).toBe("Should be later than same tier's Start Time") | ||
}) | ||
it(`should fail if endTime is same with startTime`, () => { | ||
const input = wrapper.find('input[name="tiers[0].endTime"]') | ||
input.simulate('change', { target: { value: TIMESTAMPS.PLUS_10_MINUTES } }) | ||
const inputProps = wrapper.find('InputField2').props() | ||
expect(inputProps.meta.error[0]).toBe("Should be later than same tier's Start Time") | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React from 'react' | ||
import { CrowdsaleRate } from '../../../src/components/Common/CrowdsaleRate' | ||
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,DESCRIPTION } from '../../../src/utils/constants' | ||
import {Supply} from "../../../src/components/Common/Supply"; | ||
|
||
configure({ adapter: new Adapter() }) | ||
|
||
const LABEL = `Rate` | ||
describe('CrowdsaleRate ', () => { | ||
it(`should render CrowdsaleRate component`, () => { | ||
let input = { | ||
name: 'CrowdsaleRate', | ||
disabled: false, | ||
value: '1234' | ||
} | ||
const wrapper = renderer.create( | ||
<Form | ||
onSubmit={jest.fn()} | ||
component={CrowdsaleRate} | ||
disabled={false} | ||
input={input} | ||
/> | ||
) | ||
expect(wrapper).toMatchSnapshot() | ||
}) | ||
it(`should be proper label and description`, () => { | ||
const wrapper = mount( | ||
<Form | ||
onSubmit={jest.fn()} component={CrowdsaleRate} | ||
disabled={false} name="rate" | ||
/> | ||
) | ||
let node = wrapper.find('label') | ||
expect(node.text()).toBe(LABEL) | ||
node = wrapper.find('p[className="description"]') | ||
expect(node.text()).toBe(DESCRIPTION.RATE) | ||
}) | ||
}) | ||
describe('CrowdsaleRate ', () => { | ||
const wrapper = mount( | ||
<Form | ||
onSubmit={jest.fn()} component={CrowdsaleRate} name='rate' | ||
/> | ||
) | ||
const input = wrapper.find('input[name="rate"]') | ||
it(`should give 3 errors if value is empty`, () => { | ||
input.simulate('change', { target: { value: '' } }) | ||
expect(wrapper.find('InputField2').props().meta.error.length).toBe(3) | ||
}) | ||
it(`should give error if value is not positive`, () => { | ||
input.simulate('change', { target: { value: '-10' } }) | ||
expect(wrapper.find('InputField2').props().meta.error[0]).toBe(VALIDATION_MESSAGES.POSITIVE) | ||
}) | ||
it(`should give error if value is not integer`, () => { | ||
input.simulate('change', { target: { value: '1.0001' } }) | ||
expect(wrapper.find('InputField2').props().meta.error[0]).toBe(VALIDATION_MESSAGES.INTEGER) | ||
}) | ||
it(`should give error if value is greater than 1e18`, () => { | ||
input.simulate('change', { target: { value: '1000000000000000001'} }) | ||
expect(wrapper.find('InputField2').props().meta.error[0]).toBe('Should not be greater than 1 quintillion (10^18)') | ||
}) | ||
it(`should give 3 errors if value is not numberic`, () => { | ||
input.simulate('change', { target: { value: 'asdfg'} }) | ||
expect(wrapper.find('InputField2').props().meta.error.length).toBe(3) | ||
}) | ||
it(`shouldn't give 3 errors if value is correct`, () => { | ||
input.simulate('change', { target: { value: 'asdfg'} }) | ||
expect(wrapper.find('InputField2').props().meta.error.length).toBe(3) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import React from 'react' | ||
import { CrowdsaleStartTime } from '../../../src/components/Common/CrowdsaleStartTime' | ||
import { Form } from 'react-final-form' | ||
import Adapter from 'enzyme-adapter-react-15' | ||
import { configure, mount } from 'enzyme' | ||
import renderer from 'react-test-renderer' | ||
import { VALIDATION_MESSAGES, TEXT_FIELDS, DESCRIPTION } from '../../../src/utils/constants' | ||
import MockDate from 'mockdate' | ||
|
||
configure({ adapter: new Adapter() }) | ||
const DECRIPTION = DESCRIPTION.START_TIME | ||
const LABEL = TEXT_FIELDS.START_TIME | ||
|
||
describe('CrowdsaleStartTime', () => { | ||
const TIMESTAMPS = { | ||
CURRENT_TIME: 1520852400000, | ||
PLUS_5_MINUTES: 1520852700000, | ||
PLUS_10_MINUTES: 1520853000000, | ||
PLUS_10_DAYS: 1521716400000, | ||
MINUS_5_MINUTES: 1520852100000, | ||
MINUS_10_DAYS: 1519988400000 | ||
} | ||
const crowdsale = { tiers: [{ startTime: 0, endTime: 0 }] } | ||
beforeEach(() => { | ||
MockDate.set(TIMESTAMPS.CURRENT_TIME) | ||
crowdsale.tiers[0].startTime = TIMESTAMPS.PLUS_5_MINUTES | ||
crowdsale.tiers[0].endTime = TIMESTAMPS.PLUS_10_MINUTES | ||
}) | ||
afterEach(() => { | ||
MockDate.reset() | ||
crowdsale.tiers[0].startTime = 0 | ||
crowdsale.tiers[0].endTime = 0 | ||
}) | ||
|
||
describe('Rendering', () => { | ||
it(`should render CrowdsaleStartTime component`, () => { | ||
const wrapper = renderer.create( | ||
<Form | ||
onSubmit={jest.fn()} | ||
initialValues={crowdsale} | ||
render={() => ( | ||
<CrowdsaleStartTime | ||
name="tiers[0].startTime" | ||
index="0" | ||
disabled={false} | ||
errorStyle={{ color: 'red', fontWeight: 'bold' }} | ||
/> | ||
)} | ||
/> | ||
) | ||
expect(wrapper).toMatchSnapshot() | ||
}) | ||
|
||
it(`should render CrowdsaleStartTime component if field is disabled`, () => { | ||
const wrapper = renderer.create( | ||
<Form | ||
onSubmit={jest.fn()} | ||
initialValues={crowdsale} | ||
render={() => ( | ||
<CrowdsaleStartTime | ||
name="tiers[0].startTime" | ||
index="0" | ||
disabled={true} | ||
errorStyle={{ color: 'red', fontWeight: 'bold' }} | ||
/> | ||
)} | ||
/> | ||
) | ||
expect(wrapper).toMatchSnapshot() | ||
}) | ||
|
||
it(`should be proper label and description`, () => { | ||
const wrapper = mount( | ||
<Form | ||
onSubmit={jest.fn()} | ||
initialValues={crowdsale} | ||
render={() => ( | ||
<CrowdsaleStartTime | ||
name="tiers[0].startTime" | ||
index="0" | ||
disabled={false} | ||
errorStyle={{ color: 'red', fontWeight: 'bold' }} | ||
/> | ||
)} | ||
/> | ||
) | ||
const label = wrapper.find('label') | ||
expect(label.text()).toBe(LABEL) | ||
const descript = wrapper.find('p[className="description"]') | ||
expect(descript.text()).toBe(DECRIPTION) | ||
}) | ||
}) | ||
|
||
describe('Date validations', () => { | ||
let wrapper = undefined | ||
|
||
beforeEach(() => { | ||
wrapper = mount( | ||
<Form | ||
onSubmit={jest.fn()} | ||
initialValues={crowdsale} | ||
render={() => ( | ||
<CrowdsaleStartTime | ||
name="tiers[0].startTime" | ||
index="0" | ||
disabled={false} | ||
errorStyle={{ color: 'red', fontWeight: 'bold' }} | ||
/> | ||
)} | ||
/> | ||
) | ||
}) | ||
|
||
it(`shouldn't give errors if value is correct`, () => { | ||
const input = wrapper.find('input[name="tiers[0].startTime"]') | ||
input.simulate('change', { target: { value: TIMESTAMPS.PLUS_5_MINUTES } }) | ||
const inputProps = wrapper.find('InputField2').props() | ||
expect(inputProps.meta.error).toBeUndefined() | ||
}) | ||
it(`should fail if value is empty`, () => { | ||
const input = wrapper.find('input[name="tiers[0].startTime"]') | ||
input.simulate('change', { target: { value: '' } }) | ||
const inputProps = wrapper.find('InputField2').props() | ||
expect(inputProps.meta.error[0]).toBe(VALIDATION_MESSAGES.REQUIRED) | ||
}) | ||
it(`should fail if startTime is previous than current time`, () => { | ||
const input = wrapper.find('input[name="tiers[0].startTime"]') | ||
input.simulate('change', { target: { value: TIMESTAMPS.MINUS_5_MINUTES } }) | ||
const inputProps = wrapper.find('InputField2').props() | ||
expect(inputProps.meta.error[0]).toBe(VALIDATION_MESSAGES.DATE_IN_FUTURE) | ||
}) | ||
|
||
it(`should fail if startTime is later than endTime`, () => { | ||
const input = wrapper.find('input[name="tiers[0].startTime"]') | ||
input.simulate('change', { target: { value: TIMESTAMPS.PLUS_10_DAYS } }) | ||
const inputProps = wrapper.find('InputField2').props() | ||
expect(inputProps.meta.error[0]).toBe("Should be previous than same tier's End Time") | ||
}) | ||
it(`should fail if startTime is the same with endTime`, () => { | ||
const input = wrapper.find('input[name="tiers[0].startTime"]') | ||
input.simulate('change', { target: { value: TIMESTAMPS.PLUS_10_MINUTES } }) | ||
const inputProps = wrapper.find('InputField2').props() | ||
expect(inputProps.meta.error[0]).toBe("Should be previous than same tier's End Time") | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.