[web] Add tests for js/components/ContentView/ShowFullContentButton.jsx

This commit is contained in:
Matthew Shao 2017-06-05 10:22:19 +08:00
parent 298ac8391e
commit bff23275c3
3 changed files with 65 additions and 1 deletions

View File

@ -0,0 +1,39 @@
import React from 'react'
import renderer from 'react-test-renderer'
import { Provider } from 'react-redux'
import ConnectedComponent, { ShowFullContentButton } from '../../../components/ContentView/ShowFullContentButton'
import { TStore } from '../../ducks/tutils'
describe('ShowFullContentButton Component', () => {
let setShowFullContentFn = jest.fn(),
showFullContentButton = renderer.create(
<ShowFullContentButton
setShowFullContent={setShowFullContentFn}
showFullContent={false}
visibleLines={10}
contentLines={20}
/>
),
tree = showFullContentButton.toJSON()
it('should render correctly', () => {
expect(tree).toMatchSnapshot()
})
it('should handle click', () => {
tree.children[0].props.onClick()
expect(setShowFullContentFn).toBeCalled()
})
it('should connect to state', () => {
let store = TStore(),
provider = renderer.create(
<Provider store={store}>
<ConnectedComponent/>
</Provider>
),
tree = provider.toJSON()
expect(tree).toMatchSnapshot()
})
})

View File

@ -0,0 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`ShowFullContentButton Component should connect to state 1`] = `null`;
exports[`ShowFullContentButton Component should render correctly 1`] = `
<div>
<div
className="view-all-content-btn btn-xs btn btn-default"
disabled={undefined}
onClick={[Function]}
title={undefined}
>
Show full content
</div>
<span
className="pull-right"
>
10
/
20
are visible  
</span>
</div>
`;

View File

@ -12,7 +12,7 @@ ShowFullContentButton.propTypes = {
showFullContent: PropTypes.bool.isRequired showFullContent: PropTypes.bool.isRequired
} }
function ShowFullContentButton ( {setShowFullContent, showFullContent, visibleLines, contentLines} ){ export function ShowFullContentButton ( {setShowFullContent, showFullContent, visibleLines, contentLines} ){
return ( return (
!showFullContent && !showFullContent &&