diff --git a/client/components/notice/index.jsx b/client/components/notice/index.jsx index 452d43445a9f85..50e356f0694335 100644 --- a/client/components/notice/index.jsx +++ b/client/components/notice/index.jsx @@ -1,7 +1,7 @@ /** * External dependencies */ -import React from 'react'; +import React, { PropTypes } from 'react'; import classnames from 'classnames'; import noop from 'lodash/utility/noop'; @@ -24,15 +24,15 @@ export default React.createClass( { propTypes: { // we should validate the allowed statuses - status: React.PropTypes.string, - showDismiss: React.PropTypes.bool, - isCompact: React.PropTypes.bool, - text: React.PropTypes.oneOfType( [ - React.PropTypes.string, - React.PropTypes.object + status: PropTypes.string, + showDismiss: PropTypes.bool, + isCompact: PropTypes.bool, + text: PropTypes.oneOfType( [ + PropTypes.oneOfType( [ PropTypes.string, PropTypes.node ] ), + PropTypes.arrayOf( PropTypes.oneOfType( [ PropTypes.string, PropTypes.node ] ) ) ] ), - icon: React.PropTypes.string, - className: React.PropTypes.string + icon: PropTypes.string, + className: PropTypes.string }, renderChildren() { diff --git a/client/lib/posts/test/utils.js b/client/lib/posts/test/utils.js index 6ad88f16cf93bc..5660a16bb46af7 100644 --- a/client/lib/posts/test/utils.js +++ b/client/lib/posts/test/utils.js @@ -27,6 +27,38 @@ describe( 'PostUtils', function() { } ); } ); + describe( '#isPrivate', function() { + it( 'should return undefined when no post is supplied', function() { + assert( postUtils.isPrivate() === undefined ); + } ); + + it( 'should return true when post.status is private', function() { + assert( postUtils.isPrivate( { status: 'private' } ) ); + } ); + + it( 'should return false when post.status is not private', function() { + assert( ! postUtils.isPrivate( { status: 'draft' } ) ); + } ); + } ); + + describe( '#isPublished', function() { + it( 'should return undefined when no post is supplied', function() { + assert( postUtils.isPublished() === undefined ); + } ); + + it( 'should return true when post.status is private', function() { + assert( postUtils.isPublished( { status: 'private' } ) ); + } ); + + it( 'should return true when post.status is publish', function() { + assert( postUtils.isPublished( { status: 'publish' } ) ); + } ); + + it( 'should return false when post.status is not publish or private', function() { + assert( ! postUtils.isPublished( { status: 'draft' } ) ); + } ); + } ); + describe( '#removeSlug', function() { it( 'should return undefined when no path is supplied', function() { assert( postUtils.removeSlug() === undefined ); diff --git a/client/lib/posts/utils.js b/client/lib/posts/utils.js index d82216ea8b2873..9cc1acafbca7a8 100644 --- a/client/lib/posts/utils.js +++ b/client/lib/posts/utils.js @@ -68,6 +68,10 @@ var utils = { return post && ( post.status === 'publish' || post.status === 'private' ); }, + isPrivate: function( post ) { + return post && ( 'private' === post.status ); + }, + getEditedTime: function( post ) { if ( ! post ) { return; diff --git a/client/post-editor/post-editor.jsx b/client/post-editor/post-editor.jsx index 0a798dbf843704..f8a661499c762f 100644 --- a/client/post-editor/post-editor.jsx +++ b/client/post-editor/post-editor.jsx @@ -34,7 +34,6 @@ var actions = require( 'lib/posts/actions' ), EditorMobileNavigation = require( 'post-editor/editor-mobile-navigation' ), layoutFocus = require( 'lib/layout-focus' ), titleActions = require( 'lib/screen-title/actions' ), - user = require( 'lib/user' )(), observe = require( 'lib/mixins/data-observe' ), DraftList = require( 'my-sites/drafts/draft-list' ), DraftsButton = require( 'post-editor/drafts-button' ), @@ -690,7 +689,7 @@ var PostEditor = React.createClass( { }, onSaveDraftSuccess: function() { - if ( this.state.post.status === 'publish' || this.state.post.status === 'private' ) { + if ( utils.isPublished( this.state.post ) ) { this.onSaveSuccess( this.getMessage( 'updated' ), this.getMessage( 'view' ), @@ -702,13 +701,10 @@ var PostEditor = React.createClass( { }, onPublish: function() { - var currentUser = user.get(), - edits = { - status: 'publish' - }; + var edits = { status: 'publish' }; // determine if this is a private publish - if ( this.state.post && this.state.post.status === 'private' ) { + if ( utils.isPrivate( this.state.post ) ) { edits.status = 'private'; } @@ -737,7 +733,7 @@ var PostEditor = React.createClass( { }, onPublishSuccess: function() { - const publishedMessage = 'private' === utils.getVisibility( this.state.savedPost ) ? + const publishedMessage = utils.isPrivate( this.state.savedPost ) ? this.getMessage( 'publishedPrivately' ) : this.getMessage( 'published' );