ldx-widgets
Version:
widgets
78 lines (46 loc) • 2.22 kB
text/coffeescript
describe 'DatePicker', ->
React = require 'react'
DatePicker = React.createFactory require('../../src/components/date_picker')
TestUtils = require 'react-dom/test-utils'
ReactDOM = require 'react-dom'
dispatcher = require('../../src/dispatcher')
Spinner = React.createFactory require('../../src/components/spinner')
ValidationContext = require '../../src/context_wrapper'
afterEach -> dispatcher.dispatch 'clear-all'
###
Note About ValidationContext
The input validation uses context to gain access to the app level validation methods
Because context is only present when the component is a child of the application, it is not present in tests
The ValidationContext component, simply wraps the input component, and adds the validation context methods so they are present in the tests
###
#--------------------------------------------------------------------- Default Props
it 'Should have default props', ->
wrapper = TestUtils.renderIntoDocument(ValidationContext {
factory: DatePicker
childProps: {}
})
datePicker = wrapper.getInput()
defaultProps = datePicker.props
expect(defaultProps.placeholderText).to.equal('Select a date')
expect(defaultProps.dateFormat).to.equal('MM/DD/YYYY')
expect(defaultProps.dateFormat).to.be.a('string')
expect(defaultProps.includeTime).to.equal(no)
expect(defaultProps.onChange).to.be.a('function')
it 'Expects tabIndex to be a number if tabIndex is passed', ->
wrapper = TestUtils.renderIntoDocument(ValidationContext {
factory: DatePicker
childProps:
tabIndex: 1
})
datePicker = wrapper.getInput()
expect(typeof datePicker.props.tabIndex).to.equal('number')
#--------------------------------------------------------------------- CSS Classes
it 'Should Render the appropriate CSS class when className is passed', ->
className = 'new-class'
wrapper = TestUtils.renderIntoDocument(ValidationContext {
factory: DatePicker
childProps:
className: className
})
newClassName = TestUtils.scryRenderedDOMComponentsWithClass wrapper, className
expect(newClassName.length).to.equal(1)