From 544f9ed3e5a683cd569abb9f60c26aa12bd03d57 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Fri, 3 Mar 2023 13:12:18 +0400 Subject: [PATCH 1/2] Migrate CPT e2e tests to Playwright --- .../editor/plugins/custom-post-types.spec.js | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 test/e2e/specs/editor/plugins/custom-post-types.spec.js diff --git a/test/e2e/specs/editor/plugins/custom-post-types.spec.js b/test/e2e/specs/editor/plugins/custom-post-types.spec.js new file mode 100644 index 0000000000000..f0448face2671 --- /dev/null +++ b/test/e2e/specs/editor/plugins/custom-post-types.spec.js @@ -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(); + 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(); + } ); +} ); From 33823a69e7085feed1742953e4d9c34f0c28e704 Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Mon, 24 Apr 2023 16:10:05 +0400 Subject: [PATCH 2/2] Remove previous test file --- .../editor/plugins/custom-post-types.test.js | 81 ------------------- 1 file changed, 81 deletions(-) delete mode 100644 packages/e2e-tests/specs/editor/plugins/custom-post-types.test.js diff --git a/packages/e2e-tests/specs/editor/plugins/custom-post-types.test.js b/packages/e2e-tests/specs/editor/plugins/custom-post-types.test.js deleted file mode 100644 index 61c374ef5e5ae..0000000000000 --- a/packages/e2e-tests/specs/editor/plugins/custom-post-types.test.js +++ /dev/null @@ -1,81 +0,0 @@ -/** - * WordPress dependencies - */ -import { - activatePlugin, - createNewPost, - deactivatePlugin, - publishPost, - findSidebarPanelWithTitle, - clickBlockAppender, -} from '@wordpress/e2e-test-utils'; - -const openPageAttributesPanel = async () => { - const openButton = await findSidebarPanelWithTitle( 'Page Attributes' ); - - // Get the classes from the panel. - const buttonClassName = await ( - await openButton.getProperty( 'className' ) - ).jsonValue(); - - // Open the panel if needed. - if ( -1 === buttonClassName.indexOf( 'is-opened' ) ) { - await openButton.click(); - } -}; - -describe( 'Test Custom Post Types', () => { - beforeAll( async () => { - await activatePlugin( 'gutenberg-test-custom-post-types' ); - } ); - - afterAll( async () => { - await deactivatePlugin( 'gutenberg-test-custom-post-types' ); - } ); - - it( 'should be able to create an hierarchical post without title support', async () => { - const PARENT_PAGE_INPUT = - '.editor-page-attributes__parent input:not([disabled])'; - const SUGGESTION = - '.editor-page-attributes__parent .components-form-token-field__suggestion:first-child'; - - // Create a parent post. - await createNewPost( { postType: 'hierar-no-title' } ); - await clickBlockAppender(); - await page.keyboard.type( 'Parent Post' ); - await publishPost(); - // Create a post that is a child of the previously created post. - await createNewPost( { postType: 'hierar-no-title' } ); - await openPageAttributesPanel(); - await page.waitForSelector( PARENT_PAGE_INPUT ); - await page.click( PARENT_PAGE_INPUT ); - await page.waitForSelector( SUGGESTION ); - const optionToSelect = await page.$( SUGGESTION ); - const valueToSelect = await page.$eval( - SUGGESTION, - ( element ) => element.textContent - ); - await optionToSelect.click(); - await clickBlockAppender(); - await page.keyboard.type( 'Child Post' ); - await publishPost(); - // Reload the child post and verify it is still correctly selected as a child post. - await page.reload(); - await page.waitForSelector( PARENT_PAGE_INPUT ); - // Wait for the list of suggestions to fetch - // There should be a better way to do that. - await page.waitForFunction( - ( [ value, inputSelector ] ) => - document.querySelector( inputSelector ).value === value, - {}, - [ valueToSelect, PARENT_PAGE_INPUT ] - ); - } ); - it( 'should create a cpt with a legacy block in its template without WSOD', async () => { - await createNewPost( { postType: 'leg_block_in_tpl' } ); - await clickBlockAppender(); - await page.keyboard.type( 'Hello there' ); - await page.waitForSelector( '[data-type="core/embed"]' ); - await publishPost(); - } ); -} );