From ebb97162f2ebb08831ef3b70b5b8a9e19f592397 Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Fri, 28 Jul 2017 13:31:08 +0200 Subject: [PATCH] Add unit tests for Tabs component --- src/components/tabs/index.test.js | 16 +++++++++++++ src/components/tabs/tabs.test.js | 39 +++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/components/tabs/index.test.js create mode 100644 src/components/tabs/tabs.test.js diff --git a/src/components/tabs/index.test.js b/src/components/tabs/index.test.js new file mode 100644 index 000000000..7e2c84f66 --- /dev/null +++ b/src/components/tabs/index.test.js @@ -0,0 +1,16 @@ +/* +import React from 'react'; +import { expect } from 'chai'; +import { mount } from 'enzyme'; +import { Provider } from 'react-redux'; +import store from '../../store'; +import TabsContainer from './index'; +import Tabs from './tabs'; + +describe('TabsContainer', () => { + it('should render Tabs component', () => { + const wrapper = mount(); + expect(wrapper.find(Tabs).exists()).to.equal(true); + }); +}); +*/ diff --git a/src/components/tabs/tabs.test.js b/src/components/tabs/tabs.test.js new file mode 100644 index 000000000..9e09da79f --- /dev/null +++ b/src/components/tabs/tabs.test.js @@ -0,0 +1,39 @@ +import React from 'react'; +import chai, { expect } from 'chai'; +import { mount } from 'enzyme'; +import { Tab, Tabs as ToolboxTabs } from 'react-toolbox'; +import sinon from 'sinon'; +import sinonChai from 'sinon-chai'; +import Tabs from './tabs'; + +chai.use(sinonChai); + +describe('Tabs', () => { + const history = { + location: { + pathname: '/main/voting', + }, + push: sinon.spy(), + }; + + it('should render react toolbox Tabs component', () => { + const wrapper = mount(); + expect(wrapper.find(ToolboxTabs).exists()).to.equal(true); + }); + + it('should render 3 Tab components if props.isDelegate', () => { + const wrapper = mount(); + expect(wrapper.find(Tab)).to.have.lengthOf(3); + }); + + it('should render 2 Tab components if !props.isDelegate', () => { + const wrapper = mount(); + expect(wrapper.find(Tab)).to.have.lengthOf(2); + }); + + it('should allow to change active tab', () => { + const wrapper = mount(); + wrapper.find(Tab).at(0).simulate('click'); + expect(history.push).to.have.been.calledWith('transactions'); + }); +});