-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate query test to Playwright (#47995)
* Migrate query test to Playwright * Add page status Co-authored-by: pavanpatil1 <=>
- Loading branch information
1 parent
27bb402
commit 1e9c93b
Showing
5 changed files
with
118 additions
and
66 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
51 changes: 51 additions & 0 deletions
51
packages/e2e-test-utils-playwright/src/request-utils/pages.ts
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,51 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { RequestUtils } from './index'; | ||
|
||
const PAGE_STATUS = [ | ||
'publish', | ||
'future', | ||
'draft', | ||
'pending', | ||
'private', | ||
'trash', | ||
] as const; | ||
|
||
export type Page = { | ||
id: number; | ||
status: typeof PAGE_STATUS[ number ]; | ||
}; | ||
|
||
/** | ||
* Delete all pages using REST API. | ||
* | ||
* @param {RequestUtils} this | ||
*/ | ||
export async function deleteAllPages( this: RequestUtils ) { | ||
// List all pages. | ||
// https://developer.wordpress.org/rest-api/reference/pages/#list-pages | ||
const pages = await this.rest< Page[] >( { | ||
path: '/wp/v2/pages', | ||
params: { | ||
per_page: 100, | ||
|
||
status: PAGE_STATUS.join( ',' ), | ||
}, | ||
} ); | ||
|
||
// Delete all pages one by one. | ||
// https://developer.wordpress.org/rest-api/reference/pages/#delete-a-page | ||
// "/wp/v2/pages" not yet supports batch requests. | ||
await Promise.all( | ||
pages.map( ( page ) => | ||
this.rest( { | ||
method: 'DELETE', | ||
path: `/wp/v2/pages/${ page.id }`, | ||
params: { | ||
force: true, | ||
}, | ||
} ) | ||
) | ||
); | ||
} |
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 was deleted.
Oops, something went wrong.
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,64 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); | ||
|
||
test.describe( 'Query block', () => { | ||
test.beforeAll( async ( { requestUtils } ) => { | ||
await Promise.all( [ | ||
requestUtils.activatePlugin( 'gutenberg-test-query-block' ), | ||
requestUtils.deleteAllPosts(), | ||
requestUtils.deleteAllPages(), | ||
] ); | ||
await requestUtils.createPost( { title: 'Post 1', status: 'publish' } ); | ||
} ); | ||
|
||
test.afterAll( async ( { requestUtils } ) => { | ||
await Promise.all( [ | ||
requestUtils.deleteAllPosts(), | ||
requestUtils.deactivatePlugin( 'gutenberg-test-query-block' ), | ||
] ); | ||
} ); | ||
|
||
test.beforeEach( async ( { admin } ) => { | ||
await admin.createNewPost( { postType: 'page', title: 'Query Page' } ); | ||
} ); | ||
|
||
test.afterEach( async ( { requestUtils } ) => { | ||
await requestUtils.deleteAllPages(); | ||
} ); | ||
|
||
test.describe( 'Query block insertion', () => { | ||
test( 'List', async ( { page, editor } ) => { | ||
await editor.insertBlock( { name: 'core/query' } ); | ||
|
||
await editor.canvas | ||
.getByRole( 'document', { name: 'Block: Query Loop' } ) | ||
.getByRole( 'button', { name: 'Choose' } ) | ||
.click(); | ||
|
||
await page | ||
.getByRole( 'dialog', { name: 'Choose a pattern' } ) | ||
.getByRole( 'option', { name: 'Standard' } ) | ||
.click(); | ||
|
||
await expect.poll( editor.getBlocks ).toMatchObject( [ | ||
{ | ||
name: 'core/query', | ||
innerBlocks: [ | ||
{ | ||
name: 'core/post-template', | ||
innerBlocks: [ | ||
{ name: 'core/post-title' }, | ||
{ name: 'core/post-featured-image' }, | ||
{ name: 'core/post-excerpt' }, | ||
{ name: 'core/separator' }, | ||
{ name: 'core/post-date' }, | ||
], | ||
}, | ||
], | ||
}, | ||
] ); | ||
} ); | ||
} ); | ||
} ); |
1e9c93b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flaky tests detected in 1e9c93b.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4165319957
📝 Reported issues:
specs/editor/various/switch-to-draft.test.js
specs/editor/various/switch-to-draft.test.js
specs/editor/various/multi-block-selection.test.js