Skip to content

Commit

Permalink
Rename folders for pageUtils and requestUtils and move isCurrentUrl b…
Browse files Browse the repository at this point in the history
…ack to pageUtils
  • Loading branch information
talldan committed May 5, 2022
1 parent b14538e commit 40365bf
Show file tree
Hide file tree
Showing 21 changed files with 32 additions and 28 deletions.
7 changes: 4 additions & 3 deletions packages/e2e-test-utils-playwright/src/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,25 @@ import type { Browser, Page, BrowserContext } from '@playwright/test';
*/
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';
import type { PageUtils } from '../page-utils';

export class Admin {
browser: Browser;
page: Page;
pageUtils: PageUtils;
context: BrowserContext;

constructor( page: Page ) {
constructor( page: Page, pageUtils: PageUtils ) {
this.page = page;
this.context = page.context();
this.browser = this.context.browser()!;
this.pageUtils = pageUtils;
}

createNewPost = createNewPost;
getPageError = getPageError;
isCurrentURL = isCurrentURL;
visitAdminPage = visitAdminPage;
visitSiteEditor = visitSiteEditor;
}
19 changes: 0 additions & 19 deletions packages/e2e-test-utils-playwright/src/admin/is-current-url.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ export async function visitAdminPage(
);

// Handle upgrade required screen
if ( this.isCurrentURL( 'wp-admin/upgrade.php' ) ) {
if ( this.pageUtils.isCurrentURL( 'wp-admin/upgrade.php' ) ) {
// Click update
await this.page.click( '.button.button-large.button-primary' );
// Click continue
await this.page.click( '.button.button-large' );
}

if ( this.isCurrentURL( 'wp-login.php' ) ) {
if ( this.pageUtils.isCurrentURL( 'wp-login.php' ) ) {
throw new Error( 'Not logged in' );
}

Expand Down
4 changes: 2 additions & 2 deletions packages/e2e-test-utils-playwright/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ selectors.register( 'role', selectorScript, { contentScript: true } );

export { Admin } from './admin';
export { Editor } from './editor';
export { PageUtils } from './page';
export { RequestUtils } from './request';
export { PageUtils } from './page-utils';
export { RequestUtils } from './request-utils';
export { test, expect } from './test';
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { Browser, Page, BrowserContext } from '@playwright/test';
/**
* Internal dependencies
*/
import { isCurrentURL } from './is-current-url';
import {
setClipboardData,
pressKeyWithModifier,
Expand All @@ -24,6 +25,7 @@ class PageUtils {
this.browser = this.context.browser()!;
}

isCurrentURL = isCurrentURL;
pressKeyTimes = pressKeyTimes;
pressKeyWithModifier = pressKeyWithModifier;
setBrowserViewport = setBrowserViewport;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Internal dependencies
*/
import { WP_BASE_URL } from '../config';
import type { PageUtils } from './';

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

return expectedURL.pathname === currentURL.pathname;
}
4 changes: 2 additions & 2 deletions packages/e2e-test-utils-playwright/src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ const test = base.extend<
requestUtils: RequestUtils;
}
>( {
admin: async ( { page }, use ) => {
await use( new Admin( page ) );
admin: async ( { page, pageUtils }, use ) => {
await use( new Admin( page, pageUtils ) );
},
page: async ( { page }, use ) => {
page.on( 'console', observeConsoleLogging );
Expand Down

0 comments on commit 40365bf

Please sign in to comment.