import Dropdown from './';
import v from '../../config/variables';
describe('<Dropdown />', () => {
  let wrapper, props;
  beforeEach(() => {
    props = {
      title: 'Lorem',
      open: false
    };
    wrapper = shallow(React.createElement(Dropdown, props));
  });
  it('should render correctly', () => {
    expect(wrapper).toHaveLength(1);
    expect(wrapper).toMatchSnapshot();
  });
  it('should have the right icon', () => {
    expect(wrapper.instance().caretIcon).toBe('angle-down');
  });
  it('should not render the content', () => {
    expect(wrapper.find('DropdownInner')).toHaveLength(0);
  });
  it('should render the right style', () => {
    expect(wrapper).toHaveStyleRule('cursor', v.dropdown.cursor);
  });
  it('should have an undefined onClick', () => {
    expect(wrapper.children().children().first().props().onClick).toBeUndefined();
  });
  describe('<Dropdown /> opened', () => {
    beforeEach(() => {
      props = {
        title: 'Lorem',
        open: true
      };
      wrapper = shallow(React.createElement(Dropdown, props));
    });
    it('should have the right icon', () => {
      expect(wrapper.instance().caretIcon).toBe('angle-up');
    });
    it('should render the content', () => {
      expect(wrapper.find('DropdownInner')).toHaveLength(1);
    });
  });
  describe('<Dropdown disabled />', () => {
    beforeEach(() => {
      props = {
        title: 'Lorem',
        disabled: true
      };
      wrapper = shallow(React.createElement(Dropdown, props));
    });
    it('should render the right style', () => {
      expect(wrapper).toHaveStyleRule('cursor', v.dropdown.disabled.cursor);
    });
  });
  describe('<Dropdown /> with events', () => {
    beforeEach(() => {
      props = {
        title: 'Lorem',
        open: false,
        onToggle: jest.fn(),
        onOpen: jest.fn(),
        onClose: jest.fn()
      };
      wrapper = shallow(React.createElement(Dropdown, props));
    });
    it('should call the handlers', () => {
      wrapper.find('DropdownTitle').simulate('click');
      expect(props.onOpen).toHaveBeenCalledTimes(1);
      expect(props.onToggle).toHaveBeenCalledTimes(1);
      expect(props.onClose).toHaveBeenCalledTimes(0);
      wrapper.find('DropdownTitle').simulate('click');
      expect(props.onOpen).toHaveBeenCalledTimes(1);
      expect(props.onToggle).toHaveBeenCalledTimes(2);
      expect(props.onClose).toHaveBeenCalledTimes(1);
    });
  });
  describe('<Dropdown /> with events', () => {
    beforeEach(() => {
      props = {
        title: 'Lorem',
        disabled: true,
        open: false,
        onToggle: jest.fn(),
        onOpen: jest.fn(),
        onClose: jest.fn()
      };
      wrapper = shallow(React.createElement(Dropdown, props));
    });
    it('should call the handlers', () => {
      wrapper.find('DropdownTitle').simulate('click');
      expect(props.onOpen).toHaveBeenCalledTimes(0);
      expect(props.onToggle).toHaveBeenCalledTimes(0);
      expect(props.onClose).toHaveBeenCalledTimes(0);
    });
  });
});