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

Migrate CPT e2e tests to Playwright #50031

Merged
merged 2 commits into from
Apr 25, 2023
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

This file was deleted.

79 changes: 79 additions & 0 deletions test/e2e/specs/editor/plugins/custom-post-types.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'Test Custom Post Types', () => {
test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.activatePlugin( 'gutenberg-test-custom-post-types' );
} );

test.afterAll( async ( { requestUtils } ) => {
await requestUtils.deactivatePlugin(
'gutenberg-test-custom-post-types'
);
} );

test( 'should be able to create an hierarchical post without title support', async ( {
admin,
editor,
page,
} ) => {
await admin.createNewPost( { postType: 'hierar-no-title' } );
await page.click( 'role=button[name="Add default block"i]' );
await page.keyboard.type( 'Parent Post' );
await editor.publishPost();

// Create a post that is a child of the previously created post.
await admin.createNewPost( { postType: 'hierar-no-title' } );
await editor.openDocumentSettingsSidebar();
await page
.getByRole( 'region', { name: 'Editor settings' } )
.getByRole( 'button', {
name: 'Hierarchical No Title',
} )
.click();

// Open the Document -> Page Attributes panel.
await page.getByRole( 'button', { name: 'Page Attributes' } ).click();

const parentPageLocator = page.getByRole( 'combobox', {
name: 'Parent Page',
} );

await parentPageLocator.click();
await page.getByRole( 'listbox' ).getByRole( 'option' ).first().click();
Copy link
Member Author

@Mamaduka Mamaduka Apr 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test doesn't care which option we select; only that selection remains after reloading. The options are populated based on the post ID, so it's hard to provide them explicitly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Could we add some parent locator to make it a bit easier to read here? There could be multiple listboxs on the same page.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to do that, but there's nothing specific besides the "Editor settings" region, and if there is another listbox, it will be in the same region.

I guess the Combobox could use some improvements :)

Screenshot

CleanShot 2023-04-25 at 13 11 12

const parentPage = await parentPageLocator.inputValue();

await page.click( 'role=button[name="Add default block"i]' );
await page.keyboard.type( 'Child Post' );
await editor.publishPost();
await page.reload();

// Confirm parent page selection matches after reloading.
await expect( parentPageLocator ).toHaveValue( parentPage );
} );

test( 'should create a cpt with a legacy block in its template without WSOD', async ( {
admin,
editor,
page,
} ) => {
await admin.createNewPost( { postType: 'leg_block_in_tpl' } );
await page.click( 'role=button[name="Add default block"i]' );
await page.keyboard.type( 'Hello there' );

await expect.poll( editor.getBlocks ).toMatchObject( [
{
name: 'core/embed',
attributes: { providerNameSlug: 'wordpress-tv' },
},
{
name: 'core/paragraph',
attributes: { content: 'Hello there' },
},
] );

await editor.publishPost();
} );
} );