UNPKG

ldx-widgets

Version:

widgets

234 lines (159 loc) 5.74 kB
describe 'InfoPvr', -> React = require 'react' InfoPvr = React.createFactory require('../../src/components/info_pvr') TestUtils = require 'react-addons-test-utils' ReactDOM = require 'react-dom' #--------------------------------------------------------------------- Default Props it 'Should have default props', -> infoPvr = TestUtils.renderIntoDocument InfoPvr {} defaultProps = infoPvr.props expect(defaultProps.items).to.be.a('array') expect(defaultProps.itemHeight).to.equal(35) expect(defaultProps.styleMixin).to.be.a('object') expect(defaultProps.headerClass).to.be.a('string') expect(defaultProps.pvrProps).to.be.a('object') expect(defaultProps.className).to.equal('plain-pvr') #--------------------------------------------------------------------- CSS Class it 'Should Render the appropriate class name if className is passed', -> className = 'new-class-name' infoPvr = TestUtils.renderIntoDocument InfoPvr { className: className } mainDiv = TestUtils.scryRenderedDOMComponentsWithClass infoPvr, className expect(mainDiv.length).to.equal(1) #--------------------------------------------------------------------- Header Title it 'Should Render the Header Title when headerTitle is defined', -> headerTitle = 'Header Title' infoPvr = TestUtils.renderIntoDocument InfoPvr { headerTitle: 'Header Title' } headerTitleDiv = TestUtils.findRenderedDOMComponentWithClass infoPvr, 'header plain-pvr-content-item' expect(headerTitleDiv.innerText).to.equal(headerTitle) it 'Should Render the Header Title with appropriate class when headerTitle is defined and headerClass is defined', -> headerTitle = 'Header Title' headerClass = 'header-title-class' infoPvr = TestUtils.renderIntoDocument InfoPvr { headerTitle: headerTitle headerClass: headerClass } headerTitleClass = TestUtils.scryRenderedDOMComponentsWithClass infoPvr, headerClass expect(headerTitleClass.length).to.equal(1) #--------------------------------------------------------------------- Row Items it 'Should Render the No information to display if items is not defined', -> items = [] infoPvr = TestUtils.renderIntoDocument InfoPvr { items: items } itemRowsNoInfo = TestUtils.findRenderedDOMComponentWithClass infoPvr, 'no-items' itemRowsDiv = TestUtils.scryRenderedDOMComponentsWithClass infoPvr, 'plain-pvr-content-item' expect(itemRowsNoInfo.innerText).to.equal('No information to display') expect(itemRowsDiv.length).to.equal(0) it 'Should Render info items if items is defined', -> items = [ { key: 1 label: 'One' info: 'one' }, { key: 2 label: 'Two' info: 'two' } ] infoPvr = TestUtils.renderIntoDocument InfoPvr { items: items } itemRowsDiv = TestUtils.scryRenderedDOMComponentsWithClass infoPvr, 'plain-pvr-content-item' itemRowsNoInfo = TestUtils.scryRenderedDOMComponentsWithClass infoPvr, 'no-items' expect(itemRowsDiv.length).to.equal(items.length) expect(itemRowsNoInfo.length).to.equal(0) #--------------------------------------------------------------------- Styles it 'Should calculate the style height if height is not defined in pvrProps property', -> items = [ { key: 1 label: 'One' info: 'one' }, { key: 2 label: 'Two' info: 'two' } ] infoPvr = TestUtils.renderIntoDocument InfoPvr { items: items } {props} = infoPvr {itemHeight, pvrProps} = props calculatedHeight = items.length * itemHeight + (items.length - 1) + 30 mainDiv = TestUtils.findRenderedDOMComponentWithClass infoPvr, 'plain-pvr' expect(mainDiv.style.height).to.equal(calculatedHeight+'px') it 'Should calculate the style height if height is not defined in pvrProps property and headerTitle is defined', -> items = [ { key: 1 label: 'One' info: 'one' }, { key: 2 label: 'Two' info: 'two' } ] infoPvr = TestUtils.renderIntoDocument InfoPvr { items: items headerTitle: 'Passing Header' } {props} = infoPvr {itemHeight, pvrProps} = props calculatedHeight = items.length * itemHeight + (items.length - 1) + 30 calculatedHeight += 34 mainDiv = TestUtils.findRenderedDOMComponentWithClass infoPvr, 'plain-pvr' expect(mainDiv.style.height).to.equal(calculatedHeight+'px') it 'Should use the pvrProps.height for the style height if height is defined in pvrProps property', -> height = 50 items = [ { key: 1 label: 'One' info: 'one' }, { key: 2 label: 'Two' info: 'two' } ] infoPvr = TestUtils.renderIntoDocument InfoPvr { items: items pvrProps: { height: height } } mainDiv = TestUtils.findRenderedDOMComponentWithClass infoPvr, 'plain-pvr' expect(mainDiv.style.height).to.equal(height+'px') it 'Should use the pvrProps.width for the style width if width is defined in pvrProps property', -> width = 50 items = [ { key: 1 label: 'One' info: 'one' }, { key: 2 label: 'Two' info: 'two' } ] infoPvr = TestUtils.renderIntoDocument InfoPvr { items: items pvrProps: { width: width } } mainDiv = TestUtils.findRenderedDOMComponentWithClass infoPvr, 'plain-pvr' expect(mainDiv.style.width).to.equal(width+'px')