describe 'PvrInfoList', ->
  React = require 'react'
  PvrInfoList = React.createFactory require('../../src/components/pvr_info_list')
  PvrInfoItem = React.createFactory require('../../src/components/pvr_info_item')
  TestUtils = require 'react-dom/test-utils'
  ReactDOM = require 'react-dom'

  #--------------------------------------------------------------------- Default Props
  it 'Should have default props', ->
    pvrInfoList = TestUtils.renderIntoDocument PvrInfoList {}

    defaultProps = pvrInfoList.props
    expect(defaultProps.height).to.equal('auto')
    expect(defaultProps.width).to.equal(250)
    expect(defaultProps.styleMixin).to.be.a('object')
    expect(defaultProps.itemHeight).to.equal(30)
    expect(defaultProps.position).to.equal('bottom')
    expect(defaultProps.offsetTop).to.equal(0)
    expect(defaultProps.offsetLeft).to.equal(0)
    expect(defaultProps.showNib).to.equal(yes)
    
   
  #--------------------------------------------------------------------- Render
  it 'Should Render the appropriate CSS class from position property passed', ->
    position = 'left'

    pvrInfoList = TestUtils.renderIntoDocument PvrInfoList {
      position: position
    }
  
    mainDiv = TestUtils.scryRenderedDOMComponentsWithClass pvrInfoList, "plain-pvr #{position}"

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


  it 'Should Render header title if headerTitle property is passed', ->


    headerTitle = 'New Header'

    pvrInfoList = TestUtils.renderIntoDocument PvrInfoList {
      headerTitle: headerTitle
    }

    headerTitleDiv = TestUtils.findRenderedDOMComponentWithClass pvrInfoList, 'header plain-pvr-content-item'
    
    expect(headerTitleDiv.innerText).to.equal(headerTitle)
   

  it 'Should set the div height based off of the height property when headerTitle property is not passed and items property is empy', ->

    height = 10
    
    pvrInfoList = TestUtils.renderIntoDocument PvrInfoList {
      height: height
    }

    height = height + 20

    mainDiv = TestUtils.findRenderedDOMComponentWithClass pvrInfoList, 'plain-pvr'
  
    expect(mainDiv.style['height']).to.equal("#{height}px")


  it 'Should set the div height based off of the height property and headerTitle property and items property is empty', ->

    height = 10
    
    pvrInfoList = TestUtils.renderIntoDocument PvrInfoList {
      height: height
      headerTitle: 'New Title'
    }

    height += 34 # add 34 when headerTitle is passed

    height = height + 20

    mainDiv = TestUtils.findRenderedDOMComponentWithClass pvrInfoList, 'plain-pvr'
  
    expect(mainDiv.style['height']).to.equal("#{height}px")

  
  it 'Should set the div height based off of number of items if height property is auto and items property has length', ->

    items = [{key: 'one', info: 'info', label: 'label'}, {key: 'two', info: 'info', label: 'label'}, {key: 'three', info: 'info', label: 'label'}]
    itemHeight = 20
    
    pvrInfoList = TestUtils.renderIntoDocument PvrInfoList {
      items: items
      itemHeight: itemHeight
    }

    height = items.length * itemHeight + (items.length - 1)

    height = height + 20

    mainDiv = TestUtils.findRenderedDOMComponentWithClass pvrInfoList, 'plain-pvr'
  
    expect(mainDiv.style['height']).to.equal("#{height}px")


  it 'Should Render No information to display if items is empty', ->

    pvrInfoList = TestUtils.renderIntoDocument PvrInfoList {}

    noItemsDiv = TestUtils.findRenderedDOMComponentWithClass pvrInfoList, 'no-items'
  
    expect(noItemsDiv.innerText).to.equal('No information to display')


  it 'Should Render items if items is not empty', ->

    items = [{key: 'one', info: 'info', label: 'label'}, {key: 'two', info: 'info', label: 'label'}, {key: 'three', info: 'info', label: 'label'}]

    pvrInfoList = TestUtils.renderIntoDocument PvrInfoList {
      items: items
    }

    itemsDiv = TestUtils.scryRenderedDOMComponentsWithClass pvrInfoList, 'plain-pvr-content-item'
  
    expect(itemsDiv.length).to.equal(items.length)


  it 'Should Render Nib if showNib property is true', ->

    pvrInfoList = TestUtils.renderIntoDocument PvrInfoList {
      showNib: yes
    }

    nibDiv = TestUtils.scryRenderedDOMComponentsWithClass pvrInfoList, 'nib'
  
    expect(nibDiv.length).to.equal(1)


  it 'Should Render Nib if showNib property is false', ->

    pvrInfoList = TestUtils.renderIntoDocument PvrInfoList {
      showNib: no
    }
   
    nibDiv = TestUtils.scryRenderedDOMComponentsWithClass pvrInfoList, 'nib'
  
    expect(nibDiv.length).to.equal(0)

