diff --git a/packages/editor/src/components/post-pending-status/check.js b/packages/editor/src/components/post-pending-status/check.js
index 54b155e8334a94..347cb6d7272276 100644
--- a/packages/editor/src/components/post-pending-status/check.js
+++ b/packages/editor/src/components/post-pending-status/check.js
@@ -1,19 +1,24 @@
/**
* WordPress dependencies
*/
-import { compose } from '@wordpress/compose';
-import { withSelect } from '@wordpress/data';
+import { useSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
import { store as editorStore } from '../../store';
-export function PostPendingStatusCheck( {
- hasPublishAction,
- isPublished,
- children,
-} ) {
+export function PostPendingStatusCheck( { children } ) {
+ const { hasPublishAction, isPublished } = useSelect( ( select ) => {
+ const { isCurrentPostPublished, getCurrentPost } =
+ select( editorStore );
+ return {
+ hasPublishAction:
+ getCurrentPost()._links?.[ 'wp:action-publish' ] ?? false,
+ isPublished: isCurrentPostPublished(),
+ };
+ }, [] );
+
if ( isPublished || ! hasPublishAction ) {
return null;
}
@@ -21,15 +26,4 @@ export function PostPendingStatusCheck( {
return children;
}
-export default compose(
- withSelect( ( select ) => {
- const { isCurrentPostPublished, getCurrentPostType, getCurrentPost } =
- select( editorStore );
- return {
- hasPublishAction:
- getCurrentPost()._links?.[ 'wp:action-publish' ] ?? false,
- isPublished: isCurrentPostPublished(),
- postType: getCurrentPostType(),
- };
- } )
-)( PostPendingStatusCheck );
+export default PostPendingStatusCheck;
diff --git a/packages/editor/src/components/post-pending-status/test/check.js b/packages/editor/src/components/post-pending-status/test/check.js
index 57bd0b12afc6c0..c5a338838dbdc9 100644
--- a/packages/editor/src/components/post-pending-status/test/check.js
+++ b/packages/editor/src/components/post-pending-status/test/check.js
@@ -3,27 +3,49 @@
*/
import { render, screen } from '@testing-library/react';
+/**
+ * WordPress dependencies
+ */
+import { useSelect } from '@wordpress/data';
+
/**
* Internal dependencies
*/
import { PostPendingStatusCheck } from '../check';
+jest.mock( '@wordpress/data/src/components/use-select', () => {
+ // This allows us to tweak the returned value on each test.
+ const mock = jest.fn();
+ return mock;
+} );
+
+function setupUseSelectMock( hasPublishAction ) {
+ useSelect.mockImplementation( ( cb ) => {
+ return cb( () => ( {
+ isCurrentPostPublished: () => false,
+ getCurrentPost: () => ( {
+ _links: {
+ 'wp:action-publish': hasPublishAction,
+ },
+ } ),
+ } ) );
+ } );
+}
+
describe( 'PostPendingStatusCheck', () => {
it( "should not render anything if the user doesn't have the right capabilities", () => {
- render(
-
- status
-
- );
+ setupUseSelectMock( false );
+
+ render( status );
+
expect( screen.queryByText( 'status' ) ).not.toBeInTheDocument();
} );
it( 'should render if the user has the correct capability', () => {
- render(
-
- status
-
- );
+ setupUseSelectMock( true );
+
+ render( status );
+
expect( screen.getByText( 'status' ) ).toBeVisible();
} );
} );