-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
E2E Tests: Adding a test to check CPT templates initialization
- Loading branch information
1 parent
974245c
commit 2cc39d0
Showing
6 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Using a CPT with a predefined template Should add a custom post types with a predefined template 1`] = ` | ||
"<!-- wp:image --> | ||
<figure class=\\"wp-block-image\\"><img alt=\\"\\" /></figure> | ||
<!-- /wp:image --> | ||
<!-- wp:paragraph {\\"placeholder\\":\\"Add a book description\\"} --> | ||
<p></p> | ||
<!-- /wp:paragraph --> | ||
<!-- wp:quote --> | ||
<blockquote class=\\"wp-block-quote\\"></blockquote> | ||
<!-- /wp:quote --> | ||
<!-- wp:columns --> | ||
<div class=\\"wp-block-columns has-2-columns\\"> | ||
<!-- wp:image {\\"layout\\":\\"column-1\\"} --> | ||
<figure class=\\"wp-block-image layout-column-1\\"><img alt=\\"\\" /></figure> | ||
<!-- /wp:image --> | ||
<!-- wp:paragraph {\\"placeholder\\":\\"Add a inner paragraph\\",\\"layout\\":\\"column-2\\"} --> | ||
<p class=\\"layout-column-2\\"></p> | ||
<!-- /wp:paragraph --> | ||
</div> | ||
<!-- /wp:columns -->" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import '../support/bootstrap'; | ||
import { newPost, newDesktopBrowserPage } from '../support/utils'; | ||
import { activatePlugin, deactivatePlugin } from '../support/plugins'; | ||
|
||
describe( 'Using a CPT with a predefined template', () => { | ||
beforeAll( async () => { | ||
await newDesktopBrowserPage(); | ||
await activatePlugin( 'gutenberg-test-plugin-templates' ); | ||
await newPost( 'book' ); | ||
} ); | ||
|
||
afterAll( async () => { | ||
await newDesktopBrowserPage(); | ||
await deactivatePlugin( 'gutenberg-test-plugin-templates' ); | ||
} ); | ||
|
||
it( 'Should add a custom post types with a predefined template', async () => { | ||
//Switch to Code Editor to check HTML output | ||
await page.click( '.edit-post-more-menu [aria-label="More"]' ); | ||
const codeEditorButton = ( await page.$x( '//button[contains(text(), \'Code Editor\')]' ) )[ 0 ]; | ||
await codeEditorButton.click( 'button' ); | ||
|
||
// Assert that the post already contains the template defined blocks | ||
const textEditorContent = await page.$eval( '.editor-post-text-editor', ( element ) => element.value ); | ||
expect( textEditorContent ).toMatchSnapshot(); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* Plugin Name: Gutenberg Test Plugin, Templates | ||
* Plugin URI: https://github.com/WordPress/gutenberg | ||
* Author: Gutenberg Team | ||
* | ||
* @package gutenberg-test-templates | ||
*/ | ||
|
||
/** | ||
* Registers a book CPT with a template | ||
*/ | ||
function register_book_type() { | ||
$args = array( | ||
'public' => true, | ||
'label' => 'Books', | ||
'show_in_rest' => true, | ||
'template' => array( | ||
array( 'core/image' ), | ||
array( | ||
'core/paragraph', | ||
array( | ||
'placeholder' => 'Add a book description', | ||
), | ||
), | ||
array( 'core/quote' ), | ||
array( | ||
'core/columns', | ||
array(), | ||
array( | ||
array( 'core/image', array( 'layout' => 'column-1' ) ), | ||
array( | ||
'core/paragraph', | ||
array( | ||
'placeholder' => 'Add a inner paragraph', | ||
'layout' => 'column-2', | ||
), | ||
), | ||
), | ||
), | ||
), | ||
); | ||
register_post_type( 'book', $args ); | ||
} | ||
|
||
add_action( 'init', 'register_book_type' ); |