Skip to content

Commit

Permalink
fix(Feed) More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
layershifter authored and levithomason committed Aug 13, 2016
1 parent 1d0e556 commit 1d31612
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/views/Feed/FeedContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,29 @@ FeedContent.propTypes = {
/** Primary content of the FeedContent. Mutually exclusive with children. */
content: customPropTypes.all([
customPropTypes.mutuallyExclusive(['children']),
PropTypes.node,
PropTypes.string,
]),

/** An event can contain a date. */
date: PropTypes.node,
date: PropTypes.string,

/** Shorthand for FeedExtra with prop images. */
extraImages: customPropTypes.all([
customPropTypes.mutuallyExclusive(['children', 'content']),
PropTypes.arrayOf(PropTypes.node),
PropTypes.arrayOf(PropTypes.string),
]),

/** Shorthand for FeedExtra with prop text. */
extraText: customPropTypes.all([
customPropTypes.mutuallyExclusive(['children', 'content']),
PropTypes.node,
PropTypes.string,
]),

/** A shorthand for FeedMeta. */
meta: PropTypes.node,
meta: PropTypes.string,

/** A shorthand for FeedSummary. */
summary: PropTypes.node,
summary: PropTypes.string,
}

export default FeedContent
3 changes: 1 addition & 2 deletions src/views/Feed/FeedExtra.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ FeedExtra.propTypes = {
customPropTypes.mutuallyExclusive(['images']),
PropTypes.oneOfType([
PropTypes.bool,
PropTypes.node,
PropTypes.arrayOf(PropTypes.string),
PropTypes.string,
]),
]),
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/Feed/FeedLike.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ FeedLike.propTypes = {
/** Primary content of the FeedLike, mutually exclusive with children prop. */
like: customPropTypes.all([
customPropTypes.mutuallyExclusive(['children']),
PropTypes.node,
PropTypes.string,
]),
}

Expand Down
4 changes: 2 additions & 2 deletions src/views/Feed/FeedMeta.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ FeedMeta.propTypes = {

/** Primary content of the FeedMeta. Mutually exclusive with children. */
meta: customPropTypes.all([
customPropTypes.mutuallyExclusive(['content']),
PropTypes.node,
customPropTypes.mutuallyExclusive(['children']),
PropTypes.string,
]),
}

Expand Down
32 changes: 32 additions & 0 deletions test/specs/views/Feed/Feed-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import _ from 'lodash'
import faker from 'faker'
import React from 'react'

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

describe('Feed', () => {
common.hasUIClassName()
common.isConformant(Feed)
common.propValueOnlyToClassName(Feed, 'size')
common.rendersChildren(Feed)

describe('events prop', () => {
it('renders <FeedEvent>', () => {
const events = _.times(3, () => {
return { summary: faker.hacker.phrase() }
})

mount(<Feed events={events} />)
.should.have.exactly(3).descendants('FeedEvent')
})

it('allows pass own key', () => {
const key = faker.hacker.phrase()
const events = [{ key, summary: faker.hacker.phrase() }]

mount(<Feed events={events} />).find('FeedEvent').first()
.should.have.prop('key', key)
})
})
})
37 changes: 37 additions & 0 deletions test/specs/views/Feed/FeedEvent-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import _ from 'lodash'
import faker from 'faker'
import React from 'react'

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

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

it('renders <FeedLabel> with icon prop', () => {
mount(<FeedEvent icon={faker.hacker.phrase()} />)
.should.have.descendants('FeedLabel')
})

it('renders <FeedLabel> with image prop', () => {
mount(<FeedEvent image={faker.image.imageUrl()} />)
.should.have.descendants('FeedLabel')
})

describe('content props', () => {
it('renders <FeedContent> with extraImages prop', () => {
const images = _.times(3, () => faker.image.imageUrl())
mount(<FeedEvent extraImages={images} />).should.have.descendants('FeedContent')
})

it('renders <FeedContent> with other content props', () => {
const contentProps = ['content', 'date', 'extraText', 'meta', 'summary']

contentProps.map(propKey => {
const props = { [propKey]: faker.hacker.phrase() }
mount(<FeedEvent {...props} />).should.have.descendants('FeedContent')
})
})
})
})
18 changes: 18 additions & 0 deletions test/specs/views/Feed/FeedExtra-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import faker from 'faker'
import React from 'react'

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

describe('FeedExtra', () => {
common.isConformant(FeedExtra)
common.propKeyOnlyToClassName(FeedExtra, 'images')
common.propKeyOnlyToClassName(FeedExtra, 'text')
common.rendersChildren(FeedExtra)

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

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

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

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

describe('image prop', () => {
it('renders <img> with string', () => {
const src = faker.image.imageUrl()

shallow(<FeedLabel image={src} />).should.contain(<img src={src} />)
})

it('renders node', () => {
const img = <img src={faker.image.imageUrl()} />

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

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

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

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

shallow(<FeedLike like={text} />).should.contain.text(text)
})
})
21 changes: 21 additions & 0 deletions test/specs/views/Feed/FeedMeta-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 FeedMeta from 'src/views/Feed/FeedMeta'

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

it('renders <FeedLike> with like prop', () => {
mount(<FeedMeta like={faker.hacker.phrase()} />)
.should.have.descendants('FeedLike')
})

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

shallow(<FeedMeta meta={text} />).should.contain.text(text)
})
})

0 comments on commit 1d31612

Please sign in to comment.