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 query test to Playwright #47995

Merged
merged 2 commits into from
Feb 13, 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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
createNavigationMenu,
deleteAllMenus,
} from './menus';
import { deleteAllPages } from './pages';
import { resetPreferences } from './preferences';
import { getSiteSettings, updateSiteSettings } from './site-settings';
import { deleteAllWidgets, addWidgetBlock } from './widgets';
Expand Down Expand Up @@ -147,6 +148,7 @@ class RequestUtils {
deleteAllUsers = deleteAllUsers.bind( this );
getSiteSettings = getSiteSettings.bind( this );
updateSiteSettings = updateSiteSettings.bind( this );
deleteAllPages = deleteAllPages.bind( this );
}

export type { StorageState };
Expand Down
51 changes: 51 additions & 0 deletions packages/e2e-test-utils-playwright/src/request-utils/pages.ts
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,
},
} )
)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface Post {
}

export interface CreatePostPayload {
title?: string;
content: string;
status: 'publish' | 'future' | 'draft' | 'pending' | 'private';
}
Expand Down
66 changes: 0 additions & 66 deletions packages/e2e-tests/specs/editor/blocks/query.test.js

This file was deleted.

64 changes: 64 additions & 0 deletions test/e2e/specs/editor/blocks/query.spec.js
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' },
],
},
],
},
] );
} );
} );
} );