ldx-widgets
Version:
widgets
72 lines (61 loc) • 2.28 kB
text/coffeescript
describe 'Select Input Custom', ->
SelectInputCustom = React.createFactory require('../../src/components/select_input_custom')
spy = sinon.spy()
chld = null
props =
options: [
{
optValue: 123
label: 'Number one'
}
{
optValue: 4321
label: 'Number two'
}
{
optValue: 6126
label: 'Number three'
}
{
optValue: 651
label: 'Number four'
}
]
onChange: spy
labelField: 'label'
valueField: 'optValue'
selectText: 'This is the first choice'
returnFullObjects: true
before ->
cmp = renderIntoDocument ContextWrapper {
factory: SelectInputCustom
childProps: props
}
chld = cmp.getInput()
beforeEach ->
spy.reset()
it 'should render a select component', ->
el = findRenderedDOMComponentWithTag(chld, 'select')
expect(el).to.be.ok
it 'should render a set of options equal to length of input array, plus default option', ->
el = scryRenderedDOMComponentsWithTag(chld, 'option')
expect(el.length).to.equal(props.options.length + 1)
it 'should use insert the selectText value as the first option', ->
el = scryRenderedDOMComponentsWithTag(chld, 'option')
expect(el[0].innerHTML).to.equal(props.selectText)
it 'should use a custom valueField and labelField properties to determine option labels', ->
el = scryRenderedDOMComponentsWithTag(chld, 'option')
expect(el[1].innerHTML).to.equal(props.options[0][props.labelField])
expect(el[1].value).to.equal(props.options[0][props.valueField].toString())
it 'should render a Clear button ONLY when a value is selected', ->
chld.handleChange(props.options[0][props.valueField])
el = scryRenderedDOMComponentsWithTag(chld, 'svg')
expect(el.length).to.equal(1)
it 'should remove the Clear button and reset the value when clicked', ->
chld.handleChange(props.options[1][props.valueField])
el = scryRenderedDOMComponentsWithTag(chld, 'svg')
Simulate.click(el[0])
expect(chld.getValue()).to.be.undefined
it 'should return the full value object when getValue is fired', ->
chld.handleChange(props.options[2][props.valueField])
expect(chld.getValue()).to.equal(props.options[2])