Skip to content

Commit

Permalink
Merge createNewPost into visitPostEditor
Browse files Browse the repository at this point in the history
Combine the two utils leaving only the latter. Update tests accordingly.
  • Loading branch information
WunderBart committed Oct 17, 2023
1 parent 6e5feb7 commit 59720fe
Show file tree
Hide file tree
Showing 101 changed files with 177 additions and 205 deletions.
42 changes: 0 additions & 42 deletions packages/e2e-test-utils-playwright/src/admin/create-new-post.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/e2e-test-utils-playwright/src/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type { Browser, Page, BrowserContext } from '@playwright/test';
/**
* Internal dependencies
*/
import { createNewPost } from './create-new-post';
import { getPageError } from './get-page-error';
import { visitAdminPage } from './visit-admin-page';
import { visitPostEditor } from './visit-post-editor';
Expand Down Expand Up @@ -35,8 +34,6 @@ export class Admin {
this.editor = editor;
}

/** @borrows createNewPost as this.createNewPost */
createNewPost: typeof createNewPost = createNewPost.bind( this );
/** @borrows getPageError as this.getPageError */
getPageError: typeof getPageError = getPageError.bind( this );
/** @borrows visitAdminPage as this.visitAdminPage */
Expand Down
45 changes: 28 additions & 17 deletions packages/e2e-test-utils-playwright/src/admin/visit-post-editor.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,49 @@
/**
* WordPress dependencies
*/
import { addQueryArgs } from '@wordpress/url';

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

