From 5e56b150663beac91e3ef8f6063dc4f8d92865d0 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Thu, 15 Feb 2018 18:40:33 -0500 Subject: [PATCH] State: Set new post status to draft in initialization --- editor/components/post-saved-state/index.js | 17 +++---------- .../components/post-saved-state/test/index.js | 24 ------------------- editor/store/effects.js | 7 +----- editor/store/test/effects.js | 22 ++++------------- editor/store/test/selectors.js | 8 +++++-- 5 files changed, 15 insertions(+), 63 deletions(-) diff --git a/editor/components/post-saved-state/index.js b/editor/components/post-saved-state/index.js index 034d5de3ed357..87ab343512806 100644 --- a/editor/components/post-saved-state/index.js +++ b/editor/components/post-saved-state/index.js @@ -15,7 +15,7 @@ import { Dashicon, Button } from '@wordpress/components'; */ import './style.scss'; import PostSwitchToDraftButton from '../post-switch-to-draft-button'; -import { editPost, savePost } from '../../store/actions'; +import { savePost } from '../../store/actions'; import { isEditedPostNew, isCurrentPostPublished, @@ -23,7 +23,6 @@ import { isSavingPost, isEditedPostSaveable, getCurrentPost, - getEditedPostAttribute, hasMetaBoxes, } from '../../store/selectors'; @@ -33,7 +32,7 @@ import { * @param {Object} Props Component Props. * @return {WPElement} WordPress Element. */ -export function PostSavedState( { hasActiveMetaboxes, isNew, isPublished, isDirty, isSaving, isSaveable, status, onStatusChange, onSave } ) { +export function PostSavedState( { hasActiveMetaboxes, isNew, isPublished, isDirty, isSaving, isSaveable, onSave } ) { const className = 'editor-post-saved-state'; if ( isSaving ) { @@ -61,16 +60,8 @@ export function PostSavedState( { hasActiveMetaboxes, isNew, isPublished, isDirt ); } - const onClick = () => { - if ( 'auto-draft' === status ) { - onStatusChange( 'draft' ); - } - - onSave(); - }; - return ( - @@ -85,11 +76,9 @@ export default connect( isDirty: isEditedPostDirty( state ), isSaving: isSavingPost( state ), isSaveable: isEditedPostSaveable( state ), - status: getEditedPostAttribute( state, 'status' ), hasActiveMetaboxes: hasMetaBoxes( state ), } ), { - onStatusChange: ( status ) => editPost( { status } ), onSave: savePost, } )( PostSavedState ); diff --git a/editor/components/post-saved-state/test/index.js b/editor/components/post-saved-state/test/index.js index 524d5bc02a23d..bd45a24b8aa74 100644 --- a/editor/components/post-saved-state/test/index.js +++ b/editor/components/post-saved-state/test/index.js @@ -52,29 +52,7 @@ describe( 'PostSavedState', () => { expect( wrapper.childAt( 1 ).text() ).toBe( 'Saved' ); } ); - it( 'should edit auto-draft post to draft before save', () => { - const statusSpy = jest.fn(); - const saveSpy = jest.fn(); - const wrapper = shallow( - - ); - - expect( wrapper.name() ).toBe( 'Button' ); - expect( wrapper.childAt( 0 ).text() ).toBe( 'Save' ); - wrapper.simulate( 'click' ); - expect( statusSpy ).toHaveBeenCalledWith( 'draft' ); - expect( saveSpy ).toHaveBeenCalled(); - } ); - it( 'should return Save button if edits to be saved', () => { - const statusSpy = jest.fn(); const saveSpy = jest.fn(); const wrapper = shallow( { isDirty={ true } isSaving={ false } isSaveable={ true } - onStatusChange={ statusSpy } onSave={ saveSpy } /> ); expect( wrapper.name() ).toBe( 'Button' ); expect( wrapper.childAt( 0 ).text() ).toBe( 'Save' ); wrapper.simulate( 'click' ); - expect( statusSpy ).not.toHaveBeenCalled(); expect( saveSpy ).toHaveBeenCalled(); } ); } ); diff --git a/editor/store/effects.js b/editor/store/effects.js index 8351e1b953a6d..0af81c0b53564 100644 --- a/editor/store/effects.js +++ b/editor/store/effects.js @@ -33,7 +33,6 @@ import { createErrorNotice, removeNotice, savePost, - editPost, requestMetaBoxUpdates, metaBoxUpdatesSuccess, updateReusableBlock, @@ -285,11 +284,6 @@ export default { return; } - // Change status from auto-draft to draft - if ( isEditedPostNew( state ) ) { - dispatch( editPost( { status: 'draft' } ) ); - } - dispatch( savePost() ); }, SETUP_EDITOR( action ) { @@ -319,6 +313,7 @@ export default { if ( post.status === 'auto-draft' ) { effects.push( setupNewPost( { title: post.title.raw, + status: 'draft', } ) ); } diff --git a/editor/store/test/effects.js b/editor/store/test/effects.js index dc9a25dbc7566..fc930a6faf944 100644 --- a/editor/store/test/effects.js +++ b/editor/store/test/effects.js @@ -23,7 +23,6 @@ import { resetBlocks, mergeBlocks, replaceBlocks, - editPost, savePost, requestMetaBoxUpdates, updateReusableBlock, @@ -265,8 +264,7 @@ describe( 'effects', () => { handler( {}, store ); - expect( dispatch ).toHaveBeenCalledTimes( 2 ); - expect( dispatch ).toHaveBeenCalledWith( editPost( { status: 'draft' } ) ); + expect( dispatch ).toHaveBeenCalledTimes( 1 ); expect( dispatch ).toHaveBeenCalledWith( savePost() ); } ); @@ -280,19 +278,6 @@ describe( 'effects', () => { expect( dispatch ).not.toHaveBeenCalled(); } ); - it( 'should set auto-draft to draft before save', () => { - selectors.isEditedPostSaveable.mockReturnValue( true ); - selectors.isEditedPostDirty.mockReturnValue( true ); - selectors.isCurrentPostPublished.mockReturnValue( false ); - selectors.isEditedPostNew.mockReturnValue( true ); - - handler( {}, store ); - - expect( dispatch ).toHaveBeenCalledTimes( 2 ); - expect( dispatch ).toHaveBeenCalledWith( editPost( { status: 'draft' } ) ); - expect( dispatch ).toHaveBeenCalledWith( savePost() ); - } ); - it( 'should return update action for saveable, dirty draft', () => { selectors.isEditedPostSaveable.mockReturnValue( true ); selectors.isEditedPostDirty.mockReturnValue( true ); @@ -497,7 +482,10 @@ describe( 'effects', () => { expect( result ).toEqual( [ resetPost( post ), - setupNewPost( { title: 'A History of Pork' } ), + setupNewPost( { + title: 'A History of Pork', + status: 'draft', + } ), ] ); } ); } ); diff --git a/editor/store/test/selectors.js b/editor/store/test/selectors.js index 0ce5c950bbf24..51fcb716f7422 100644 --- a/editor/store/test/selectors.js +++ b/editor/store/test/selectors.js @@ -254,7 +254,9 @@ describe( 'selectors', () => { }, editor: { present: { - edits: {}, + edits: { + status: 'draft', + }, }, }, }; @@ -269,7 +271,9 @@ describe( 'selectors', () => { }, editor: { present: { - edits: {}, + edits: { + status: 'draft', + }, }, }, };