-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Migrate hooks api test to playwright #42584
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 hooks api test to playwright #42584
Conversation
Hi @kevin940726 👋 I hope you are doing great!! All CI checks have passed for this PR except the Could you please help me in reviewing this PR? Thanks!! |
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 working on this.
It looks good so far, but there are a few small improvement that I think can be made.
await page.keyboard.type( 'First paragraph' ); | ||
expect( | ||
page.locator( '.edit-post-sidebar .e2e-reset-block-button' ) | ||
).not.toBeNull(); |
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 think it'd be good to use playwright's toBeVisible()
instead of not.toBeNull()
.
'First paragraph' | ||
); | ||
await page.click( 'role=button[name="Reset Block"i]' ); | ||
expect( await editor.getEditedPostContent() ).toMatchSnapshot(); |
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 snapshot is an empty string, so I think it's ok to change this to
expect( await editor.getEditedPostContent() ).toEqual( '' );
And then remove the snapshot file (test/e2e/specs/editor/plugins/__snapshots__/Using-Hooks-API-Pressing-reset-block-button-resets-the-block-1-chromium.txt
)
const content = page.locator( 'p[data-type="core/paragraph"]' ); | ||
expect( await content.evaluate( ( node ) => node.innerText ) ).toEqual( | ||
'First 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.
Some of the playwright APIs should make this a bit simpler to write:
const content = page.locator( 'p[data-type="core/paragraph"]' ); | |
expect( await content.evaluate( ( node ) => node.innerText ) ).toEqual( | |
'First paragraph' | |
); | |
const paragraphBlock = page.locator( 'role=document[name="Paragraph block"i]' ); | |
await expect( paragraphBlock ).toHaveText( 'First paragraph' ); |
I haven't tested that the above code works btw, but hopefully it sends you down the right path.
await page.click( 'role=button[name="Add default block"i]' ); | ||
await page.keyboard.type( 'First paragraph' ); | ||
expect( | ||
page.locator( '.edit-post-sidebar .e2e-reset-block-button' ) |
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.
Lower down in the code (line 41) the locator 'role=button[name="Reset Block"i]'
is being used, and it'd be great to use that here as well instead of the classnames.
Hi @talldan, I have addressed all the feedbacks and pushed the changes. Also the CI is passed :) Please take a look and let me know if any further changes required. Thanks! |
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.
Looks good, thanks for addressing those changes!
What?
Part of #38851.
Migrate hooks-api.test.js to its Playwright version.
Why?
Part of #38851.
How?
See MIGRATION.md for migration steps.
Testing Instructions
Run
npm run test-e2e:playwright test/e2e/specs/editor/plugins/hooks-api.spec.js