interface PostOptions {
interface PostEditorOptions {
postId?: string | number;
postType?: string;
title?: string;
content?: string;
excerpt?: string;
showWelcomeGuide?: boolean;
}

/**
* Creates new post.
* Creates new post or visits existing post if postId is provided.
*
* @param this
* @param options Options to create new post.
* @param options Options to create or visit post.
*/
export async function visitPostEditor(
this: Admin,
options: PostOptions = {}
options: PostEditorOptions = {}
) {
if ( typeof options.postId === 'undefined' ) {
throw new Error( 'postId is required.' );
}
const query = new URLSearchParams();
let adminPage: string;

if ( options.postId ) {
const { postId } = options;

const query = addQueryArgs( '', {
post: options.postId,
action: 'edit',
} ).slice( 1 );
adminPage = 'post.php';

query.set( 'post', String( postId ) );
query.set( 'action', 'edit' );
} else {
const { postType, title, content, excerpt } = options;

adminPage = 'post-new.php';

if ( postType ) query.set( 'post_type', postType );
if ( title ) query.set( 'post_title', title );
if ( content ) query.set( 'content', content );
if ( excerpt ) query.set( 'excerpt', excerpt );
}

await this.visitAdminPage( 'post.php', query );
await this.visitAdminPage( adminPage, query.toString() );

await this.editor.setPreferences( 'core/edit-post', {
welcomeGuide: options.showWelcomeGuide ?? false,
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/blocks/avatar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test.describe( 'Avatar', () => {
password: 'gravatargravatar123magic',
} );

await admin.createNewPost();
await admin.visitPostEditor();
} );

test.afterEach( async ( { requestUtils } ) => {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/blocks/buttons.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'Buttons', () => {
test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
await admin.visitPostEditor();
} );

test( 'has focus on button content', async ( { editor, page } ) => {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/blocks/classic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test.use( {

test.describe( 'Classic', () => {
test.beforeEach( async ( { admin, editor } ) => {
await admin.createNewPost();
await admin.visitPostEditor();
// To do: run with iframe.
await editor.switchToLegacyCanvas();
} );
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/blocks/code.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'Code', () => {
test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
await admin.visitPostEditor();
} );

test( 'can be created by three backticks and enter', async ( {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/blocks/columns.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'Columns', () => {
test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
await admin.visitPostEditor();
} );

test.afterEach( async ( { requestUtils } ) => {
Expand Down
12 changes: 6 additions & 6 deletions test/e2e/specs/editor/blocks/comments.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test.describe( 'Comments', () => {
requestUtils,
} ) => {
await requestUtils.deleteAllComments();
await admin.createNewPost();
await admin.visitPostEditor();
await editor.insertBlock( { name: 'core/comments' } );
await expect(
editor.canvas.locator(
Expand All @@ -63,7 +63,7 @@ test.describe( 'Comments', () => {
page,
requestUtils,
} ) => {
await admin.createNewPost();
await admin.visitPostEditor();
await editor.insertBlock( { name: 'core/comments' } );
const postId = await editor.publishPost();

Expand Down Expand Up @@ -117,7 +117,7 @@ test.describe( 'Comments', () => {
commentsBlockUtils,
} ) => {
await commentsBlockUtils.setOption( 'page_comments', '0' );
await admin.createNewPost();
await admin.visitPostEditor();
await editor.insertBlock( { name: 'core/comments' } );
const postId = await editor.publishPost();

Expand Down Expand Up @@ -147,7 +147,7 @@ test.describe( 'Comments', () => {
admin,
editor,
} ) => {
await admin.createNewPost();
await admin.visitPostEditor();
await editor.insertBlock( {
name: 'core/comments',
attributes: { legacy: true, textColor: 'vivid-purple' },
Expand Down Expand Up @@ -184,7 +184,7 @@ test.describe( 'Comments', () => {
editor,
requestUtils,
} ) => {
await admin.createNewPost();
await admin.visitPostEditor();
await editor.insertBlock( { name: 'core/comments' } );
const postId = await editor.publishPost();

Expand Down Expand Up @@ -212,7 +212,7 @@ test.describe( 'Comments', () => {
editor,
requestUtils,
} ) => {
await admin.createNewPost();
await admin.visitPostEditor();
await editor.insertBlock( {
name: 'core/comments',
attributes: { legacy: true },
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/blocks/cover.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test.use( {

test.describe( 'Cover', () => {
test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
await admin.visitPostEditor();
} );

test( 'can set overlay color using color picker on block placeholder', async ( {
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/specs/editor/blocks/gallery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test.describe( 'Gallery', () => {
page,
pageUtils,
} ) => {
await admin.createNewPost();
await admin.visitPostEditor();

pageUtils.setClipboardData( {
plainText: `[gallery ids="${ uploadedMedia.id }"]`,
Expand Down Expand Up @@ -91,7 +91,7 @@ test.describe( 'Gallery', () => {
editor,
galleryBlockUtils,
} ) => {
await admin.createNewPost();
await admin.visitPostEditor();
await editor.insertBlock( { name: 'core/gallery' } );
const galleryBlock = editor.canvas.locator(
'role=document[name="Block: Gallery"i]'
Expand Down Expand Up @@ -119,7 +119,7 @@ test.describe( 'Gallery', () => {
} ) => {
const galleryCaption = 'Tested gallery caption';

await admin.createNewPost();
await admin.visitPostEditor();
await editor.insertBlock( {
name: 'core/gallery',
innerBlocks: [
Expand Down Expand Up @@ -162,7 +162,7 @@ test.describe( 'Gallery', () => {
} ) => {
const caption = 'Tested caption';

await admin.createNewPost();
await admin.visitPostEditor();
await editor.insertBlock( {
name: 'core/gallery',
innerBlocks: [
Expand Down Expand Up @@ -204,7 +204,7 @@ test.describe( 'Gallery', () => {
editor,
page,
} ) => {
await admin.createNewPost();
await admin.visitPostEditor();
await editor.insertBlock( { name: 'core/gallery' } );
await editor.canvas
.locator( 'role=button[name="Media Library"i]' )
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/blocks/group.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'Group', () => {
test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
await admin.visitPostEditor();
} );

test( 'can be created using the block inserter', async ( {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/blocks/heading.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'Heading', () => {
test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
await admin.visitPostEditor();
} );

test( 'can be created by prefixing number sign and a space', async ( {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/blocks/html.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'HTML block', () => {
test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
await admin.visitPostEditor();
} );

test( 'can be created by typing "/html"', async ( { editor, page } ) => {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/specs/editor/blocks/image.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test.describe( 'Image', () => {
} );

test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
await admin.visitPostEditor();
} );

test.afterEach( async ( { requestUtils } ) => {
Expand Down Expand Up @@ -738,7 +738,7 @@ test.describe.skip( 'Image - interactivity', () => {
} );

test.beforeEach( async ( { admin, editor } ) => {
await admin.createNewPost();
await admin.visitPostEditor();
await editor.insertBlock( { name: 'core/image' } );
} );

Expand Down
6 changes: 3 additions & 3 deletions test/e2e/specs/editor/blocks/links.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'Links', () => {
test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
await admin.visitPostEditor();
} );

test.afterEach( async ( { requestUtils } ) => {
Expand All @@ -30,7 +30,7 @@ test.describe( 'Links', () => {
status: 'publish',
} );

await admin.createNewPost();
await admin.visitPostEditor();

// Now in a new post and try to create a link from an autocomplete suggestion using the keyboard.
await editor.insertBlock( {
Expand Down Expand Up @@ -373,7 +373,7 @@ test.describe( 'Links', () => {
status: 'publish',
} );

await admin.createNewPost();
await admin.visitPostEditor();

// Now in a new post and try to create a link from an autocomplete suggestion using the keyboard.
await editor.insertBlock( {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/blocks/list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'List (@firefox)', () => {
test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
await admin.visitPostEditor();
} );

test( 'can be created by using an asterisk at the start of a paragraph block', async ( {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/blocks/missing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'missing block', () => {
test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
await admin.visitPostEditor();
} );

test( 'should strip potentially malicious on* attributes', async ( {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/blocks/navigation-colors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test.describe( 'Navigation colors', () => {
attributes: { openSubmenusOnClick: true },
} );

await admin.createNewPost();
await admin.visitPostEditor();

await editor.insertBlock( {
name: 'core/navigation',
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/blocks/navigation-list-view.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test.describe( 'Navigation block - List view editing', () => {
} );

test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
await admin.visitPostEditor();
} );

test.afterAll( async ( { requestUtils } ) => {
Expand Down
Loading

0 comments on commit 59720fe

Please sign in to comment.