Skip to content
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 Cover Block tests to Playwright #45784

Merged
merged 17 commits into from
May 15, 2023
Merged

Migrate Cover Block tests to Playwright #45784

merged 17 commits into from
May 15, 2023

Conversation

worldomonation
Copy link
Contributor

@worldomonation worldomonation commented Nov 15, 2022

What?

This PR is part of the migration effort tracked at #38851.

Why?

This PR proposes a migration of the cover.test.js to the new Playwright-based framework.

How?

Testing Instructions

npm run test:e2e:playwright -- test/e2e/specs/editor/blocks/cover.spec.js

In the current form (pending outcome of this question, it should produce the following outcome:

Running 6 tests using 1 worker

  ✓  1 …2 › Cover › can set overlay color using color picker on block placeholder (2.4s)
Failed to load resource: the server responded with a status of 404 (Not Found)
  ✓  2 … Cover › can set background image using image upload on block placeholder (3.3s)
Failed to load resource: the server responded with a status of 404 (Not Found)
  ✓  3 …over.spec.js:102:2 › Cover › dims background image down by 50% by default (1.8s)
Failed to load resource: the server responded with a status of 404 (Not Found)
  ✓  4 …] › editor/blocks/cover.spec.js:126:2 › Cover › can have the title edited (2.3s)
Failed to load resource: the server responded with a status of 404 (Not Found)
  ✓  5 …tor/blocks/cover.spec.js:151:2 › Cover › can be resized using drag & drop (2.4s)
Failed to load resource: the server responded with a status of 404 (Not Found)
  -  6 …er › dims the background image down by 50% when transformed from the Image block

  1 skipped
  5 passed (13.1s)

Screenshots or screencast

@codesandbox
Copy link

codesandbox bot commented Nov 15, 2022

CodeSandbox logoCodeSandbox logo  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Nov 15, 2022
@github-actions
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @worldomonation! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@worldomonation worldomonation marked this pull request as ready for review November 15, 2022 20:52
@worldomonation
Copy link
Contributor Author

Hi folks - this is my first PR in the Gutenberg repo. As I understand it, I must wait for the tests to be triggered manually.

@worldomonation
Copy link
Contributor Author

Looks like my run at https://github.com/WordPress/gutenberg/actions/runs/3474015855 failed. I will need to investigate why it is failing on CI and not locally.

