From 328b12035424a99fb71b9a93c767d906dc5f0e1f Mon Sep 17 00:00:00 2001 From: Jorge Date: Fri, 21 Dec 2018 15:37:46 +0000 Subject: [PATCH 1/5] Add: End 2 End tests on the sidebar link panel for cpts. --- .../e2e/specs/sidebar-permalink-panel.test.js | 36 +++++++++++++++ test/e2e/test-plugins/custom-cpts.php | 45 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 test/e2e/test-plugins/custom-cpts.php diff --git a/test/e2e/specs/sidebar-permalink-panel.test.js b/test/e2e/specs/sidebar-permalink-panel.test.js index 03e24ff34ec3db..e3cf03884dea20 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-cpts' ); + } ); + + afterAll( async () => { + await deactivatePlugin( 'gutenberg-test-custom-cpts' ); + } ); + 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 public 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 public 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 public 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-cpts.php b/test/e2e/test-plugins/custom-cpts.php new file mode 100644 index 00000000000000..8cce5ac3057489 --- /dev/null +++ b/test/e2e/test-plugins/custom-cpts.php @@ -0,0 +1,45 @@ + 'PublicQNotPublic', + 'show_in_rest' => true, + 'public' => false, + 'publicly_queryable' => true, + 'supports' => [ 'title', 'editor', 'revisions' ], + 'show_ui' => true, + 'show_in_menu' => true, + ] ); +} ); + +add_action( 'init', function() { + register_post_type( 'not_public_q_public', [ + 'label' => 'NotPublicQPublic', + 'show_in_rest' => true, + 'public' => true, + 'publicly_queryable' => false, + 'supports' => [ 'title', 'editor', 'revisions' ], + 'show_ui' => true, + 'show_in_menu' => true, + ] ); +} ); + + +add_action( 'init', function() { + register_post_type( 'public_q_public', [ + 'label' => 'PublicQueryPublic', + 'show_in_rest' => true, + 'public' => true, + 'publicly_queryable' => true, + 'supports' => [ 'title', 'editor', 'revisions' ], + 'show_ui' => true, + 'show_in_menu' => true, + ] ); +} ); From 4e7fa0c2ba457aba6481295d6ff0384fa850b3f3 Mon Sep 17 00:00:00 2001 From: Matthew Riley MacPherson Date: Fri, 21 Dec 2018 16:59:07 +0000 Subject: [PATCH 2/5] chore: Tweak wording in tests --- test/e2e/specs/sidebar-permalink-panel.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/e2e/specs/sidebar-permalink-panel.test.js b/test/e2e/specs/sidebar-permalink-panel.test.js index e3cf03884dea20..4821b21b840a74 100644 --- a/test/e2e/specs/sidebar-permalink-panel.test.js +++ b/test/e2e/specs/sidebar-permalink-panel.test.js @@ -42,7 +42,7 @@ describe( 'Sidebar Permalink Panel', () => { expect( await findSidebarPanelWithTitle( 'Permalink' ) ).toBeUndefined(); } ); - it( 'should not render link panel when post is public queryable but not public', async () => { + 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(); @@ -51,7 +51,7 @@ describe( 'Sidebar Permalink Panel', () => { expect( await findSidebarPanelWithTitle( 'Permalink' ) ).toBeUndefined(); } ); - it( 'should not render link panel when post is public but not public queryable', async () => { + 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(); @@ -60,7 +60,7 @@ describe( 'Sidebar Permalink Panel', () => { expect( await findSidebarPanelWithTitle( 'Permalink' ) ).toBeUndefined(); } ); - it( 'should render link panel when post is public and public queryable', async () => { + 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(); From 0613f14cd18e5bccff8fdc013a22c326a3563364 Mon Sep 17 00:00:00 2001 From: Matthew Riley MacPherson Date: Fri, 21 Dec 2018 17:59:06 +0000 Subject: [PATCH 3/5] chore: Change PHP to use array() --- test/e2e/test-plugins/custom-cpts.php | 55 +++++++++++++-------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/test/e2e/test-plugins/custom-cpts.php b/test/e2e/test-plugins/custom-cpts.php index 8cce5ac3057489..7bece694619cac 100644 --- a/test/e2e/test-plugins/custom-cpts.php +++ b/test/e2e/test-plugins/custom-cpts.php @@ -8,38 +8,37 @@ */ add_action( 'init', function() { - register_post_type( 'public_q_not_public', [ - 'label' => 'PublicQNotPublic', - 'show_in_rest' => true, - 'public' => false, - 'publicly_queryable' => true, - 'supports' => [ 'title', 'editor', 'revisions' ], - 'show_ui' => true, - 'show_in_menu' => true, - ] ); + register_post_type( 'public_q_not_public', array( + 'label' => 'PublicQNotPublic', + 'show_in_rest' => true, + 'public' => false, + 'publicly_queryable' => true, + 'supports' => [ 'title', 'editor', 'revisions' ], + 'show_ui' => true, + 'show_in_menu' => true, + ) ); } ); add_action( 'init', function() { - register_post_type( 'not_public_q_public', [ - 'label' => 'NotPublicQPublic', - 'show_in_rest' => true, - 'public' => true, - 'publicly_queryable' => false, - 'supports' => [ 'title', 'editor', 'revisions' ], - 'show_ui' => true, - 'show_in_menu' => true, - ] ); + register_post_type( 'not_public_q_public', array( + 'label' => 'NotPublicQPublic', + 'show_in_rest' => true, + 'public' => true, + 'publicly_queryable' => false, + 'supports' => [ 'title', 'editor', 'revisions' ], + 'show_ui' => true, + 'show_in_menu' => true, + ) ); } ); - add_action( 'init', function() { - register_post_type( 'public_q_public', [ - 'label' => 'PublicQueryPublic', - 'show_in_rest' => true, - 'public' => true, - 'publicly_queryable' => true, - 'supports' => [ 'title', 'editor', 'revisions' ], - 'show_ui' => true, - 'show_in_menu' => true, - ] ); + register_post_type( 'public_q_public', array( + 'label' => 'PublicQueryPublic', + 'show_in_rest' => true, + 'public' => true, + 'publicly_queryable' => true, + 'supports' => [ 'title', 'editor', 'revisions' ], + 'show_ui' => true, + 'show_in_menu' => true, + ) ); } ); From b7a6ea0c1e103b3ca6c71a2701e6573c0d2f95a8 Mon Sep 17 00:00:00 2001 From: Jorge Date: Fri, 21 Dec 2018 18:11:08 +0000 Subject: [PATCH 4/5] chore: reformate identation --- test/e2e/test-plugins/custom-cpts.php | 84 ++++++++++++++++----------- 1 file changed, 51 insertions(+), 33 deletions(-) diff --git a/test/e2e/test-plugins/custom-cpts.php b/test/e2e/test-plugins/custom-cpts.php index 7bece694619cac..d45ec792b3bdfd 100644 --- a/test/e2e/test-plugins/custom-cpts.php +++ b/test/e2e/test-plugins/custom-cpts.php @@ -7,38 +7,56 @@ * @package gutenberg-test-custom-cpts */ -add_action( 'init', function() { - register_post_type( 'public_q_not_public', array( - 'label' => 'PublicQNotPublic', - 'show_in_rest' => true, - 'public' => false, - 'publicly_queryable' => true, - 'supports' => [ 'title', 'editor', 'revisions' ], - 'show_ui' => true, - 'show_in_menu' => true, - ) ); -} ); +add_action( + 'init', + function() { + register_post_type( + 'public_q_not_public', + array( + 'label' => 'PublicQNotPublic', + 'show_in_rest' => true, + 'public' => false, + 'publicly_queryable' => true, + 'supports' => [ 'title', 'editor', 'revisions' ], + 'show_ui' => true, + 'show_in_menu' => true, + ) + ); + } +); -add_action( 'init', function() { - register_post_type( 'not_public_q_public', array( - 'label' => 'NotPublicQPublic', - 'show_in_rest' => true, - 'public' => true, - 'publicly_queryable' => false, - 'supports' => [ 'title', 'editor', 'revisions' ], - 'show_ui' => true, - 'show_in_menu' => true, - ) ); -} ); +add_action( + 'init', + function() { + register_post_type( + 'not_public_q_public', + array( + 'label' => 'NotPublicQPublic', + 'show_in_rest' => true, + 'public' => true, + 'publicly_queryable' => false, + 'supports' => [ 'title', 'editor', 'revisions' ], + 'show_ui' => true, + 'show_in_menu' => true, + ) + ); + } +); -add_action( 'init', function() { - register_post_type( 'public_q_public', array( - 'label' => 'PublicQueryPublic', - 'show_in_rest' => true, - 'public' => true, - 'publicly_queryable' => true, - 'supports' => [ 'title', 'editor', 'revisions' ], - 'show_ui' => true, - 'show_in_menu' => true, - ) ); -} ); +add_action( + 'init', + function() { + register_post_type( + 'public_q_public', + array( + 'label' => 'PublicQueryPublic', + 'show_in_rest' => true, + 'public' => true, + 'publicly_queryable' => true, + 'supports' => [ 'title', 'editor', 'revisions' ], + 'show_ui' => true, + 'show_in_menu' => true, + ) + ); + } +); From 5aad5bb6775ae464ff2d236dad64835633b28808 Mon Sep 17 00:00:00 2001 From: Jorge Date: Fri, 21 Dec 2018 18:22:38 +0000 Subject: [PATCH 5/5] chore: Make the test code more descriptive --- .../e2e/specs/sidebar-permalink-panel.test.js | 4 +- test/e2e/test-plugins/custom-cpts.php | 62 ----------------- test/e2e/test-plugins/custom-post-types.php | 68 +++++++++++++++++++ 3 files changed, 70 insertions(+), 64 deletions(-) delete mode 100644 test/e2e/test-plugins/custom-cpts.php create mode 100644 test/e2e/test-plugins/custom-post-types.php diff --git a/test/e2e/specs/sidebar-permalink-panel.test.js b/test/e2e/specs/sidebar-permalink-panel.test.js index 4821b21b840a74..cff6ce3ea7bec5 100644 --- a/test/e2e/specs/sidebar-permalink-panel.test.js +++ b/test/e2e/specs/sidebar-permalink-panel.test.js @@ -15,11 +15,11 @@ import { activatePlugin, deactivatePlugin } from '../support/plugins'; // 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-cpts' ); + await activatePlugin( 'gutenberg-test-custom-post-types' ); } ); afterAll( async () => { - await deactivatePlugin( 'gutenberg-test-custom-cpts' ); + await deactivatePlugin( 'gutenberg-test-custom-post-types' ); } ); it( 'should not render permalink sidebar panel while the post is new', async () => { diff --git a/test/e2e/test-plugins/custom-cpts.php b/test/e2e/test-plugins/custom-cpts.php deleted file mode 100644 index d45ec792b3bdfd..00000000000000 --- a/test/e2e/test-plugins/custom-cpts.php +++ /dev/null @@ -1,62 +0,0 @@ - 'PublicQNotPublic', - 'show_in_rest' => true, - 'public' => false, - 'publicly_queryable' => true, - 'supports' => [ 'title', 'editor', 'revisions' ], - 'show_ui' => true, - 'show_in_menu' => true, - ) - ); - } -); - -add_action( - 'init', - function() { - register_post_type( - 'not_public_q_public', - array( - 'label' => 'NotPublicQPublic', - 'show_in_rest' => true, - 'public' => true, - 'publicly_queryable' => false, - 'supports' => [ 'title', 'editor', 'revisions' ], - 'show_ui' => true, - 'show_in_menu' => true, - ) - ); - } -); - -add_action( - 'init', - function() { - register_post_type( - 'public_q_public', - array( - 'label' => 'PublicQueryPublic', - 'show_in_rest' => true, - 'public' => true, - 'publicly_queryable' => true, - 'supports' => [ 'title', 'editor', 'revisions' ], - 'show_ui' => true, - 'show_in_menu' => true, - ) - ); - } -); 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 00000000000000..6262c89f66d376 --- /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' );