react-conventions
Version:
An open source set of React components that implement Ambassador's Design and UX patterns.
56 lines (42 loc) • 1.82 kB
JavaScript
import React from 'react'
import { shallow, mount } from 'enzyme'
import Tab from '../src/components/TabWrapper/Tab'
describe('Tab', () => {
let wrapper;
it('should shallow render itself', () => {
wrapper = shallow(<Tab title="Test Tab" />);
expect(wrapper.hasClass('tab')).to.equal(true);
expect(wrapper.hasClass('active')).to.equal(false);
expect(wrapper.find('span')).to.have.length(0);
expect(wrapper.text().trim()).to.equal('Test Tab');
});
it('should have active state when the active property is set to true', () => {
wrapper = shallow(<Tab title="Test Tab" active={true} />);
expect(wrapper.hasClass('tab')).to.equal(true);
expect(wrapper.hasClass('active')).to.equal(true);
expect(wrapper.find('span')).to.have.length(0);
expect(wrapper.text().trim()).to.equal('Test Tab');
});
it('should render the count if the count property is provided', () => {
wrapper = shallow(<Tab title="Test Tab" count={1234} />);
expect(wrapper.hasClass('tab')).to.equal(true);
expect(wrapper.hasClass('active')).to.equal(false);
expect(wrapper.find('span')).to.have.length(1);
expect(wrapper.text().trim()).to.equal('Test Tab (1.234)');
});
it('should trigger a callback when clicked if the callback is provided', () => {
let callbackTriggered = false;
function callback() {
callbackTriggered = true;
};
wrapper = mount(<Tab title="Test Tab With Count" onClick={callback} />);
wrapper.simulate('click');
expect(callbackTriggered).to.be.true;
});
it('should not cause an error when clicked if the callback is not provided', () => {
let callbackTriggered = false;
wrapper = mount(<Tab title="Test Tab With Count" />);
wrapper.simulate('click');
expect(callbackTriggered).to.be.false;
});
});