diff --git a/packages/editor/src/components/post-preview-button/test/index.js b/packages/editor/src/components/post-preview-button/test/index.js index e34c05caa178b..d9a8fd0efa224 100644 --- a/packages/editor/src/components/post-preview-button/test/index.js +++ b/packages/editor/src/components/post-preview-button/test/index.js @@ -139,22 +139,6 @@ describe( 'PostPreviewButton', () => { ).toBeInTheDocument(); } ); - it( 'should be disabled if post is not saveable.', () => { - mockUseSelect( { isEditedPostSaveable: () => false } ); - - render( ); - - expect( screen.getByRole( 'button' ) ).toBeDisabled(); - } ); - - it( 'should not be disabled if post is saveable.', () => { - mockUseSelect( { isEditedPostSaveable: () => true } ); - - render( ); - - expect( screen.getByRole( 'button' ) ).toBeEnabled(); - } ); - it( 'should set `href` to edited post preview link if specified.', () => { const url = 'https://wordpress.org'; mockUseSelect( { diff --git a/packages/editor/src/store/selectors.js b/packages/editor/src/store/selectors.js index 18010511b5390..bdb51e3b7865e 100644 --- a/packages/editor/src/store/selectors.js +++ b/packages/editor/src/store/selectors.js @@ -1035,7 +1035,7 @@ export function getPermalinkParts( state ) { * @return {boolean} Is locked. */ export function isPostLocked( state ) { - return state.postLock.isLocked; + return state.postLock?.isLocked ?? false; } /** diff --git a/packages/editor/src/store/test/selectors.js b/packages/editor/src/store/test/selectors.js index 1de25604ebd7e..546adfe34afcc 100644 --- a/packages/editor/src/store/test/selectors.js +++ b/packages/editor/src/store/test/selectors.js @@ -1421,6 +1421,27 @@ describe( 'selectors', () => { expect( isEditedPostSaveable( state ) ).toBe( true ); } ); + + it( 'should return false if the post is locked', () => { + const state = { + editor: { + present: { + blocks: { + value: [], + }, + edits: {}, + }, + }, + initialEdits: {}, + currentPost: {}, + saving: {}, + postLock: { + isLocked: true, + }, + }; + + expect( isEditedPostSaveable( state ) ).toBe( false ); + } ); } ); describe( 'isEditedPostAutosaveable', () => {