-
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.
- Loading branch information
1 parent
c2468d4
commit a5e5359
Showing
4 changed files
with
172 additions
and
99 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
packages/e2e-test-utils-playwright/src/page/create-new-post.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,66 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { addQueryArgs } from '@wordpress/url'; | ||
|
||
/** | ||
* Creates new post. | ||
* | ||
* @this {import('.').PageUtils} | ||
* @param {Object} object Object to create new post, along with tips enabling option. | ||
* @param {string} [object.postType] Post type of the new post. | ||
* @param {string} [object.title] Title of the new post. | ||
* @param {string} [object.content] Content of the new post. | ||
* @param {string} [object.excerpt] Excerpt of the new post. | ||
* @param {boolean} [object.showWelcomeGuide] Whether to show the welcome guide. | ||
*/ | ||
export async function createNewPost( { | ||
postType, | ||
title, | ||
content, | ||
excerpt, | ||
showWelcomeGuide = false, | ||
} = {} ) { | ||
const query = addQueryArgs( '', { | ||
post_type: postType, | ||
post_title: title, | ||
content, | ||
excerpt, | ||
} ).slice( 1 ); | ||
|
||
await this.visitAdminPage( 'post-new.php', query ); | ||
|
||
await this.page.waitForSelector( '.edit-post-layout' ); | ||
|
||
const isWelcomeGuideActive = await this.page.evaluate( () => | ||
window.wp.data | ||
.select( 'core/edit-post' ) | ||
.isFeatureActive( 'welcomeGuide' ) | ||
); | ||
const isFullscreenMode = await this.page.evaluate( () => | ||
window.wp.data | ||
.select( 'core/edit-post' ) | ||
.isFeatureActive( 'fullscreenMode' ) | ||
); | ||
|
||
if ( showWelcomeGuide !== isWelcomeGuideActive ) { | ||
await this.page.evaluate( () => | ||
window.wp.data | ||
.dispatch( 'core/edit-post' ) | ||
.toggleFeature( 'welcomeGuide' ) | ||
); | ||
|
||
await this.page.reload(); | ||
await this.page.waitForSelector( '.edit-post-layout' ); | ||
} | ||
|
||
if ( isFullscreenMode ) { | ||
await this.page.evaluate( () => | ||
window.wp.data | ||
.dispatch( 'core/edit-post' ) | ||
.toggleFeature( 'fullscreenMode' ) | ||
); | ||
|
||
await this.page.waitForSelector( 'body:not(.is-fullscreen-mode)' ); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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,104 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); | ||
|
||
test.describe( 'new editor state', () => { | ||
test.beforeAll( async ( { requestUtils } ) => { | ||
await requestUtils.activatePlugin( | ||
'gutenberg-test-plugin-post-formats-support' | ||
); | ||
} ); | ||
|
||
test.afterAll( async ( { requestUtils } ) => { | ||
await requestUtils.deactivatePlugin( | ||
'gutenberg-test-plugin-post-formats-support' | ||
); | ||
} ); | ||
|
||
test( 'should show the New Post page in Gutenberg', async ( { | ||
page, | ||
pageUtils, | ||
} ) => { | ||
await pageUtils.createNewPost(); | ||
|
||
await expect( page ).toHaveURL( /post-new.php/ ); | ||
|
||
// Should display the blank title. | ||
const title = page.locator( 'role=textbox[name="Add title"i]' ); | ||
await expect( title ).toBeEditable(); | ||
await expect( title ).toHaveText( '' ); | ||
|
||
// Should display the Preview button. | ||
await expect( | ||
page.locator( 'role=button[name="Preview"i]' ) | ||
).toBeVisible(); | ||
|
||
// Should display the Post Formats UI. | ||
await expect( | ||
page.locator( 'role=combobox[name="Post Format"i]' ) | ||
).toBeVisible(); | ||
} ); | ||
|
||
test( 'should have no history', async ( { page, pageUtils } ) => { | ||
await pageUtils.createNewPost(); | ||
|
||
await expect( | ||
page.locator( 'role=button[name="Undo"i]' ) | ||
).toBeDisabled(); | ||
await expect( | ||
page.locator( 'role=button[name="Redo"i]' ) | ||
).toBeDisabled(); | ||
} ); | ||
|
||
test( 'should focus the title if the title is empty', async ( { | ||
page, | ||
pageUtils, | ||
} ) => { | ||
await pageUtils.createNewPost(); | ||
|
||
await expect( | ||
page.locator( 'role=textbox[name="Add title"i]' ) | ||
).toBeFocused(); | ||
} ); | ||
|
||
test( 'should not focus the title if the title exists', async ( { | ||
page, | ||
pageUtils, | ||
} ) => { | ||
await pageUtils.createNewPost(); | ||
|
||
// Enter a title for this post. | ||
await page.type( | ||
'role=textbox[name="Add title"i]', | ||
'Here is the title' | ||
); | ||
// Save the post as a draft. | ||
await page.click( 'role=button[name="Save draft"i]' ); | ||
await page.waitForSelector( | ||
'role=button[name="Dismiss this notice"] >> text=Draft saved' | ||
); | ||
|
||
// Reload the browser so a post is loaded with a title. | ||
await page.reload(); | ||
await page.waitForSelector( '.edit-post-layout' ); | ||
|
||
// The document `body` should be the `activeElement`, because nothing is | ||
// focused by default when a post already has a title. | ||
await expect( page.locator( 'body' ) ).toBeFocused(); | ||
} ); | ||
|
||
test( 'should be saveable with sufficient initial edits', async ( { | ||
page, | ||
pageUtils, | ||
} ) => { | ||
await pageUtils.createNewPost( { title: 'Here is the title' } ); | ||
|
||
// Verify saveable by presence of the Save Draft button. | ||
const saveDraftButton = page.locator( | ||
'role=button[name="Save draft"i]' | ||
); | ||
await expect( saveDraftButton ).toBeVisible(); | ||
await expect( saveDraftButton ).toBeEnabled(); | ||
} ); | ||
} ); |