From 1d0e55609ecc85d6b1a336ce99312747828cb88f Mon Sep 17 00:00:00 2001
From: Alexander Fedyashov <af@e42.guru>
Date: Thu, 11 Aug 2016 18:48:10 +0300
Subject: [PATCH] feat(Feed) Update prop handling and tests

---
 src/views/Feed/FeedDate.js                |  2 +-
 src/views/Feed/FeedUser.js                | 17 +++++++++++++----
 test/specs/views/Feed/FeedDate-test.js    | 16 ++++++++++++++++
 test/specs/views/Feed/FeedSummary-test.js | 21 +++++++++++++++++++++
 test/specs/views/Feed/FeedUser-test.js    | 16 ++++++++++++++++
 5 files changed, 67 insertions(+), 5 deletions(-)
 create mode 100644 test/specs/views/Feed/FeedDate-test.js
 create mode 100644 test/specs/views/Feed/FeedSummary-test.js
 create mode 100644 test/specs/views/Feed/FeedUser-test.js

diff --git a/src/views/Feed/FeedDate.js b/src/views/Feed/FeedDate.js
index fdcbcbbd6b..8349a183e7 100644
--- a/src/views/Feed/FeedDate.js
+++ b/src/views/Feed/FeedDate.js
@@ -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,
   ]),
 }
 
diff --git a/src/views/Feed/FeedUser.js b/src/views/Feed/FeedUser.js
index 7cbc47cd2e..ceae62a6d7 100644
--- a/src/views/Feed/FeedUser.js
+++ b/src/views/Feed/FeedUser.js
@@ -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 = {
@@ -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
diff --git a/test/specs/views/Feed/FeedDate-test.js b/test/specs/views/Feed/FeedDate-test.js
new file mode 100644
index 0000000000..e5d2ce3070
--- /dev/null
+++ b/test/specs/views/Feed/FeedDate-test.js
@@ -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)
+  })
+})
diff --git a/test/specs/views/Feed/FeedSummary-test.js b/test/specs/views/Feed/FeedSummary-test.js
new file mode 100644
index 0000000000..bc02150e43
--- /dev/null
+++ b/test/specs/views/Feed/FeedSummary-test.js
@@ -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)
+  })
+})
diff --git a/test/specs/views/Feed/FeedUser-test.js b/test/specs/views/Feed/FeedUser-test.js
new file mode 100644
index 0000000000..54e7f89122
--- /dev/null
+++ b/test/specs/views/Feed/FeedUser-test.js
@@ -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)
+  })
+})