Repository navigation
Migrate undo to Playwright - #48701
Conversation
|
Size Change: +112 B (0%) Total Size: 1.37 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in d1219a6. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4805307444
|
11a67ed to
4a48a98
Compare
|
Thanks for the PR! I'll try to find some time to review it. Thanks for your patience! ❤️ |
kevin940726
left a comment
There was a problem hiding this comment.
Thanks for the PR! Very well done! Left some nitpicks but overall I think this is really close! 💯
| const after = await editor.getEditedPostContent(); | ||
|
|
||
| expect( after ).toBe( | ||
| `<!-- wp:paragraph --> | ||
| <p>before pause after pause</p> | ||
| <!-- /wp:paragraph -->` | ||
| ); |
There was a problem hiding this comment.
Nit: editor.getBlocks could be more readable, see https://github.com/WordPress/gutenberg/blob/trunk/docs/contributors/code/e2e/overusing-snapshots.md.
| const after = await editor.getEditedPostContent(); | |
| expect( after ).toBe( | |
| `<!-- wp:paragraph --> | |
| <p>before pause after pause</p> | |
| <!-- /wp:paragraph -->` | |
| ); | |
| await expect.poll( editor.getBlocks ).toMatchObject( [ { | |
| name: 'core/paragraph', | |
| attributes: { content: 'before pause after pause' }, | |
| } ] ); |
Same for other assertions below.
| blockIndex, | ||
| editableIndex, |
There was a problem hiding this comment.
Nit: TBH, I have no idea what these mean 😅 . Could we instead use public APIs like wp.data.select( 'core/block-editor' ).getBlockIndex() to compute some of these fields?
However, I think we can keep these if we can't figure out a better way to test the same thing in this PR. If it's possible, I'd like to refactor it to better match the best practices, as shown in the PR #48035. I don't think that's a focus for this migration PR though!
There was a problem hiding this comment.
@kevin940726 Do you think we need editableIndex ?
There was a problem hiding this comment.
I don't know what it does or trying to achieve, TBH. Seems like every assertion is checking if it's equal to 0. I'm open to delete it if you also think it doesn't help with the test.
There was a problem hiding this comment.
The value of blockIndex has been reduced by one because the order has been changed to return the order without the title of the post.
01e510b to
15985ec
Compare
kevin940726
left a comment
There was a problem hiding this comment.
This LGTM 👍 ! I'll tag @Mamaduka for another pair of eyes in case I missed something. Either way I think we can still merge it and iterate if necessary!
| await pageUtils.pressKeys( 'primary+a' ); | ||
| await pageUtils.pressKeys( 'primary+b' ); | ||
| await pageUtils.pressKeys( 'primary+z' ); | ||
| const activeElementLocator = page.locator( ':focus' ); |
|
|
||
| await expect.poll( editor.getEditedPostContent ).toBe( '' ); | ||
| await expect.poll( undoUtils.getSelection ).toEqual( { | ||
| blockIndex: 0, |
There was a problem hiding this comment.
If undo is used to empty the block, getSelectionStart().offset will be undefined.
|
@kevin940726 Thank you for reviewing! I refactored getSelection now, can you check? |
kevin940726
left a comment
There was a problem hiding this comment.
LGTM 👍
Nit: Could you move the utils to bottom of the file as shown in other tests? It's just a preference of mine to move the less relevant part to the end so that readers can jump straight into the tests.
What?
Part of #38851
Why?
See this post for an overview of the migration.
How?
By following the migration guide.
Testing Instructions
npm run test:e2e:playwright -- test/e2e/specs/editor/various/undo.spec.js