ldx-widgets
Version:
widgets
61 lines (35 loc) • 1.53 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 update it's check state when clicked", ->
iosToggleSwitch = TestUtils.renderIntoDocument IOSToggleSwitch {
checked: yes
onChange: ->
}
el = ReactDOM.findDOMNode(iosToggleSwitch)
TestUtils.Simulate.click el, {}
inputChecked = iosToggleSwitch.getValue()
expect(inputChecked).to.equal(no)
TestUtils.Simulate.click el, {}
inputChecked = iosToggleSwitch.getValue()
expect(inputChecked).to.equal(yes)
it 'Should add the is-checked class when checked is true', ->
iosToggleSwitch = TestUtils.renderIntoDocument IOSToggleSwitch {
checked: yes
onChange: ->
}
el = ReactDOM.findDOMNode(iosToggleSwitch)
expect(el.className).to.equal('ios-toggle-switch is-checked')
#--------------------------------------------------------------------- Click handling
it 'Should call the onChangee prop when clicked', ->
onClick = sinon.spy()
iosToggleSwitch = TestUtils.renderIntoDocument IOSToggleSwitch {
onChange: onClick
}
el = ReactDOM.findDOMNode(iosToggleSwitch)
TestUtils.Simulate.click el, {}
expect(onClick.calledOnce).to.equal(true)