import React from 'react'; import sinon from 'sinon'; import { shallow, ShallowWrapper } from 'enzyme'; import Button from '../../button/Button'; import PlainButton from '../../plain-button/PlainButton'; import Collapsible from '..'; describe('components/collapsible/Collapsible', () => { let wrapper: ShallowWrapper; beforeEach(() => { wrapper = shallow( foobar , ); }); test('should render component correctly', () => { expect(wrapper).toMatchSnapshot(); }); test('should toggle visibility on click', () => { wrapper.find('.collapsible-card-title').simulate('click'); expect(wrapper.state('isOpen')).toBeFalsy(); wrapper.find('.collapsible-card-title').simulate('click'); expect(wrapper.state('isOpen')).toBeTruthy(); }); test('should render with headerActionItems', () => { wrapper = shallow( Click Here} isOpen={false} title="foo"> foobar , ); expect(wrapper).toMatchSnapshot(); }); test('should apply correct border class', () => { wrapper = shallow( foobar , ); expect(wrapper).toMatchSnapshot(); }); test('should apply correct isOpen state', () => { wrapper = shallow( foobar , ); expect(wrapper).toMatchSnapshot(); }); test('should apply buttonProps correctly', () => { wrapper = shallow( foobar , ); expect(wrapper).toMatchSnapshot(); }); test('should render a PlainButton if a button is passed in', () => { wrapper = shallow( } title="foo"> foobar , ); expect(wrapper).toMatchSnapshot(); }); test('should not render a PlainButton if a button is not passed in', () => { wrapper = shallow( foobar , ); expect(wrapper).toMatchSnapshot(); }); test('should fire open and close handlers', () => { const closeSpy = sinon.spy(); const openSpy = sinon.spy(); wrapper = shallow( foobar , ); expect(closeSpy.notCalled).toBe(true); expect(openSpy.notCalled).toBe(true); wrapper.find('.collapsible-card-title').simulate('click'); expect(closeSpy.calledOnce).toBe(true); expect(openSpy.notCalled).toBe(true); wrapper.find('.collapsible-card-title').simulate('click'); expect(closeSpy.calledOnce).toBe(true); expect(openSpy.calledOnce).toBe(true); }); });