Add e2e test for Merchant > Pages > Can create a new page (#38238)

* Add create-page.spec.js

Create e2e test for Critical Flow: Merchant > Pages > Can create a new page

* Add changelog entry

* Update selector for close dialog

---------

Co-authored-by: Jon Lane <jon.lane@automattic.com>
This commit is contained in:
AashikP 2023-05-12 03:53:47 +05:30 committed by GitHub
parent 1188197a2f
commit 7e3729c5fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 77 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Add e2e test for Merchant > Pages > Can create a new page

View File

@ -0,0 +1,73 @@
const { test, expect, request } = require( '@playwright/test' );
const { admin } = require( '../../test-data/data' );
const pageTitle = `Page-${ new Date().getTime().toString() }`;
test.describe( 'Can create a new page', () => {
test.use( { storageState: process.env.ADMINSTATE } );
test.afterAll( async ( { baseURL } ) => {
const base64auth = Buffer.from(
`${ admin.username }:${ admin.password }`
).toString( 'base64' );
const wpApi = await request.newContext( {
baseURL: `${ baseURL }/wp-json/wp/v2/`,
extraHTTPHeaders: {
Authorization: `Basic ${ base64auth }`,
},
} );
let response = await wpApi.get( `pages` );
const allPages = await response.json();
await allPages.forEach( async ( page ) => {
if ( page.title.rendered === pageTitle ) {
response = await wpApi.delete( `pages/${ page.id }`, {
data: {
force: true,
},
} );
}
} );
} );
test( 'can create new page', async ( { page } ) => {
await page.goto( 'wp-admin/post-new.php?post_type=page' );
const welcomeModalVisible = await page
.getByRole( 'heading', {
name: 'Welcome to the block editor',
} )
.isVisible();
if ( welcomeModalVisible ) {
await page.getByRole( 'button', { name: 'Close' } ).click();
}
await page
.getByRole( 'textbox', { name: 'Add Title' } )
.fill( pageTitle );
await page.getByRole( 'button', { name: 'Add default block' } ).click();
await page
.getByRole( 'document', {
name:
'Empty block; start writing or type forward slash to choose a block',
} )
.fill( 'Test Page' );
await page
.getByRole( 'button', { name: 'Publish', exact: true } )
.click();
await page
.getByRole( 'region', { name: 'Editor publish' } )
.getByRole( 'button', { name: 'Publish', exact: true } )
.click();
await expect(
page.getByText( `${ pageTitle } is now live.` )
).toBeVisible();
} );
} );