ldx-widgets
Version:
widgets
54 lines (31 loc) • 1.48 kB
text/coffeescript
describe 'IOSToggleSwitch', ->
React = require 'react'
IOSToggleSwitch = React.createFactory require('../../src/components/ios_toggle_switch')
_ = require 'lodash'
TestUtils = require 'react-addons-test-utils'
ReactDOM = require 'react-dom'
#--------------------------------------------------------------------- Input checked toggle
it 'Should render on when checked is true', ->
iosToggleSwitch = TestUtils.renderIntoDocument IOSToggleSwitch {
checked: yes
handleChange: ->
}
input = TestUtils.findRenderedDOMComponentWithClass iosToggleSwitch, 'ios-toggle-switch-checkbox'
inputChecked = ReactDOM.findDOMNode(input).checked
expect(inputChecked).to.equal(true)
it 'Should render off when checked is false', ->
iosToggleSwitch = TestUtils.renderIntoDocument IOSToggleSwitch {
checked: no
}
input = TestUtils.findRenderedDOMComponentWithClass iosToggleSwitch, 'ios-toggle-switch-checkbox'
inputChecked = ReactDOM.findDOMNode(input).checked
expect(inputChecked).to.equal(false)
#--------------------------------------------------------------------- Click handling
it 'Should call the onClick prop when clicked', ->
onClick = sinon.spy()
iosToggleSwitch = TestUtils.renderIntoDocument IOSToggleSwitch {
handleChange: onClick
}
el = ReactDOM.findDOMNode(iosToggleSwitch)
TestUtils.Simulate.click el, {}
expect(onClick.calledOnce).to.equal(true)