-
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 'meta-attribute-block' e2e tests to Playwright #55830
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
9 changes: 0 additions & 9 deletions
9
packages/e2e-tests/specs/editor/plugins/__snapshots__/meta-attribute-block.test.js.snap
This file was deleted.
Oops, something went wrong.
100 changes: 0 additions & 100 deletions
100
packages/e2e-tests/specs/editor/plugins/meta-attribute-block.test.js
This file was deleted.
Oops, something went wrong.
104 changes: 104 additions & 0 deletions
104
test/e2e/specs/editor/plugins/meta-attribute-block.spec.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,104 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); | ||
|
||
const VARIATIONS = [ | ||
[ 'Early Registration', 'test/test-meta-attribute-block-early' ], | ||
[ 'Late Registration', 'test/test-meta-attribute-block-late' ], | ||
]; | ||
|
||
test.describe( 'Block with a meta attribute', () => { | ||
test.beforeAll( async ( { requestUtils } ) => { | ||
await requestUtils.activatePlugin( | ||
'gutenberg-test-meta-attribute-block' | ||
); | ||
} ); | ||
|
||
test.afterAll( async ( { requestUtils } ) => { | ||
await requestUtils.deactivatePlugin( | ||
'gutenberg-test-meta-attribute-block' | ||
); | ||
} ); | ||
|
||
for ( const [ title, blockName ] of VARIATIONS ) { | ||
test.describe( title, () => { | ||
test( 'Should persist the meta attribute properly', async ( { | ||
admin, | ||
editor, | ||
page, | ||
pageUtils, | ||
} ) => { | ||
await admin.createNewPost(); | ||
await editor.insertBlock( { name: blockName } ); | ||
await page.keyboard.type( 'Value' ); | ||
|
||
// Regression Test: Previously the caret would wrongly reset to the end | ||
// of any input for meta-sourced attributes, due to syncing behavior of | ||
// meta attribute updates. | ||
// | ||
// See: https://github.com/WordPress/gutenberg/issues/15739 | ||
await pageUtils.pressKeys( 'ArrowLeft', { times: 5 } ); | ||
await page.keyboard.type( 'Meta ' ); | ||
|
||
await editor.saveDraft(); | ||
await page.reload(); | ||
|
||
const block = page.getByRole( 'document', { | ||
name: `Block: Test Meta Attribute Block (${ title })`, | ||
} ); | ||
await expect( block ).toBeVisible(); | ||
await expect( block.locator( '.my-meta-input' ) ).toHaveValue( | ||
'Meta Value' | ||
); | ||
} ); | ||
|
||
test( 'Should use the same value in all the blocks', async ( { | ||
admin, | ||
editor, | ||
page, | ||
} ) => { | ||
await admin.createNewPost(); | ||
await editor.insertBlock( { name: blockName } ); | ||
await editor.insertBlock( { name: blockName } ); | ||
await editor.insertBlock( { name: blockName } ); | ||
await page.keyboard.type( 'Meta Value' ); | ||
|
||
const inputs = await page.locator( '.my-meta-input' ).all(); | ||
for ( const input of inputs ) { | ||
await expect( input ).toHaveValue( 'Meta Value' ); | ||
} | ||
} ); | ||
|
||
test( 'Should persist the meta attribute properly in a different post type', async ( { | ||
admin, | ||
editor, | ||
page, | ||
pageUtils, | ||
} ) => { | ||
await admin.createNewPost( { postType: 'page' } ); | ||
await editor.insertBlock( { name: blockName } ); | ||
await page.keyboard.type( 'Value' ); | ||
|
||
// Regression Test: Previously the caret would wrongly reset to the end | ||
// of any input for meta-sourced attributes, due to syncing behavior of | ||
// meta attribute updates. | ||
// | ||
// See: https://github.com/WordPress/gutenberg/issues/15739 | ||
await pageUtils.pressKeys( 'ArrowLeft', { times: 5 } ); | ||
await page.keyboard.type( 'Meta ' ); | ||
|
||
await editor.saveDraft(); | ||
await page.reload(); | ||
|
||
const block = page.getByRole( 'document', { | ||
name: `Block: Test Meta Attribute Block (${ title })`, | ||
} ); | ||
await expect( block ).toBeVisible(); | ||
await expect( block.locator( '.my-meta-input' ) ).toHaveValue( | ||
'Meta Value' | ||
); | ||
} ); | ||
} ); | ||
} | ||
} ); |
Oops, something went wrong.
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.
I'm wondering if typing immediately after inserting a block can potentially be flaky since we don't have a promise ensuring the block is there and focused (AFAIR there were issues with that before!). What if we returned the inserted block locator from the
createBlock
so that we can do a simpleawait expect( block ).toBeFocused()
? I've drafted an implementation in #55851.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.
Would look more less like this:
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.
This should be okay. The editor will automatically focus first focusable element in newly inserted block.
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.
Is the block insertion synchronous, though? I can see that, e.g.,
window.wp.data.dispatch( 'core/block-editor' ).insertBlock( x )
returns a promise but we're not really awaiting it 🤔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.
Right, maybe we should await that. @kevin940726, WDYY?
I'll keep an eye on the flaky reports for this test, just in case.