-
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.
Reorganise e2e utils into admin, editor, pageUtils and requestUtils c…
…lasses Add new editor canvas utility Update tests to use EditorCanvas util WIP Reorganize e2e utils Fix a few things Fix test issues Rename folders for pageUtils and requestUtils and move isCurrentUrl back to pageUtils Fix remaining test issues Update docs Make constructors consistent Update new image block test to use reorganized utils Update migration guide Add step for configuring editor utils Avoid configuring Editor in every test
- Loading branch information
Showing
49 changed files
with
700 additions
and
300 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
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
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,40 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import type { Browser, Page, BrowserContext } from '@playwright/test'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { createNewPost } from './create-new-post'; | ||
import { getPageError } from './get-page-error'; | ||
import { visitAdminPage } from './visit-admin-page'; | ||
import { visitSiteEditor } from './visit-site-editor'; | ||
import type { PageUtils } from '../page-utils'; | ||
|
||
type AdminConstructorProps = { | ||
page: Page; | ||
pageUtils: PageUtils; | ||
}; | ||
|
||
export class Admin { | ||
browser: Browser; | ||
page: Page; | ||
pageUtils: PageUtils; | ||
context: BrowserContext; | ||
|
||
constructor( { page, pageUtils }: AdminConstructorProps ) { | ||
this.page = page; | ||
this.context = page.context(); | ||
this.browser = this.context.browser()!; | ||
this.pageUtils = pageUtils; | ||
} | ||
|
||
createNewPost = createNewPost; | ||
getPageError = getPageError; | ||
visitAdminPage = visitAdminPage; | ||
visitSiteEditor = visitSiteEditor; | ||
} |
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
19 changes: 19 additions & 0 deletions
19
packages/e2e-test-utils-playwright/src/editor/click-block-options-menu-item.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,19 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { Editor } from './index'; | ||
|
||
/** | ||
* Clicks a block toolbar button. | ||
* | ||
* @param {Editor} this | ||
* @param {string} label The text string of the button label. | ||
*/ | ||
export async function clickBlockOptionsMenuItem( this: Editor, label: string ) { | ||
await this.clickBlockToolbarButton( 'Options' ); | ||
await this.page | ||
.locator( | ||
`role=menu[name="Options"i] >> role=menuitem[name="${ label }"i]` | ||
) | ||
.click(); | ||
} |
9 changes: 7 additions & 2 deletions
9
...ht/src/page/click-block-toolbar-button.js → .../src/editor/click-block-toolbar-button.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
11 changes: 9 additions & 2 deletions
11
...right/src/page/get-edited-post-content.js → ...ght/src/editor/get-edited-post-content.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 |
---|---|---|
@@ -1,11 +1,18 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { Editor } from './index'; | ||
|
||
/** | ||
* Returns a promise which resolves with the edited post content (HTML string). | ||
* | ||
* @this {import('./').PageUtils} | ||
* @param {Editor} this | ||
* | ||
* @return {Promise} Promise resolving with post content markup. | ||
*/ | ||
export async function getEditedPostContent() { | ||
export async function getEditedPostContent( this: Editor ) { | ||
return await this.page.evaluate( () => | ||
// @ts-ignore (Reason: wp isn't typed) | ||
window.wp.data.select( 'core/editor' ).getEditedPostContent() | ||
); | ||
} |
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,64 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import type { Browser, Page, BrowserContext, Frame } from '@playwright/test'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { clickBlockOptionsMenuItem } from './click-block-options-menu-item'; | ||
import { clickBlockToolbarButton } from './click-block-toolbar-button'; | ||
import { getEditedPostContent } from './get-edited-post-content'; | ||
import { insertBlock } from './insert-block'; | ||
import { openDocumentSettingsSidebar } from './open-document-settings-sidebar'; | ||
import { openPreviewPage } from './preview'; | ||
import { selectBlockByClientId } from './select-block-by-client-id'; | ||
import { showBlockToolbar } from './show-block-toolbar'; | ||
import { saveSiteEditorEntities } from './site-editor'; | ||
|
||
type EditorConstructorProps = { | ||
page: Page; | ||
hasIframe?: boolean; | ||
}; | ||
|
||
export class Editor { | ||
browser: Browser; | ||
page: Page; | ||
context: BrowserContext; | ||
#hasIframe: boolean; | ||
|
||
constructor( { page, hasIframe = false }: EditorConstructorProps ) { | ||
this.page = page; | ||
this.context = page.context(); | ||
this.browser = this.context.browser()!; | ||
this.#hasIframe = hasIframe; | ||
} | ||
|
||
get canvas(): Frame | Page { | ||
let frame; | ||
|
||
if ( this.#hasIframe ) { | ||
frame = this.page.frame( 'editor-canvas' ); | ||
} else { | ||
frame = this.page; | ||
} | ||
|
||
if ( ! frame ) { | ||
throw new Error( | ||
'EditorUtils: unable to find editor canvas iframe or page' | ||
); | ||
} | ||
|
||
return frame; | ||
} | ||
|
||
clickBlockOptionsMenuItem = clickBlockOptionsMenuItem; | ||
clickBlockToolbarButton = clickBlockToolbarButton; | ||
getEditedPostContent = getEditedPostContent; | ||
insertBlock = insertBlock; | ||
openDocumentSettingsSidebar = openDocumentSettingsSidebar; | ||
openPreviewPage = openPreviewPage; | ||
saveSiteEditorEntities = saveSiteEditorEntities; | ||
selectBlockByClientId = selectBlockByClientId; | ||
showBlockToolbar = showBlockToolbar; | ||
} |
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
Oops, something went wrong.