@Mamaduka Mamaduka added the [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. label Nov 16, 2022
@kevin940726
Copy link
Member

Hi! I only just saw this now 😞 . Sorry for the late reply! And thank you for your contribution!

@worldomonation
Copy link
Contributor Author

worldomonation commented Apr 26, 2023

@kevin940726 I have a quick question regarding the await editor.transformBlockTo( <block_name> ) method.

When I call the aforementioned method in one of the specs I am migrating, the following error is thrown at the end:

  1) [chromium] › editor/blocks/cover.spec.js:200:7 › Cover › dims the background image down by 50% when transformed from the Image block

    Error: page.evaluate: window.wp.galleryBlockV2Enabled is not defined

       at ../../../packages/e2e-test-utils-playwright/src/editor/transform-block-to.ts:13

      11 |  */
      12 | export async function transformBlockTo( this: Editor, name: string ) {
    > 13 | 	await this.page.evaluate(
         | 	                ^
      14 | 		( [ blockName ] ) => {
      15 | 			const clientIds = window.wp.data
      16 | 				.select( 'core/block-editor' )

        at Editor.transformBlockTo (gutenberg/packages/e2e-test-utils-playwright/src/editor/transform-block-to.ts:13:18)
        at gutenberg/test/e2e/specs/editor/blocks/cover.spec.js:221:16

I'm do not understand why the transformBlockTo is calling galleryBlockV2Enabled. Could you point me in the right direction?

- update spec with accessibility-based selectors where possible.
@kevin940726
Copy link
Member

@worldomonation Could you share a branch so that I can test locally?

@worldomonation
Copy link
Contributor Author

@worldomonation Could you share a branch so that I can test locally?

Sure, my work is in the forked repo worldomonation:add/playwright-cover-block-e2e.
Link to the branch in my forked repo.

@kevin940726
Copy link
Member

@worldomonation I just checked out your code and the test passed locally for me. Could you try again?

@worldomonation
Copy link
Contributor Author

@worldomonation I just checked out your code and the test passed locally for me. Could you try again?

Thanks for trying. I had marked the step with the issue, dims the background image down by 50% when transformed from the Image block, as skipped. Did you unskip it?

@kevin940726
Copy link
Member

@worldomonation Yep, I unskipped it.

@worldomonation
Copy link
Contributor Author

@worldomonation Yep, I unskipped it.

I think I figured it out.
I started this PR back at Denver in late 2022, and haven't looked at it until this week. I thought I had updated my local, forked repo with upstream but looks like I neglected to do that plus a npm run build.

It now passes for me locally too. Thanks for helping me work through the issues.

I hope to have this ready for review soon.

- clarify use of `span` element in the first spec.
test/e2e/specs/editor/blocks/cover.spec.js Outdated Show resolved Hide resolved
test/e2e/specs/editor/blocks/cover.spec.js Outdated Show resolved Hide resolved
test/e2e/specs/editor/blocks/cover.spec.js Outdated Show resolved Hide resolved
test/e2e/specs/editor/blocks/cover.spec.js Outdated Show resolved Hide resolved
test/e2e/specs/editor/blocks/cover.spec.js Outdated Show resolved Hide resolved
test/e2e/specs/editor/blocks/cover.spec.js Outdated Show resolved Hide resolved
test/e2e/specs/editor/blocks/cover.spec.js Show resolved Hide resolved
test/e2e/specs/editor/blocks/cover.spec.js Outdated Show resolved Hide resolved
test/e2e/specs/editor/blocks/cover.spec.js Outdated Show resolved Hide resolved
test/e2e/specs/editor/blocks/cover.spec.js Outdated Show resolved Hide resolved
…-box__handle-bottom'.

- move image upload and filename methods previously handled by `getTestImage` into a POM-like function at bottom of file.
…at locator as starting point for all other interactions.

- use `getComputedStyle` instad of `node.style.<attribute>`.
- replace implementation detail check on image upload with a `expect.toPass` check.
- remove steps when resizing box.
- replace implementation detail check for coverbox height with truthy check.
@worldomonation
Copy link
Contributor Author

@kevin940726 I left two questions - 1 and 2 that I needed further clarification on how to proceed.

I'm more than happy for more rounds of code reviews should you deem it necessary, so please feel free to take apart the revised spec. Thanks!

Copy link
Member

@kevin940726 kevin940726 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for the updates! I left some suggestions and feedback below. Overall this is looking very good though! 💯

test/e2e/specs/editor/blocks/cover.spec.js Outdated Show resolved Hide resolved
test/e2e/specs/editor/blocks/cover.spec.js Outdated Show resolved Hide resolved
test/e2e/specs/editor/blocks/cover.spec.js Outdated Show resolved Hide resolved
test/e2e/specs/editor/blocks/cover.spec.js Outdated Show resolved Hide resolved
test/e2e/specs/editor/blocks/cover.spec.js Outdated Show resolved Hide resolved
Copy link
Member

@kevin940726 kevin940726 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great! Just a small suggestion and I think we're good to go! Thank you so much for the hard work! 🙇

} );
} );

class ImageBlockUtils {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should name it CoverBlockUtils? 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I thought maybe ImageBlockUtils was always used as the name for the POM class, for some reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name changed to CoverBlockUtils in 405c709.

Copy link
Member

@kevin940726 kevin940726 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again! 💯

@worldomonation This is really well done! I couldn't have done it better myself! Also congrats on your first merged PR!

@kevin940726 kevin940726 merged commit 9e6b646 into WordPress:trunk May 15, 2023
@github-actions
Copy link

Congratulations on your first merged pull request, @worldomonation! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts:

https://profiles.wordpress.org/me/profile/edit/

And if you don't have a WordPress.org account, you can create one on this page:

https://login.wordpress.org/register

Kudos!

@github-actions github-actions bot added this to the Gutenberg 15.9 milestone May 15, 2023
@worldomonation
Copy link
Contributor Author

Thanks again! 💯

@worldomonation This is really well done! I couldn't have done it better myself! Also congrats on your first merged PR!

Thanks @kevin940726 for the many rounds of review. I really enjoyed working on this and would love to pick up a few more in the coming weeks! Thank you again.

@worldomonation worldomonation deleted the add/playwright-cover-block-e2e branch May 16, 2023 02:41
@cbravobernal cbravobernal added the [Type] Code Quality Issues or PRs that relate to code quality label May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants