import { DropdownItem, Icon } from '../'
import v from '../../config/variables'

describe('<DropdownItem />', () => {
  let wrapper, props
  beforeEach(() => {
    props = {
      children: 'Lorem'
    }
    wrapper = shallow(<DropdownItem {...props} />)
  })

  it('should render correctly', () => {
    expect(wrapper).toHaveLength(1)
    expect(wrapper).toMatchSnapshot()
  })

  it('should render the right style', () => {
    expect(wrapper).toHaveStyleRule('color', v.dropDownItem.color)
  })

  it('should have a undefined href', () => {
    expect(wrapper.props().href).toBeUndefined()
  })

  describe('<DropdownItem textCenter />', () => {
    beforeEach(() => {
      props = {
        children: 'Lorem',
        textCenter: true
      }

      wrapper = shallow(<DropdownItem {...props} />)
    })

    it('should render the right style', () => {
      expect(wrapper).toHaveStyleRule('text-align', 'center')
    })
  })

  describe('<DropdownItem icon="coffee" />', () => {
    beforeEach(() => {
      props = {
        children: 'Lorem',
        icon: 'coffee'
      }

      wrapper = shallow(<DropdownItem {...props} />)
    })

    it('should render the icon', () => {
      expect(wrapper.find(Icon)).toHaveLength(1)
    })
  })

  describe('<DropdownItem to="/" />', () => {
    beforeEach(() => {
      props = {
        children: 'Lorem',
        to: '/'
      }

      wrapper = shallow(<DropdownItem {...props} />)
    })

    it('should have a href', () => {
      expect(wrapper.props().href).toBe(props.to)
    })
  })

  describe('<DropdownItem onPress />', () => {
    beforeEach(() => {
      props = {
        children: 'Lorem',
        onPress: jest.fn()
      }

      wrapper = shallow(<DropdownItem {...props} />)
    })

    it('should have a onPress', () => {
      expect(props.onPress).not.toHaveBeenCalled()
      wrapper.simulate('click')
      expect(props.onPress).toHaveBeenCalledTimes(1)
    })
  })

  describe('<DropdownItem /> with onPress and to', () => {
    beforeEach(() => {
      props = {
        children: 'Lorem',
        to: '/',
        onPress: jest.fn()
      }

      wrapper = shallow(<DropdownItem {...props} />)
    })

    it('should have a undefined onPress', () => {
      expect(wrapper.props().href).toBe(props.to)
      expect(wrapper.props().onClick).toBeUndefined()
    })
  })
})
