-
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 customizing-widgets to Playwright (#39540)
* Migrate customizing-widgets to Playwright * Fix sidebar reduce motion in customizer * Delete sanity test
- Loading branch information
1 parent
f3b4f44
commit 9f5b842
Showing
9 changed files
with
774 additions
and
934 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
16 changes: 16 additions & 0 deletions
16
packages/e2e-test-utils-playwright/src/page/click-block-toolbar-button.js
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,16 @@ | ||
/** | ||
* Clicks a block toolbar button. | ||
* | ||
* @this {import('./').PageUtils} | ||
* @param {string} label The text string of the button label. | ||
*/ | ||
export async function clickBlockToolbarButton( label ) { | ||
await this.showBlockToolbar(); | ||
|
||
const blockToolbar = this.page.locator( | ||
'role=toolbar[name="Block tools"i]' | ||
); | ||
const button = blockToolbar.locator( `role=button[name="${ label }"]` ); | ||
|
||
await button.click(); | ||
} |
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
15 changes: 15 additions & 0 deletions
15
packages/e2e-test-utils-playwright/src/page/show-block-toolbar.js
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,15 @@ | ||
/** | ||
* The block toolbar is not always visible while typing. | ||
* Call this function to reveal it. | ||
* | ||
* @this {import('./').PageUtils} | ||
*/ | ||
export async function showBlockToolbar() { | ||
// Move the mouse to disable the isTyping mode. We need at least three | ||
// mousemove events for it to work across windows (iframe). With three | ||
// moves, it's a guarantee that at least two will be in the same window. | ||
// Two events are required for the flag to be unset. | ||
await this.page.mouse.move( 50, 50 ); | ||
await this.page.mouse.move( 75, 75 ); | ||
await this.page.mouse.move( 100, 100 ); | ||
} |
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 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,65 @@ | ||
/** | ||
* Delete all the widgets in the widgets screen. | ||
* | ||
* @this {import('./index').RequestUtils} | ||
*/ | ||
export async function deleteAllWidgets() { | ||
const [ widgets, sidebars ] = await Promise.all( [ | ||
this.rest( { path: '/wp/v2/widgets' } ), | ||
this.rest( { path: '/wp/v2/sidebars' } ), | ||
] ); | ||
|
||
await this.batchRest( | ||
widgets.map( ( widget ) => ( { | ||
method: 'DELETE', | ||
path: `/wp/v2/widgets/${ widget.id }?force=true`, | ||
} ) ) | ||
); | ||
|
||
await this.batchRest( | ||
sidebars.map( ( sidebar ) => ( { | ||
method: 'POST', | ||
path: `/wp/v2/sidebars/${ sidebar.id }`, | ||
body: { id: sidebar.id, widgets: [] }, | ||
} ) ) | ||
); | ||
} | ||
|
||
/** | ||
* Add a widget block to the widget area. | ||
* | ||
* @this {import('./index').RequestUtils} | ||
* @param {string} serializedBlock The serialized content of the inserted block HTML. | ||
* @param {string} widgetAreaId The ID of the widget area. | ||
*/ | ||
export async function addWidgetBlock( serializedBlock, widgetAreaId ) { | ||
const { id: blockId } = await this.rest( { | ||
method: 'POST', | ||
path: '/wp/v2/widgets', | ||
data: { | ||
id_base: 'block', | ||
sidebar: widgetAreaId, | ||
instance: { | ||
raw: { content: serializedBlock }, | ||
}, | ||
}, | ||
} ); | ||
|
||
const { widgets } = await this.rest( { | ||
path: `/wp/v2/sidebars/${ widgetAreaId }`, | ||
} ); | ||
|
||
const updatedWidgets = new Set( widgets ); | ||
// Remove duplicate. | ||
updatedWidgets.delete( blockId ); | ||
// Add to last block. | ||
updatedWidgets.add( blockId ); | ||
|
||
await this.rest( { | ||
method: 'PUT', | ||
path: `/wp/v2/sidebars/${ widgetAreaId }`, | ||
data: { | ||
widgets: [ ...updatedWidgets ], | ||
}, | ||
} ); | ||
} |
Oops, something went wrong.