-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e3d551
commit 6f78851
Showing
3 changed files
with
62 additions
and
56 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
53 changes: 53 additions & 0 deletions
53
packages/e2e-test-utils-playwright/src/request-utils/menus.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,53 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { RequestUtils } from './index'; | ||
|
||
export interface MenuData { | ||
title: string; | ||
content: string; | ||
} | ||
export interface Navigation { | ||
id: number; | ||
content: string; | ||
status: 'publish' | 'future' | 'draft' | 'pending' | 'private'; | ||
} | ||
|
||
/** | ||
* Create a navigation menu | ||
* | ||
* @param {Object} menuData navigation menu post data. | ||
* @return {string} Menu content. | ||
*/ | ||
export async function createNavigationMenu( | ||
this: RequestUtils, | ||
menuData: MenuData | ||
) { | ||
return this.rest( { | ||
method: 'POST', | ||
path: `/wp/v2/navigation/`, | ||
data: { | ||
status: 'publish', | ||
...menuData, | ||
}, | ||
} ); | ||
} | ||
|
||
/** | ||
* Delete all navigation menus | ||
* | ||
*/ | ||
export async function deleteAllNavigationMenus( this: RequestUtils ) { | ||
const menus = await this.rest< Navigation[] >( { | ||
path: `/wp/v2/navigation/`, | ||
} ); | ||
|
||
if ( ! menus?.length ) return; | ||
|
||
await this.batchRest( | ||
menus.map( ( menu ) => ( { | ||
method: 'DELETE', | ||
path: `/wp/v2/navigation/${ menu.id }?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