-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 undo to Playwright #48701
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! ❤️ |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I’ll try 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.
@kevin940726 Do you think we need editableIndex
?
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 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.
}, | ||
] ); | ||
await expect.poll( undoUtils.getSelection ).toEqual( { | ||
blockIndex: 0, |
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.
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
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 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' ); |
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.
Cool trick!
|
||
await expect.poll( editor.getEditedPostContent ).toBe( '' ); | ||
await expect.poll( undoUtils.getSelection ).toEqual( { | ||
blockIndex: 0, |
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.
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? |
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.
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.
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.
Thank you, @torounit!
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