-
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
post-editor-template-mode
to Playwright (#40175)
* Migrate post-editor-template-mode to Playwright * Use core/preferences store
- Loading branch information
1 parent
4165501
commit 7183f04
Showing
11 changed files
with
564 additions
and
406 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
23 changes: 23 additions & 0 deletions
23
packages/e2e-test-utils-playwright/src/page/open-document-settings-sidebar.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,23 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
const { expect } = require( '../test' ); | ||
|
||
/** | ||
* Clicks on the button in the header which opens Document Settings sidebar when it is closed. | ||
* | ||
* @this {import('./').PageUtils} | ||
*/ | ||
export async function openDocumentSettingsSidebar() { | ||
const editorSettings = this.page.locator( | ||
'role=region[name="Editor settings"i]' | ||
); | ||
|
||
if ( ! ( await editorSettings.isVisible() ) ) { | ||
await this.page.click( | ||
'role=region[name="Editor top bar"i] >> role=button[name="Settings"i]' | ||
); | ||
|
||
await expect( editorSettings ).toBeVisible(); | ||
} | ||
} |
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,24 @@ | ||
/** @typedef {import('@playwright/test').Page} Page */ | ||
|
||
/** | ||
* Opens the preview page of an edited post. | ||
* | ||
* @this {import('./').PageUtils} | ||
* @return {Page} preview page. | ||
*/ | ||
export async function openPreviewPage() { | ||
const editorTopBar = this.page.locator( | ||
'role=region[name="Editor top bar"i]' | ||
); | ||
const previewButton = editorTopBar.locator( | ||
'role=button[name="Preview"i]' | ||
); | ||
await previewButton.click(); | ||
|
||
const [ previewPage ] = await Promise.all( [ | ||
this.context.waitForEvent( 'page' ), | ||
this.page.click( 'role=menuitem[name="Preview in new tab"i]' ), | ||
] ); | ||
|
||
return previewPage; | ||
} |
48 changes: 48 additions & 0 deletions
48
packages/e2e-test-utils-playwright/src/page/set-browser-viewport.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,48 @@ | ||
/** | ||
* Named viewport options. | ||
* | ||
* @typedef {"large"|"medium"|"small"} WPDimensionsName | ||
*/ | ||
|
||
/** | ||
* Viewport dimensions object. | ||
* | ||
* @typedef {Object} WPViewportDimensions | ||
* | ||
* @property {number} width Width, in pixels. | ||
* @property {number} height Height, in pixels. | ||
*/ | ||
|
||
/** | ||
* Predefined viewport dimensions to reference by name. | ||
* | ||
* @enum {WPViewportDimensions} | ||
* | ||
* @type {Record<WPDimensionsName, WPViewportDimensions>} | ||
*/ | ||
const PREDEFINED_DIMENSIONS = { | ||
large: { width: 960, height: 700 }, | ||
medium: { width: 768, height: 700 }, | ||
small: { width: 600, height: 700 }, | ||
}; | ||
|
||
/** | ||
* Valid argument argument type from which to derive viewport dimensions. | ||
* | ||
* @typedef {WPDimensionsName|WPViewportDimensions} WPViewport | ||
*/ | ||
|
||
/** | ||
* Sets browser viewport to specified type. | ||
* | ||
* @this {import('./').PageUtils} | ||
* @param {WPViewport} viewport Viewport name or dimensions object to assign. | ||
*/ | ||
export async function setBrowserViewport( viewport ) { | ||
const dimensions = | ||
typeof viewport === 'string' | ||
? PREDEFINED_DIMENSIONS[ viewport ] | ||
: viewport; | ||
|
||
await this.page.setViewportSize( dimensions ); | ||
} |
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
66 changes: 66 additions & 0 deletions
66
packages/e2e-test-utils-playwright/src/request/templates.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,66 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { RequestUtils } from './index'; | ||
|
||
type TemplateType = 'wp_template' | 'wp_template_part'; | ||
|
||
interface Template { | ||
wp_id: number; | ||
id: string; | ||
} | ||
|
||
const PATH_MAPPING = { | ||
wp_template: '/wp/v2/templates', | ||
wp_template_part: '/wp/v2/template-parts', | ||
}; | ||
|
||
/** | ||
* Delete all the templates of given type. | ||
* | ||
* @param this | ||
* @param type - Template type to delete. | ||
*/ | ||
async function deleteAllTemplates( this: RequestUtils, type: TemplateType ) { | ||
const path = PATH_MAPPING[ type ]; | ||
|
||
if ( ! path ) { | ||
throw new Error( `Unsupported template type: ${ type }.` ); | ||
} | ||
|
||
const templates = await this.rest< Template[] >( { path } ); | ||
|
||
for ( const template of templates ) { | ||
if ( ! template?.id || ! template?.wp_id ) { | ||
continue; | ||
} | ||
|
||
let response; | ||
|
||
try { | ||
response = await this.rest( { | ||
method: 'DELETE', | ||
path: `${ path }/${ template.id }`, | ||
params: { force: true }, | ||
} ); | ||
} catch ( responseError ) { | ||
// Disable reason - the error provides valuable feedback about issues with tests. | ||
// eslint-disable-next-line no-console | ||
console.warn( | ||
`deleteAllTemplates failed to delete template (id: ${ template.wp_id }) with the following error`, | ||
responseError | ||
); | ||
} | ||
|
||
if ( ! response.deleted ) { | ||
// Disable reason - the error provides valuable feedback about issues with tests. | ||
// eslint-disable-next-line no-console | ||
console.warn( | ||
`deleteAllTemplates failed to delete template (id: ${ template.wp_id }) with the following response`, | ||
response | ||
); | ||
} | ||
} | ||
} | ||
|
||
export { deleteAllTemplates }; |
27 changes: 0 additions & 27 deletions
27
packages/e2e-tests/specs/editor/various/__snapshots__/post-editor-template-mode.test.js.snap
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.