diff --git a/test/e2e/specs/sidebar-permalink-panel.test.js b/test/e2e/specs/sidebar-permalink-panel.test.js index 03e24ff34ec3d..cff6ce3ea7bec 100644 --- a/test/e2e/specs/sidebar-permalink-panel.test.js +++ b/test/e2e/specs/sidebar-permalink-panel.test.js @@ -7,12 +7,21 @@ import { openDocumentSettingsSidebar, publishPost, } from '../support/utils'; +import { activatePlugin, deactivatePlugin } from '../support/plugins'; // This tests are not together with the remaining sidebar tests, // because we need to publish/save a post, to correctly test the permalink panel. // The sidebar test suit enforces that focus is never lost, but during save operations // the focus is lost and a new element is focused once the save is completed. describe( 'Sidebar Permalink Panel', () => { + beforeAll( async () => { + await activatePlugin( 'gutenberg-test-custom-post-types' ); + } ); + + afterAll( async () => { + await deactivatePlugin( 'gutenberg-test-custom-post-types' ); + } ); + it( 'should not render permalink sidebar panel while the post is new', async () => { await newPost(); await openDocumentSettingsSidebar(); @@ -32,4 +41,31 @@ describe( 'Sidebar Permalink Panel', () => { } ); expect( await findSidebarPanelWithTitle( 'Permalink' ) ).toBeUndefined(); } ); + + it( 'should not render link panel when post is publicly queryable but not public', async () => { + await newPost( { postType: 'public_q_not_public' } ); + await page.keyboard.type( 'aaaaa' ); + await publishPost(); + // Start editing again. + await page.type( '.editor-post-title__input', ' (Updated)' ); + expect( await findSidebarPanelWithTitle( 'Permalink' ) ).toBeUndefined(); + } ); + + it( 'should not render link panel when post is public but not publicly queryable', async () => { + await newPost( { postType: 'not_public_q_public' } ); + await page.keyboard.type( 'aaaaa' ); + await publishPost(); + // Start editing again. + await page.type( '.editor-post-title__input', ' (Updated)' ); + expect( await findSidebarPanelWithTitle( 'Permalink' ) ).toBeUndefined(); + } ); + + it( 'should render link panel when post is public and publicly queryable', async () => { + await newPost( { postType: 'public_q_public' } ); + await page.keyboard.type( 'aaaaa' ); + await publishPost(); + // Start editing again. + await page.type( '.editor-post-title__input', ' (Updated)' ); + expect( await findSidebarPanelWithTitle( 'Permalink' ) ).toBeDefined(); + } ); } ); diff --git a/test/e2e/test-plugins/custom-post-types.php b/test/e2e/test-plugins/custom-post-types.php new file mode 100644 index 0000000000000..6262c89f66d37 --- /dev/null +++ b/test/e2e/test-plugins/custom-post-types.php @@ -0,0 +1,68 @@ + 'PublicQNotPublic', + 'show_in_rest' => true, + 'public' => false, + 'publicly_queryable' => true, + 'supports' => array( 'title', 'editor', 'revisions' ), + 'show_ui' => true, + 'show_in_menu' => true, + ) + ); +} +add_action( 'init', 'public_queryable_true_public_false_cpt' ); + +/** + * Registers a custom post type that is public but not public_queryable. + */ +function public_queryable_false_public_true_cpt() { + $public_queryable_false_public_true = 'not_public_q_public'; + register_post_type( + $public_queryable_false_public_true, + array( + 'label' => 'NotPublicQPublic', + 'show_in_rest' => true, + 'public' => true, + 'publicly_queryable' => false, + 'supports' => array( 'title', 'editor', 'revisions' ), + 'show_ui' => true, + 'show_in_menu' => true, + ) + ); +} +add_action( 'init', 'public_queryable_false_public_true_cpt' ); + +/** + * Registers a custom post type that is public and public_queryable. + */ +function public_queryable_true_public_true_cpt() { + $public_queryable_true_public_true = 'public_q_public'; + register_post_type( + $public_queryable_true_public_true, + array( + 'label' => 'PublicQueryPublic', + 'show_in_rest' => true, + 'public' => true, + 'publicly_queryable' => true, + 'supports' => array( 'title', 'editor', 'revisions' ), + 'show_ui' => true, + 'show_in_menu' => true, + ) + ); +} +add_action( 'init', 'public_queryable_true_public_true_cpt' );