Skip to content

Commit

Permalink
feat(swipe-action): 完善测试案例
Browse files Browse the repository at this point in the history
  • Loading branch information
SzHeJason committed Sep 28, 2018
1 parent 8050f43 commit 2083653
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/components/swipe-action/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SwipeAction Snap render options 1`] = `"<div class=\\"at-swipe-action swipe-action--test\\"><div style=\\"transform:translate3d(0px,0,0);\\" class=\\"at-swipe-action__content animtion\\"><div class=\\"normal\\">AtSwipeAction 一般使用场景</div></div><div class=\\"at-swipe-action__options\\"><div style=\\"background-color:#6190E8;\\" class=\\"at-swipe-action__option cancel\\"><span class=\\"taro-text option__text\\">取消</span></div><div style=\\"background-color:#FF4949;\\" class=\\"at-swipe-action__option confirm\\"><span class=\\"taro-text option__text\\">确认</span></div></div></div>"`;
59 changes: 59 additions & 0 deletions src/components/swipe-action/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import Nerv, { findDOMNode } from 'nervjs'
import { renderToString } from 'nerv-server'
import { Simulate, renderIntoDocument } from 'nerv-test-utils'

import { View } from '@tarojs/components'

import AtSwipeAction from '../../../.temp/components/swipe-action/index'

const OPTIONS = [
{
text: '取消',
className: 'cancel',
style: {
backgroundColor: '#6190E8'
}
},
{
text: '确认',
className: 'confirm',
style: {
backgroundColor: '#FF4949'
}
}
]

describe('SwipeAction Snap', () => {
it('render options', () => {
const component = renderToString(
<AtSwipeAction
className='swipe-action--test'
disabled
autoClose
options={OPTIONS}
>
<View className='normal'>AtSwipeAction 一般使用场景</View>
</AtSwipeAction>
)
expect(component).toMatchSnapshot()
})
})

describe('SwipeAction Behavior ', () => {
it('SwipeAction onClick', () => {
const onClick = jest.fn()

const component = renderIntoDocument(
<AtSwipeAction options={OPTIONS} onClick={onClick}>
<View className='normal'>AtSwipeAction 一般使用场景</View>
</AtSwipeAction>
)
const componentDom = findDOMNode(component, 'at-swipe-action')

const optionDom = componentDom.querySelector('.at-swipe-action__option')

Simulate.click(optionDom)

expect(onClick).toBeCalled()
})
})

0 comments on commit 2083653

Please sign in to comment.