Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Add more unit tests for forging components
Browse files Browse the repository at this point in the history
  • Loading branch information
slaweet committed Jul 21, 2017
1 parent 4c62223 commit 2e64149
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/components/forging/delegateStats.test.js
@@ -0,0 +1,29 @@
import React from 'react';
import chai, { expect } from 'chai';
import sinonChai from 'sinon-chai';
import { mount } from 'enzyme';
import DelegateStats from './delegateStats';

chai.use(sinonChai);

describe('<DelegateStats />', () => {
const delegate = {
username: 'genesis_17',
rate: 19,
approval: 30,
productivity: 99.2,
};
let wrapper;

beforeEach(() => {
wrapper = mount(<DelegateStats delegate={delegate} />);
});

it('should render 3 Card components', () => {
expect(wrapper.find('Card')).to.have.lengthOf(3);
});

it('should render 3 CircularProgressbar components', () => {
expect(wrapper.find('svg.CircularProgressbar')).to.have.lengthOf(3);
});
});
42 changes: 42 additions & 0 deletions src/components/forging/forgingComponent.test.js
@@ -0,0 +1,42 @@
import React from 'react';
import chai, { expect } from 'chai';
import sinonChai from 'sinon-chai';
import { mount } from 'enzyme';
import ForgingComponent from './forgingComponent';

chai.use(sinonChai);


describe('<ForgingComponent />', () => {
let wrapper;
const props = {
account: {
delegate: {},
},
peers: {},
statistics: {},
forgedBlocks: [],
loadStats: () => {},
loadForgedBlocks: () => {},
};

beforeEach(() => {
wrapper = mount(<ForgingComponent {...props} />);
});

it('should render <ForgingTitle/>', () => {
expect(wrapper.find('ForgingTitle')).to.have.lengthOf(1);
});

it('should render <ForgingStats/>', () => {
expect(wrapper.find('ForgingStats')).to.have.lengthOf(1);
});

it('should render <DelegateStats/>', () => {
expect(wrapper.find('DelegateStats')).to.have.lengthOf(1);
});

it('should render <ForgedBlocks/>', () => {
expect(wrapper.find('ForgedBlocks')).to.have.lengthOf(1);
});
});
52 changes: 52 additions & 0 deletions src/components/forging/forgingStats.test.js
@@ -0,0 +1,52 @@
import React from 'react';
import chai, { expect } from 'chai';
import sinonChai from 'sinon-chai';
import { mount } from 'enzyme';
import ForgingStats from './forgingStats';

chai.use(sinonChai);


describe('<ForgingStats />', () => {
const account = {
delegate: {
username: 'genesis_17',
rate: 19,
approval: 30,
productivity: 99.2,
},
};
const statistics = {
last24h: 321317,
last7d: 3213179124,
last30d: 321317912423,
last365d: 32131791242342,
};
const loadStats = () => {};
let wrapper;

beforeEach(() => {
wrapper = mount(<ForgingStats account={account} statistics={statistics}
loadStats={loadStats} />);
});

it('should render 4 Card components', () => {
expect(wrapper.find('Card')).to.have.lengthOf(4);
});

it('should render Card component for Last 24 hours', () => {
expect(wrapper.find('Card').at(0).text().trim()).to.equal('Last 24 hours 0.00321317 LSK');
});

it('should render Card component for Last 7 days', () => {
expect(wrapper.find('Card').at(1).text().trim()).to.equal('Last 7 days 32.13179124 LSK');
});

it('should render Card component for Last 30 days', () => {
expect(wrapper.find('Card').at(2).text().trim()).to.equal('Last 30 days 3,213.17912423 LSK');
});

it('should render Card component for Last 365 days', () => {
expect(wrapper.find('Card').at(3).text().trim()).to.equal('Last 365 days 321,317.91242342 LSK');
});
});
37 changes: 37 additions & 0 deletions src/components/forging/forgingTitle.test.js
@@ -0,0 +1,37 @@
import React from 'react';
import chai, { expect } from 'chai';
import sinonChai from 'sinon-chai';
import { mount } from 'enzyme';
import ForgingTitle from './forgingTitle';

chai.use(sinonChai);


describe('<ForgingTitle />', () => {
const account = {
delegate: {
username: 'genesis_17',
rate: 19,
approval: 30,
productivity: 99.2,
},
};
const statistics = {
total: 132423,
};
const loadStats = () => {};
let wrapper;

beforeEach(() => {
wrapper = mount(<ForgingTitle
account={account} statistics={statistics} loadStats={loadStats}/>);
});

it('should render 1 Card component', () => {
expect(wrapper.find('Card')).to.have.lengthOf(1);
});

it('should render h2 with delegate name', () => {
expect(wrapper.find('h2').text()).to.equal(account.delegate.username);
});
});
2 changes: 1 addition & 1 deletion src/components/forging/index.js
Expand Up @@ -11,7 +11,7 @@ const mapStateToProps = state => ({
});

const mapDispatchToProps = dispatch => ({
loadForgedBlocks: (activePeer, limit = 10, offset = 0, generatorPublicKey) => {
loadForgedBlocks: (activePeer, limit, offset, generatorPublicKey) => {
getForgedBlocks(activePeer, limit, offset, generatorPublicKey).then((data) => {
dispatch(updateForgedBlocks(data.blocks));
});
Expand Down
22 changes: 22 additions & 0 deletions src/components/forging/index.test.js
@@ -0,0 +1,22 @@
import React from 'react';
import chai, { expect } from 'chai';
import sinonChai from 'sinon-chai';
import { mount } from 'enzyme';
import { Provider } from 'react-redux';
import Forging from './';
import store from '../../store';

chai.use(sinonChai);


describe('<Forging />', () => {
let wrapper;

beforeEach(() => {
wrapper = mount(<Provider store={store}><Forging /></Provider>);
});

it('should render 1 <ForgingComponent/>', () => {
expect(wrapper.find('ForgingComponent')).to.have.lengthOf(1);
});
});

0 comments on commit 2e64149

Please sign in to comment.