import * as Nerv from 'nervjs'
import * as sinon from 'sinon'
import * as $ from 'webpack-zepto'
import Radio from '../'
import { VNode } from 'nerv-shared'
describe('Radio test', () => {
let scratch
beforeAll(() => {
scratch = document.createElement('div')
document.body.appendChild(scratch)
})
beforeEach(() => {
scratch = document.createElement('div')
document.body.appendChild(scratch)
})
afterEach(() => {
scratch.parentNode.removeChild(scratch)
scratch = null
})
it('basic render', () => {
const onChange = sinon.spy()
const radioJSX = (
{}
选项一
)
const component = Nerv.render(radioJSX as any, scratch)
$(Nerv.findDOMNode(component)).trigger('click')
expect(
$(component.vnode.dom)
.find('.at-radio__inner')
.hasClass('at-radio--checked')
).toBeFalsy()
expect(onChange.called).toBeTruthy()
})
it('disabled', () => {
const onChange = sinon.spy()
class Test extends Nerv.Component {
state = {
radio1: 0
}
render () {
return (
{
onChange()
this.setState({ radio1: label })
}}
disabled
value={this.state.radio1}
label='1'
>
{}
选项一
{
this.setState({ radio1: label })
}}
value={this.state.radio1}
label='2'
Radio
>
{}
选项二
)
}
}
const component = Nerv.render( as VNode, scratch)
$(component.vnode.dom)
.find('.at-radio')
.eq(0)
.trigger('click')
Nerv.nextTick(() => {
expect(onChange.called).toBeFalsy()
})
})
it('radioGroup', () => {
const onChange = sinon.spy()
const radioGroupJSX = (
{
onChange(label)
}}
>
{}
{}选项一
{}选项二
{}选项三
)
const component = Nerv.render(radioGroupJSX as any, scratch)
$(component.vnode.dom)
.find('.at-radio')
.eq(0)
.trigger('click')
expect(onChange.args).toEqual([['1']])
})
it('radio button', (done) => {
const onChange = sinon.spy()
const radiob = (
{}北京
)
const component = Nerv.render(radiob as any, scratch)
$(Nerv.findDOMNode(component)).trigger('click')
Nerv.nextTick(() => {
expect(onChange.called).toBeTruthy()
done()
})
})
it('radio btn group', (done) => {
const btnGroup = (
{}
{}北京
{}上海
{}深圳
{}凹凸实验室
)
const component = Nerv.render(btnGroup as any, scratch)
$(Nerv.findDOMNode(component))
.find('.at-radio-button')
.eq(0)
.trigger('click')
Nerv.nextTick(() => {
expect($(Nerv.findDOMNode(component)).css('color')).toBe('rgb(0, 0, 0)')
done()
})
})
})