describe 'Select Input Custom', ->
  SelectInputCustom = React.createFactory require('../../src/components/select_input_custom')

  spy = sinon.spy()
  chld = null
  props =
    options: [
      {
        optValue: 123
        label: 'Number one'
      }
      {
        optValue: 4321
        label: 'Number two'
      }
      {
        optValue: 6126
        label: 'Number three'
      }
      {
        optValue: 651
        label: 'Number four'
      }
    ]
    onChange: spy
    labelField: 'label'
    valueField: 'optValue'
    selectText: 'This is the first choice'
    returnFullObjects: true

  before ->
    cmp = renderIntoDocument ContextWrapper {
      factory: SelectInputCustom
      childProps: props
    }
    chld = cmp.getInput()

  beforeEach ->
    spy.reset()

  it 'should render a select component', ->
    el = findRenderedDOMComponentWithTag(chld, 'select')
    expect(el).to.be.ok

  it 'should render a set of options equal to length of input array, plus default option', ->
    el = scryRenderedDOMComponentsWithTag(chld, 'option')
    expect(el.length).to.equal(props.options.length + 1)

  it 'should use insert the selectText value as the first option', ->
    el = scryRenderedDOMComponentsWithTag(chld, 'option')
    expect(el[0].innerHTML).to.equal(props.selectText)

  it 'should use a custom valueField and labelField properties to determine option labels', ->
    el = scryRenderedDOMComponentsWithTag(chld, 'option')
    expect(el[1].innerHTML).to.equal(props.options[0][props.labelField])
    expect(el[1].value).to.equal(props.options[0][props.valueField].toString())

  it 'should render a Clear button ONLY when a value is selected', ->
    props.value = props.options[0]
    
    cmp = renderIntoDocument ContextWrapper {
      factory: SelectInputCustom
      childProps: props
    }
    chld = cmp.getInput()

    chld.handleValueChange(props.options[0])
    el = scryRenderedDOMComponentsWithTag(chld, 'svg')
    expect(el.length).to.equal(1)

  it 'should remove the Clear button and reset the value when clicked', ->
    chld.handleValueChange(props.options[1])
    el = scryRenderedDOMComponentsWithTag(chld, 'svg')
    Simulate.click(el[0])
    expect(chld.getValue()).to.equal('')

  it 'should return the full value object when getValue is fired', ->
    props.value = props.options[2]
    
    cmp = renderIntoDocument ContextWrapper {
      factory: SelectInputCustom
      childProps: props
    }
    chld = cmp.getInput()

    expect(chld.getValue()).to.equal(props.options[2])
    