Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: Use post.utils for Status Testing #1712

Merged
merged 5 commits into from
Jan 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions client/components/notice/index.jsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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() {
Expand Down
32 changes: 32 additions & 0 deletions client/lib/posts/test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
4 changes: 4 additions & 0 deletions client/lib/posts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 4 additions & 8 deletions client/post-editor/post-editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand Down Expand Up @@ -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' ),
Expand All @@ -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';
}

Expand Down Expand Up @@ -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' );

Expand Down