Repository navigation
Migrate 'block editor keyboard shortcuts' e2e tests to Playwright - #57422
Conversation
Co-authored-by: Alvi Tazwar <55917380+alvitazwar@users.noreply.github.com>
| // Duplicate via keyboard. | ||
| await pageUtils.pressKeys( 'primaryShift+d' ); | ||
|
|
||
| await expect.poll( editor.getBlocks ).toMatchObject( [ |
There was a problem hiding this comment.
I'm not sure if it's an issue with the editor.getBlocks method or a bug in the editor, but after duplication, the newly inserted blocks content attribute is undefined.
I've omitted attributes in this test since it's only testing the event propagation via portals. I think it's worth to look into this separately.
P.S. The assertion works correctly if I insert another block.
Example test case
test( 'duplication test', async ( { editor, page, pageUtils } ) => {
await editor.canvas
.getByRole( 'button', { name: 'Add default block' } )
.click();
await page.keyboard.type( '1st' );
// Duplicate via keyboard.
await pageUtils.pressKeys( 'primaryShift+d' );
// Insert another block manually.
await page.keyboard.press( 'ArrowDown' );
await page.keyboard.press( 'Enter' );
await expect.poll( editor.getBlocks ).toMatchObject( [
{
name: 'core/paragraph',
attributes: { content: '1st' },
},
{
name: 'core/paragraph',
attributes: { content: '1st' },
},
{
name: 'core/paragraph',
attributes: { content: '' },
},
] );
} );There was a problem hiding this comment.
I can't reproduce this. The content attribute is correctly showing for me 🤔 .
There was a problem hiding this comment.
Try removing the // Insert another block manually. part of the example test.
There was a problem hiding this comment.
I can reproduce this after re-pulling the latest trunk.
It seems like a side-effect of #43204. After duplication, they shared the same RichTextData content and triggered the loop-detection optimization of toMatchObject, and bailed out comparing it. I don't know why inserting a new block fixes it though.
There was a problem hiding this comment.
I guess we can add a check in editor.getBlocks() to automatically convert RichTextData to plain string for testing purposes.
|
Size Change: 0 B Total Size: 1.69 MB ℹ️ View Unchanged
|
| */ | ||
| const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); | ||
|
|
||
| async function addTestParagraphBlocks( { editor, page } ) { |
There was a problem hiding this comment.
Nit: What do you think if we just use editor.setContent or createNewPost with the content option? If it's easier to manage focus this way then nvm.
There was a problem hiding this comment.
I forgot about the editor.setContent 😅 I think it should work; IIRC, the resetBlocks should focus on the last block, where these tests expect it.
There was a problem hiding this comment.
I was mistaken. The resetBlocks doesn't handle the focus; the replaceBlocks does. I guess we can update the setContent to focus on the last inserted block, but that's probably out of the scope of this PR.
| } ); | ||
| } | ||
|
|
||
| test.describe( 'Block editor keyboard shortcuts', () => { |
There was a problem hiding this comment.
Nit: I think a lot of these tests can be grouped into one to speed up the process. Especially we use mostly the same setup for each test, and each test only does one assertion. It's not a requirement for this migration though!
There was a problem hiding this comment.
We might need to adjust test shortcuts handling through portals in the same tree tests, but it should be doable.
What's the preferred method for having multiple checks in a single file, test.step or custom failure messages?
There was a problem hiding this comment.
What's the preferred method for having multiple checks in a single file,
test.stepor custom failure messages?
Either! Whichever looks the best to you 😉.
There was a problem hiding this comment.
Let's skip this for now. The whole suite runs in less than 10s.
I thought I could use editor.setContent to reset to the content state, but #57422 (comment) will complicate tests.
| // Duplicate via keyboard. | ||
| await pageUtils.pressKeys( 'primaryShift+d' ); | ||
|
|
||
| await expect.poll( editor.getBlocks ).toMatchObject( [ |
There was a problem hiding this comment.
I can't reproduce this. The content attribute is correctly showing for me 🤔 .
What?
Part of #38851.
Supersedes and closes #50930.
PR migrates
block-editor-keyboard-shortcuts.test.jse2e tests to Playwright.Why?
See #38851.
How?
I've included the author of the previous PR so they get credit for their contribution.
Testing Instructions