diff --git a/client/lib/posts/post-edit-store.js b/client/lib/posts/post-edit-store.js index a8c695ea2b67f..7893a80a00161 100644 --- a/client/lib/posts/post-edit-store.js +++ b/client/lib/posts/post-edit-store.js @@ -471,7 +471,23 @@ PostEditStore = { }, isDirty: function() { - return _post !== _savedPost || _rawContent !== _initialRawContent; + debug( + 'isDirty post?%s rawContent?%s initial=%s content=%s', + _post !== _savedPost, + _rawContent !== _initialRawContent, + _initialRawContent, + _rawContent + ); + if ( _post !== _savedPost ) { + return true; + } + if ( _rawContent !== _initialRawContent ) { + return ( + ! isContentEmpty( _rawContent ) || + ! isContentEmpty( _initialRawContent ) + ); + } + return false; }, isNew: function() { diff --git a/client/lib/posts/test/post-edit-store.js b/client/lib/posts/test/post-edit-store.js index 243ce31c24be2..96e3a04baefca 100644 --- a/client/lib/posts/test/post-edit-store.js +++ b/client/lib/posts/test/post-edit-store.js @@ -570,6 +570,56 @@ describe( 'post-edit-store', function() { assert( PostEditStore.isDirty() ); } ); + + it( 'returns false if content changes from empty to


', function() { + dispatcherCallback( { + action: { + type: 'RECEIVE_POST_TO_EDIT', + post: {} + } + } ); + + dispatcherCallback( { + action: { + type: 'EDIT_POST_RAW_CONTENT', + content: '' + } + } ); + + dispatcherCallback( { + action: { + type: 'EDIT_POST_RAW_CONTENT', + content: '


' + } + } ); + + assert( ! PostEditStore.isDirty() ); + } ); + + it( 'returns false if content changes from


to empty', function() { + dispatcherCallback( { + action: { + type: 'RECEIVE_POST_TO_EDIT', + post: {} + } + } ); + + dispatcherCallback( { + action: { + type: 'EDIT_POST_RAW_CONTENT', + content: '


' + } + } ); + + dispatcherCallback( { + action: { + type: 'EDIT_POST_RAW_CONTENT', + content: '' + } + } ); + + assert( ! PostEditStore.isDirty() ); + } ); } ); describe( '#isSaveBlocked()', function() {