describe 'InfoModal', ->
  React = require 'react'
  InfoModal = React.createFactory require('../../src/components/info_modal')
  _ = require 'lodash'
  TestUtils = require 'react-addons-test-utils'
  ReactDOM = require 'react-dom'
   
  #--------------------------------------------------------------------- Default Props
  it 'Should have default props', ->
    infoModal = TestUtils.renderIntoDocument InfoModal {}

    defaultProps = infoModal.props
    expect(defaultProps.height).to.equal('auto')
    expect(defaultProps.itemHeight).to.equal(35)
    expect(defaultProps.className).to.equal('modal info-modal')
    

  #--------------------------------------------------------------------- Render
  it 'Should Render the appropriate CSS class when className property passed', ->
    className = 'new-class'

    infoModal = TestUtils.renderIntoDocument InfoModal {
      className: className
    }
  
    mainDiv = TestUtils.scryRenderedDOMComponentsWithClass infoModal, "new-class"

    expect(mainDiv.length).to.equal(1)


  it 'Should Render the headerTitle when headerTitle property passed', ->
    headerTitle = 'New Header'

    infoModal = TestUtils.renderIntoDocument InfoModal {
      headerTitle: headerTitle
    }
  
    headerDiv = TestUtils.findRenderedDOMComponentWithClass infoModal, "title"

    expect(headerDiv.innerText).to.equal(headerTitle)


  it 'Should NOT Render the headerTitle when headerTitle property is not passed', ->
    
    infoModal = TestUtils.renderIntoDocument InfoModal {}
  
    headerDiv = TestUtils.scryRenderedDOMComponentsWithClass infoModal, "title"

    expect(headerDiv.length).to.equal(0)


  it 'Should Render the Done button', ->
    
    infoModal = TestUtils.renderIntoDocument InfoModal {}
  
    doneBtn = TestUtils.findRenderedDOMComponentWithClass infoModal, "done prmy"

    expect(doneBtn.innerText).to.equal("Done")


  it 'Should Render the No information to display when items property passed is empty', ->
    items = []

    infoModal = TestUtils.renderIntoDocument InfoModal {
      items: items
    }
  
    itemsDiv = TestUtils.findRenderedDOMComponentWithClass infoModal, "no-items"

    expect(itemsDiv.innerText).to.equal('No information to display')


  it 'Should Render the items when items property passed', ->
    items = [{label: 'One', info: "One"}, {label: 'Two', info: "Two"}]

    infoModal = TestUtils.renderIntoDocument InfoModal {
      items: items
    }
  
    itemRowsDiv = TestUtils.scryRenderedDOMComponentsWithClass infoModal, 'plain-pvr-content-item'
    itemRowsNoInfo = TestUtils.scryRenderedDOMComponentsWithClass infoModal, 'no-items'

    expect(itemRowsDiv.length).to.equal(items.length)
    expect(itemRowsNoInfo.length).to.equal(0)


  it 'Should call close when Done is clicked', ->

    close = sinon.spy()
    
    infoModal = TestUtils.renderIntoDocument InfoModal {
      close: close
    }

    doneBtn = TestUtils.findRenderedDOMComponentWithClass infoModal, "done prmy"

    TestUtils.Simulate.click doneBtn, {}

    expect(close.calledOnce).to.equal(true)

   


