Skip to content

Conversation

pooja-muchandikar
Copy link
Contributor

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

@pooja-muchandikar
Copy link
Contributor Author

Hi @kevin940726 👋

I hope you are doing great!!

All CI checks have passed for this PR except the React Native E2E Tests (iOS) / test CI check. It is failed but seems like its not related to the test case I worked on..

image

Could you please help me in reviewing this PR?

Thanks!!

Copy link
Contributor

@talldan talldan left a 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();
Copy link
Contributor

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();
Copy link
Contributor

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)

Comment on lines 37 to 40
const content = page.locator( 'p[data-type="core/paragraph"]' );
expect( await content.evaluate( ( node ) => node.innerText ) ).toEqual(
'First paragraph'
);
Copy link
Contributor

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:

Suggested change
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' )
Copy link
Contributor

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.

@pooja-muchandikar
Copy link
Contributor Author

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!

Copy link
Contributor

@talldan talldan left a 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!

@talldan talldan merged commit 2dcf64b into WordPress:trunk Jul 25, 2022
@github-actions github-actions bot added this to the Gutenberg 13.8 milestone Jul 25, 2022
@pooja-muchandikar pooja-muchandikar deleted the add/playwright-hooks-api-test branch July 25, 2022 10:02
@Mamaduka Mamaduka added the [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. label Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants