Skip to content

Commit

Permalink
Fix unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
desaiuditd committed Feb 9, 2024
1 parent 97e7ba9 commit 1ccdeda
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
16 changes: 0 additions & 16 deletions packages/editor/src/components/post-preview-button/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,6 @@ describe( 'PostPreviewButton', () => {
).toBeInTheDocument();
} );

it( 'should be disabled if post is not saveable.', () => {
mockUseSelect( { isEditedPostSaveable: () => false } );

render( <PostPreviewButton /> );

expect( screen.getByRole( 'button' ) ).toBeDisabled();
} );

it( 'should not be disabled if post is saveable.', () => {
mockUseSelect( { isEditedPostSaveable: () => true } );

render( <PostPreviewButton /> );

expect( screen.getByRole( 'button' ) ).toBeEnabled();
} );

it( 'should set `href` to edited post preview link if specified.', () => {
const url = 'https://wordpress.org';
mockUseSelect( {
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
21 changes: 21 additions & 0 deletions packages/editor/src/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 1ccdeda

Please sign in to comment.