New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable the Preview button when post type isn't viewable #6232

Merged
merged 5 commits into from Apr 18, 2018

Conversation

Projects
None yet
3 participants
@danielbachhuber
Member

danielbachhuber commented Apr 18, 2018

Description

In the classic editor, the preview button is only available if is_post_type_viewable returns true. We are updating the logic to follow the same behavior.

Fixes #5749

Previously #5770 #6120

How Has This Been Tested?

Register a post type with publicly_queryable set to false.
E.g:

function create_product_type() {
	register_post_type( 'acme_product',
		array(
			'label'  => 'Product',
			'labels' => array(
				'name' => __( 'Products' ),
				'singular_name' => __( 'Product' )
			),
			'public' => true,
			'show_in_rest' => true,
			'publicly_queryable' => false,
		)
	);
}
add_action( 'init', 'create_product_type' );

Verify preview button is not available for posts of this Post Type.

image

image

@danielbachhuber danielbachhuber requested a review from pento Apr 18, 2018

@danielbachhuber

This comment has been minimized.

Member

danielbachhuber commented Apr 18, 2018

@pento There doesn't seem to be a good way to test a component using ifCondition. Specifically, I tried the following and didn't see what I expected:

it( 'should be null if the post type is not viewable', () => {
	const wrapper = shallow(
		<PostPreviewButton
			postId={ 1 }
			isSaveable
			isViewable={ false }
			link="https://wordpress.org/?p=1" />
	);
	expect( wrapper ).toBe( null );
} );

Is there a direction you can point me in, or should we punt on it for now?

@gziolo

This comment has been minimized.

Member

gziolo commented Apr 18, 2018

@danielbachhuber, given that isViewable is coming from REST API and is never used inside the component because HOC bails out early when it is set to false, it won't work this way. In general, we don't test all those HOCs with unit tests. You could do it, but it's usually too much work to mock all dependencies which only slows us down when doing refactoring later. See also this section in our testing docs: https://github.com/WordPress/gutenberg/blob/master/docs/testing-overview.md#pain-points.

@youknowriad

LGTM 👍

@youknowriad youknowriad merged commit d6d950a into master Apr 18, 2018

2 checks passed

codecov/project 43.9% (-0.02%) compared to 1d05c53
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@youknowriad

This comment has been minimized.

Contributor

youknowriad commented Apr 18, 2018

Merged to include in the release.

@youknowriad youknowriad deleted the 5749-disable-preview-two branch Apr 18, 2018

nuzzio added a commit to nuzzio/gutenberg that referenced this pull request Apr 25, 2018

Disable the Preview button when post type isn't viewable (WordPress#6232
)

* Add tests for `viewable` REST API param

* Minor corrections to test and docs

* Disable the Preview button when post type isn't viewable

* Fix coding style issue

* Add e2e assertion for the preview button
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment