From 1ccdedae001041530e2c3b7baca9a089a2271561 Mon Sep 17 00:00:00 2001 From: Udit Desai Date: Sun, 6 Jun 2021 15:09:28 +1000 Subject: [PATCH] Fix unit tests. --- .../post-preview-button/test/index.js | 16 -------------- packages/editor/src/store/selectors.js | 2 +- packages/editor/src/store/test/selectors.js | 21 +++++++++++++++++++ 3 files changed, 22 insertions(+), 17 deletions(-) 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 e34c05caa178bd..d9a8fd0efa2243 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 18010511b53902..bdb51e3b7865e1 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 1de25604ebd7e3..546adfe34afcca 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', () => {