ldx-widgets
Version:
widgets
76 lines (52 loc) • 2.5 kB
text/coffeescript
describe 'InputPlaceHolder', ->
React = require 'react'
InputPlaceHolder = React.createFactory require('../../src/components/input_placeholder')
_ = require 'lodash'
TestUtils = require 'react-addons-test-utils'
ReactDOM = require 'react-dom'
#--------------------------------------------------------------------- Default Props
it 'Should have default props', ->
inputPlaceHolder = TestUtils.renderIntoDocument InputPlaceHolder {}
defaultProps = inputPlaceHolder.props
expect(defaultProps.className).to.equal('')
expect(defaultProps.type).to.equal('text')
expect(defaultProps.placeholderIsSupported).to.be.a('boolean')
#--------------------------------------------------------------------- Text Change
it 'Should call the onChange when text is entered', ->
onChange = sinon.spy()
inputPlaceHolder = TestUtils.renderIntoDocument InputPlaceHolder {
onChange: onChange
value: 'new value'
}
inputText = TestUtils.findRenderedDOMComponentWithTag inputPlaceHolder, 'input'
TestUtils.Simulate.change inputText
expect(onChange.called).to.equal(true)
it 'Should remove the placeholder when text is added', ->
onChange = sinon.spy()
inputPlaceHolder = TestUtils.renderIntoDocument InputPlaceHolder {
onChange: onChange
value: 'new text'
}
input = TestUtils.findRenderedDOMComponentWithTag inputPlaceHolder, 'input'
inputValue = ReactDOM.findDOMNode(input).value
expect(inputValue).to.equal('new text')
it 'Should have placeholder class when no text has been added and place holder isnt supported', ->
onChange = sinon.spy()
inputPlaceHolder = TestUtils.renderIntoDocument InputPlaceHolder {
onChange: onChange
value: ''
placeholder: 'placeholder text'
placeholderIsSupported: false
}
placeHolderClass = TestUtils.scryRenderedDOMComponentsWithClass inputPlaceHolder, 'placeholder'
expect(placeHolderClass.length).to.equal(1)
it 'Should have not placeholder class when text has been added and place holder isnt supported', ->
onChange = sinon.spy()
inputPlaceHolder = TestUtils.renderIntoDocument InputPlaceHolder {
onChange: onChange
value: 'text'
placeholder: 'placeholder text'
placeholderIsSupported: false
}
placeHolderClass = TestUtils.scryRenderedDOMComponentsWithClass inputPlaceHolder, 'placeholder'
expect(placeHolderClass.length).to.equal(0)