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 switch-to-draft to Playwright #48120

Merged
merged 2 commits into from
Feb 21, 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,7 +26,7 @@ import {
createNavigationMenu,
deleteAllMenus,
} from './menus';
import { deleteAllPages } from './pages';
import { deleteAllPages, createPage } from './pages';
import { resetPreferences } from './preferences';
import { getSiteSettings, updateSiteSettings } from './site-settings';
import { deleteAllWidgets, addWidgetBlock } from './widgets';
Expand Down Expand Up @@ -149,6 +149,7 @@ class RequestUtils {
getSiteSettings = getSiteSettings.bind( this );
updateSiteSettings = updateSiteSettings.bind( this );
deleteAllPages = deleteAllPages.bind( this );
createPage = createPage.bind( this );
}

export type { StorageState };
Expand Down
50 changes: 40 additions & 10 deletions packages/e2e-test-utils-playwright/src/request-utils/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,25 @@ export type Page = {
status: typeof PAGE_STATUS[ number ];
};

export type CreatePagePayload = {
title?: string;
content?: string;
status: typeof PAGE_STATUS[ number ];
date?: string;
date_gmt?: string;
};

export async function deletePage( this: RequestUtils, id: number ) {
// https://developer.wordpress.org/rest-api/reference/pages/#delete-a-page
return await this.rest( {
method: 'DELETE',
path: `/wp/v2/pages/${ id }`,
params: {
force: true,
},
} );
}

/**
* Delete all pages using REST API.
*
Expand All @@ -35,17 +54,28 @@ export async function deleteAllPages( this: RequestUtils ) {
} );

// 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,
},
} )
)
pages.map( ( page ) => deletePage.call( this, page.id ) )
);
}

/**
* Create a new page.
*
* @param this
* @param payload The page payload.
*/
export async function createPage(
this: RequestUtils,
payload: CreatePagePayload
) {
// https://developer.wordpress.org/rest-api/reference/pages/#create-a-page
const page = await this.rest< Page >( {
method: 'POST',
path: `/wp/v2/pages`,
params: payload,
} );

return page;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ export interface Post {

export interface CreatePostPayload {
title?: string;
content: string;
content?: string;
status: 'publish' | 'future' | 'draft' | 'pending' | 'private';
date?: string;
date_gmt: string;
}

/**
Expand Down
254 changes: 0 additions & 254 deletions packages/e2e-tests/specs/editor/various/switch-to-draft.test.js

This file was deleted.

Loading