import InputText from './'
import v from '../../config/variables'

describe('<InputText />', () => {
  let props, wrapper

  beforeEach(() => {
    props = {
      onChange: jest.fn()
    }
    wrapper = shallow(<InputText {...props} />)
  })

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

  it('should call the handler', () => {
    expect(props.onChange).toHaveBeenCalledTimes(0)
    wrapper.props().onChange({
      target: {
        value: 'p'
      }
    })

    wrapper.update()

    expect(props.onChange).toHaveBeenCalledTimes(1)
    expect(wrapper.props().value).toBe('p')
  })

  describe('<InputText textCenter />', () => {
    beforeEach(() => {
      props = {
        textCenter: true
      }
      wrapper = shallow(<InputText {...props} />)
    })

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

  describe('<InputText textCenter />', () => {
    beforeEach(() => {
      props = {
        disabled: true
      }
      wrapper = shallow(<InputText {...props} />)
    })

    it('should render the styles correctly', () => {
      expect(wrapper).toHaveStyleRule('background', v.input.disabled.backgroundColor)
    })
  })

  describe('<InputText textCenter />', () => {
    beforeEach(() => {
      props = {
        readOnly: true
      }
      wrapper = shallow(<InputText {...props} />)
    })

    it('should render the styles correctly', () => {
      expect(wrapper).toHaveStyleRule('background', v.input.disabled.backgroundColor)
    })
  })

  describe('<InputText textCenter />', () => {
    beforeEach(() => {
      props = {
        size: 'small'
      }
      wrapper = shallow(<InputText {...props} />)
    })

    it('should render the styles correctly', () => {
      expect(wrapper).toHaveStyleRule('padding', `${v.sizeDivisor[props.size]}px ${v.sizeDivisor[props.size] * 2}px`)
    })
  })
})
