@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
41 lines (32 loc) • 1.15 kB
JavaScript
import { render, screen } from '@testing-library/react';
import { useSelect } from '@wordpress/data';
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", () => {
setupUseSelectMock( false );
render( <PostPendingStatusCheck>status</PostPendingStatusCheck> );
expect( screen.queryByText( 'status' ) ).not.toBeInTheDocument();
} );
it( 'should render if the user has the correct capability', () => {
setupUseSelectMock( true );
render( <PostPendingStatusCheck>status</PostPendingStatusCheck> );
expect( screen.getByText( 'status' ) ).toBeVisible();
} );
} );