Skip to content

Commit

Permalink
feat(Feed) Update prop handling and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Fedyashov authored and levithomason committed Aug 13, 2016
1 parent b362097 commit 1d0e556
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/views/Feed/FeedDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ FeedDate.propTypes = {
/** Shorthand for primary content of the FeedDate. Mutually exclusive with the children prop. */
date: customPropTypes.all([
customPropTypes.mutuallyExclusive(['children']),
PropTypes.node,
PropTypes.string,
]),
}

Expand Down
17 changes: 13 additions & 4 deletions src/views/Feed/FeedUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import cx from 'classnames'
import React, { PropTypes } from 'react'

import META from '../../utils/Meta'
import { getUnhandledProps } from '../../utils/propUtils'
import { customPropTypes, getUnhandledProps } from '../../utils/propUtils'

function FeedUser(props) {
const { children, className } = props
const { children, className, user } = props
const classes = cx(className, 'user')
const rest = getUnhandledProps(FeedUser, props)

return <a {...rest} className={classes}>{children}</a>
return <a {...rest} className={classes}>{children || user}</a>
}

FeedUser._meta = {
Expand All @@ -20,10 +20,19 @@ FeedUser._meta = {

FeedUser.propTypes = {
/** Primary content of the FeedUser. */
children: PropTypes.node,
children: customPropTypes.all([
customPropTypes.mutuallyExclusive(['user']),
PropTypes.node,
]),

/** Classes that will be added to the FeedUser className. */
className: PropTypes.string,

/** Shorthand for primary content of the FeedUser. Mutually exclusive with the children prop. */
user: customPropTypes.all([
customPropTypes.mutuallyExclusive(['children']),
PropTypes.string,
]),
}

export default FeedUser
16 changes: 16 additions & 0 deletions test/specs/views/Feed/FeedDate-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import faker from 'faker'
import React from 'react'

import * as common from 'test/specs/commonTests'
import FeedDate from 'src/views/Feed/FeedDate'

describe('FeedDate', () => {
common.isConformant(FeedDate)
common.rendersChildren(FeedDate)

it('renders text with date prop', () => {
const text = faker.hacker.phrase()

shallow(<FeedDate date={text} />).should.contain.text(text)
})
})
21 changes: 21 additions & 0 deletions test/specs/views/Feed/FeedSummary-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import faker from 'faker'
import React from 'react'

import * as common from 'test/specs/commonTests'
import FeedSummary from 'src/views/Feed/FeedSummary'

describe('FeedSummary', () => {
common.isConformant(FeedSummary)
common.rendersChildren(FeedSummary)

it('renders <FeedDate> with date prop', () => {
mount(<FeedSummary date={faker.hacker.phrase()} />)
.should.have.descendants('FeedDate')
})

it('renders text with summary prop', () => {
const text = faker.hacker.phrase()

shallow(<FeedSummary summary={text} />).should.contain.text(text)
})
})
16 changes: 16 additions & 0 deletions test/specs/views/Feed/FeedUser-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import faker from 'faker'
import React from 'react'

import * as common from 'test/specs/commonTests'
import FeedUser from 'src/views/Feed/FeedUser'

describe('FeedUser', () => {
common.isConformant(FeedUser)
common.rendersChildren(FeedUser)

it('renders text with user prop', () => {
const text = faker.hacker.phrase()

shallow(<FeedUser user={text} />).should.contain.text(text)
})
})

0 comments on commit 1d0e556

Please sign in to comment.