Skip to content

Commit

Permalink
Add: End 2 End tests on the sidebar premalinkl for CPT's. (#13060)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta authored Dec 21, 2018
1 parent 3f23b1a commit d8f3ec3
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/e2e/specs/sidebar-permalink-panel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
} );
} );
68 changes: 68 additions & 0 deletions test/e2e/test-plugins/custom-post-types.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Plugin Name: Gutenberg Test Custom Post Types
* Plugin URI: https://github.com/WordPress/gutenberg
* Author: Gutenberg Team
*
* @package gutenberg-test-custom-post-types
*/

/**
* Registers a custom post type that is public_queryable but not public.
*/
function public_queryable_true_public_false_cpt() {
$public_queryable_true_public_false = 'public_q_not_public';
register_post_type(
$public_queryable_true_public_false,
array(
'label' => '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' );

0 comments on commit d8f3ec3

Please sign in to comment.