UNPKG

yoda-common-boilerplate

Version:

Repository of all JCP reusable atoms, molecules and organisms

72 lines (58 loc) 2.43 kB
import React from 'react'; import { shallow, mount } from 'enzyme'; import { expect } from 'chai'; import sinon from 'sinon'; import 'ignore-styles'; import Accordion from '../Accordion.jsx'; const siteConfig = { elements: [ { 'title': 'Element 1',       'content': 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',       'showOnLoad': true     }, {   'title': 'Element 2',       'content': 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',       'showOnLoad': true   } ] }; describe('<Accordion />', () => { let wrapper; beforeEach(() => { wrapper = mount(<Accordion defaultShow={1} elements={siteConfig.elements} />)   });  it('Accordion component should exist ', () => { expect(wrapper).to.exist; }); it.skip('Accordion component should exist ', () => { expect(wrapper.type()).to.equal('div'); }); it('should have deafult props passed', () => { expect(wrapper.state().active).to.equal(false); expect(wrapper.state().activeIndex).to.equal(1); }); it('should have two panes in accordion', () => { expect(wrapper.find('AccordionSub')).to.have.length(2); }); it('should have two accordion-box in accordion', () => { expect(wrapper.find('.accordion-box')).to.have.length(2); }); it('should toggle on click of the exact heading if its already open', () => { const toggle = sinon.spy(); const selectedIndex = sinon.spy(); wrapper.find('.accordion-box h3').at(0).simulate('click',{ id : 1 }); expect(toggle(1)).to.have.been.called; expect(selectedIndex(1)).to.have.been.called; expect(wrapper.state().activeIndex).to.equal(0); }); it('should toggle on click of the other heading if its already not open', () => { const toggle = sinon.spy(); const selectedIndex = sinon.spy(); wrapper.find('.accordion-box h3').at(1).simulate('click', { id : 2 }); expect(toggle(2)).to.have.been.called; expect(selectedIndex(2)).to.have.been.called; expect(wrapper.state().activeIndex).to.equal(2); }); });