Skip to content

Commit

Permalink
Fix a few things
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed May 4, 2022
1 parent 3f32c20 commit b3a4334
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Internal dependencies
*/
import type { Admin } from './';

/**
* Regular expression matching a displayed PHP error within a markup string.
*
Expand All @@ -15,11 +20,12 @@ const REGEXP_PHP_ERROR = /(<b>)?(Fatal error|Recoverable fatal error|Warning|Par
*
* @see http://php.net/manual/en/function.error-reporting.php
*
* @this {import('./').PageUtils}
* @param {Admin} this
*
* @return {Promise<?string>} Promise resolving to a string or null, depending
* whether a page error is present.
*/
export async function getPageError() {
export async function getPageError( this: Admin ) {
const content = await this.page.content();
const match = content.match( REGEXP_PHP_ERROR );
return match ? match[ 0 ] : null;
Expand Down
4 changes: 4 additions & 0 deletions packages/e2e-test-utils-playwright/src/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import type { Browser, Page, BrowserContext } from '@playwright/test';
* Internal dependencies
*/
import { createNewPost } from './create-new-post';
import { getPageError } from './get-page-error';
import { isCurrentURL } from './is-current-url';
import { visitAdminPage } from './visit-admin-page';
import { visitSiteEditor } from './visit-site-editor';

Expand All @@ -25,6 +27,8 @@ export class Admin {
}

createNewPost = createNewPost;
getPageError = getPageError;
isCurrentURL = isCurrentURL;
visitAdminPage = visitAdminPage;
visitSiteEditor = visitSiteEditor;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
* Internal dependencies
*/
import { WP_BASE_URL } from '../config';
import type { Admin } from './';

/**
* Checks if current URL is a WordPress path.
*
* @this {import('./').PageUtils}
* @param {Admin} this
* @param {string} WPPath String to be serialized as pathname.
* @return {boolean} Boolean represents whether current URL is or not a WordPress path.
*/
export function isCurrentURL( WPPath ) {
export function isCurrentURL( this: Admin, WPPath: string ) {
const currentURL = new URL( this.page.url() );
const expectedURL = new URL( WPPath, WP_BASE_URL );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@
*/
import { join } from 'path';

/**
* Internal dependencies
*/
import type { Admin } from './';

/**
* Visits admin page and handle errors.
*
* @this {import('./').PageUtils}
* @param {Admin} this
* @param {string} adminPath String to be serialized as pathname.
* @param {string} query String to be serialized as query portion of URL.
*/
export async function visitAdminPage( adminPath, query ) {
export async function visitAdminPage(
this: Admin,
adminPath: string,
query: string
) {
await this.page.goto(
join( 'wp-admin', adminPath ) + ( query ? `?${ query }` : '' )
);
Expand Down
10 changes: 2 additions & 8 deletions packages/e2e-test-utils-playwright/src/page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ import type { Browser, Page, BrowserContext } from '@playwright/test';
/**
* Internal dependencies
*/
import { getPageError } from './get-page-error';
import { isCurrentURL } from './is-current-url';
import {
setClipboardData,
pressKeyWithModifier,
} from './press-key-with-modifier';
import { pressKeyTimes } from './press-key-times';
import { selectBlockByClientId } from '../editor/select-block-by-client-id';
import { setBrowserViewport } from './set-browser-viewport';

class PageUtils {
Expand All @@ -27,13 +24,10 @@ class PageUtils {
this.browser = this.context.browser()!;
}

getPageError = getPageError;
isCurrentURL = isCurrentURL;
pressKeyTimes = pressKeyTimes;
pressKeyWithModifier = pressKeyWithModifier;
setClipboardData = setClipboardData;
selectBlockByClientId = selectBlockByClientId;
setBrowserViewport = setBrowserViewport;
pressKeyTimes = pressKeyTimes;
setClipboardData = setClipboardData;
}

export { PageUtils };
6 changes: 3 additions & 3 deletions test/e2e/specs/site-editor/template-part.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {

test.use( {
editor: async ( { page }, use ) => {
await use( new Editor( { page, isIframe: true } ) );
await use( new Editor( { page, hasIframe: true } ) );
},
} );

Expand Down Expand Up @@ -59,7 +59,7 @@ test.describe( 'Template Part', () => {
await expect( paragraph ).toBeVisible();
} );

test.only( 'can detach blocks from a template part', async ( {
test( 'can detach blocks from a template part', async ( {
admin,
editor,
page,
Expand Down Expand Up @@ -97,7 +97,7 @@ test.describe( 'Template Part', () => {
'data-block'
);
await editor.selectBlockByClientId( templatePartClientId );
await canvas.clickBlockOptionsMenuItem(
await editor.clickBlockOptionsMenuItem(
'Detach blocks from template part'
);

Expand Down

0 comments on commit b3a4334

Please sign in to comment.