Skip to content
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

Add: End 2 End tests on the sidebar permalink editor for CPT's. #13060

Merged
merged 5 commits into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' );