diff --git a/editor/actions.js b/editor/actions.js index 31387abc78b6c..3d6be1f3528b7 100644 --- a/editor/actions.js +++ b/editor/actions.js @@ -55,6 +55,7 @@ export function savePost( postId, edits ) { type: 'REQUEST_POST_UPDATE', edits, postId, + isNew: ! postId, }; } diff --git a/editor/test/actions.js b/editor/test/actions.js index 22a78ee696420..cc3a89ab19f1f 100644 --- a/editor/test/actions.js +++ b/editor/test/actions.js @@ -6,7 +6,11 @@ import { expect } from 'chai'; /** * Internal dependencies */ -import { focusBlock, replaceBlocks } from '../actions'; +import { + focusBlock, + replaceBlocks, + savePost, +} from '../actions'; describe( 'actions', () => { describe( 'focusBlock', () => { @@ -36,4 +40,24 @@ describe( 'actions', () => { } ); } ); } ); + + describe( 'savePost', () => { + it( 'should return the REQUEST_POST_UPDATE action for a new post', () => { + expect( savePost( null, { title: 'changed' } ) ).to.eql( { + type: 'REQUEST_POST_UPDATE', + edits: { title: 'changed' }, + postId: null, + isNew: true, + } ); + } ); + + it( 'should return the REQUEST_POST_UPDATE action for an existing post', () => { + expect( savePost( 1, { title: 'changed' } ) ).to.eql( { + type: 'REQUEST_POST_UPDATE', + edits: { title: 'changed' }, + postId: 1, + isNew: false, + } ); + } ); + } ); } );