-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate code block test case to playwright #40844
Closed
Closed
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d4b5b03
Migrate code block test case to playwright
070f7a5
addressed review feedbacks
57b592e
resolve action filing issue
08f1ad4
addressed feedbacks
aaa02e5
Fix stylint issue
ab32326
Fix styleint issue
abd8c96
Merge branch 'trunk' into add/playwright-code-test
5616a3a
Resilved merge conflicts and solve styleint issue
e970138
Remove unused var
kevin940726 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
packages/e2e-test-utils-playwright/src/page/click-block-appender.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,17 @@ | ||
/** | ||
* Clicks the default block appender. | ||
* | ||
* @this {import('./').PageUtils} | ||
*/ | ||
|
||
export async function clickBlockAppender() { | ||
// The block appender is only visible when there's no selection. | ||
await this.page.evaluate( () => | ||
window.wp.data.dispatch( 'core/block-editor' ).clearSelectedBlock() | ||
); | ||
const appender = await this.page.waitForSelector( | ||
'.block-editor-default-block-appender__content' | ||
); | ||
await appender.click(); | ||
await this.page.evaluate( () => new Promise( window.requestIdleCallback ) ); | ||
} |
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,58 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
|
||
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); | ||
|
||
|
||
test.describe( 'Code', () => { | ||
test.beforeEach( async ({pageUtils}) => { | ||
await pageUtils.createNewPost(); | ||
} ); | ||
|
||
test( 'can be created by three backticks and enter', async ({page,pageUtils}) => { | ||
await pageUtils.clickBlockAppender(); | ||
await page.keyboard.type( '```' ); | ||
await page.keyboard.press( 'Enter' ); | ||
await page.keyboard.type( '<?php' ); | ||
|
||
// Check the content | ||
const content = await pageUtils.getEditedPostContent(); | ||
expect( content ).toBe( | ||
`<!-- wp:code --> | ||
<pre class="wp-block-code"><code><?php</code></pre> | ||
<!-- /wp:code -->` | ||
); | ||
|
||
} ); | ||
|
||
test( 'should delete block when backspace in an empty code', async ({page,pageUtils}) => { | ||
await pageUtils.insertBlock({ name: 'core/code' }); | ||
|
||
await page.keyboard.type( 'a' ); | ||
|
||
await page.keyboard.press( 'Backspace' ); | ||
await page.keyboard.press( 'Backspace' ); | ||
|
||
// Expect code block to be deleted. | ||
expect( await pageUtils.getEditedPostContent() ).toBe( '' ); | ||
} ); | ||
|
||
test( 'should paste plain text', async ({page,pageUtils}) => { | ||
await pageUtils.insertBlock( { name: 'core/code' }); | ||
|
||
// Test to see if HTML and white space is kept. | ||
await pageUtils.setClipboardData( { plainText: '<img />\n\t<br>' } ); | ||
|
||
await pageUtils.pressKeyWithModifier( 'primary', 'v' ); | ||
|
||
// Check the content | ||
const content = await pageUtils.getEditedPostContent(); | ||
expect( content ).toBe( | ||
`<!-- wp:code --> | ||
<pre class="wp-block-code"><code><img /> | ||
<br></code></pre> | ||
<!-- /wp:code -->` | ||
); | ||
} ); | ||
} ); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually want to limit the usage of e2e utils if we can inline them directly. If we're just creating a page, I believe we can just click on the appender button directly:
The same code has also been used in
copy-cut-paste
tests. This way we don't have to create theclickBlockAppender
util (unless we really need it in other situations).