Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

E2E tests for Single Product Template #5722

Merged
merged 21 commits into from
Feb 21, 2022
Merged

Conversation

sunyatasattva
Copy link
Contributor

@sunyatasattva sunyatasattva commented Feb 4, 2022

This PR adds E2E tests for the Single Product Template, and a bunch of test utils that we are going to be able to use in the next tests as well. It also adds an empty theme which supports block editing to the repo to be used with E2E tests.

Specifically regarding #5656, it covers the following test cases:

  • Should a user navigate to Site Editor > All Templates with an FSE theme active they should see the WooCommerce provided Single Product block template.
  • Should a user load the Single Product template, the editor will have the “WooCommerce Single Product Block” Legacy Template block present.
  • Should a user load the product page it will render product details and allow the user to add the product to their basket. (more details on why this wasn't added yet below)
  • Should a user customise the Single Product template and save it. The user should see a "Clear customizations" option on the All Templates view (clearing customisations functionality should be covered by Gutenberg)
  • Should a user load the customised Single Product template the Site Editor should render these customisations
  • Should a user have a customised Single Product template, these customisations would be present on the frontend.

Closes #5656

Testing

Automated Tests

  • Changes in this PR are covered by Automated Tests.
    • Unit tests
    • E2E tests

Manual Testing

How to test the changes in this Pull Request:

  1. Pull the latest trunk on the gutenberg monorepo, as this PR requires Refactor Site Editor test utils to the e2e-test-utils package WordPress/gutenberg#38463 to be there and the changes in e2e-test-utils, while merged on trunk, have not yet been published to npm.
  2. Run npm run test:e2e -- -i "tests/e2e/specs/backend/site-editing-templates.test.js"
  3. Assess that the included test cases pass.

User Facing Testing

These are steps for user testing (where "user" is someone interacting with this change that is not editing any code).

  • Same as above

@tjcafferkey As I was writing tests for this, I have been thinking more about the conversation in #5656, and I understood a bit more why it felt a bit out of place in this issue to test for the functionality mentioned in point 3.

Basically, I feel that this issue and PR should be more about the Single Product Template, while the adding to basket and so on, is more of a test of the Legacy Single Product Block.

After reading #5346 which you mentioned, I am 100% convinced that it is important that we test certain functionality separately from Woo Core. So, I'm not saying we should add the test case 3 above, but I feel that in the interest of trying to keep PRs small and focused, and iterate fast, it would be best to exclude that from this PR and instead open a new issue with tests for the Legacy Block itself.

What are your thoughts?

If you disagree, I'm totally ok with adding those tests here, but they will definitely require much more work, and perhaps it would be best to spec them in a bit more detailed way and decide what to test within a legacy block.

@sunyatasattva sunyatasattva added skip-changelog PRs that you don't want to appear in the changelog. category: tests focus: FSE Work related to prepare WooCommerce for FSE. labels Feb 4, 2022
@sunyatasattva sunyatasattva self-assigned this Feb 4, 2022
@rubikuserbot rubikuserbot requested a review from a team February 4, 2022 18:40
@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2022

Size Change: +1.29 kB (0%)

Total Size: 817 kB

Filename Size Change
build/active-filters-frontend.js 6.27 kB -103 B (-2%)
build/active-filters.js 6.95 kB -107 B (-2%)
build/all-products-frontend.js 18.7 kB -77 B (0%)
build/all-products.js 34.2 kB -37 B (0%)
build/all-reviews.js 8.06 kB +4 B (0%)
build/atomic-block-components/add-to-cart--atomic-block-components/button--atomic-block-components/catego--214e300a.js 151 B -104 B (-41%) 🎉
build/atomic-block-components/add-to-cart--atomic-block-components/button--atomic-block-components/image---a7e2bb9b.js 2.72 kB +21 B (+1%)
build/atomic-block-components/add-to-cart--atomic-block-components/button.js 0 B -1.48 kB (removed) 🏆
build/atomic-block-components/add-to-cart-frontend.js 7 kB +62 B (+1%)
build/atomic-block-components/add-to-cart.js 7.5 kB +998 B (+15%) ⚠️
build/atomic-block-components/button-frontend.js 1.54 kB -3 B (0%)
build/atomic-block-components/button.js 2.15 kB +1.24 kB (+136%) 🆘
build/atomic-block-components/category-list--atomic-block-components/image--atomic-block-components/ratin--2614069e.js 472 B +6 B (+1%)
build/atomic-block-components/category-list-frontend.js 896 B +70 B (+8%) 🔍
build/atomic-block-components/image-frontend.js 1.84 kB +71 B (+4%)
build/atomic-block-components/image.js 1.49 kB +395 B (+36%) 🚨
build/atomic-block-components/price-frontend.js 1.74 kB +1 B (0%)
build/atomic-block-components/rating-frontend.js 1.11 kB +69 B (+7%) 🔍
build/atomic-block-components/sale-badge-frontend.js 1.07 kB +68 B (+7%) 🔍
build/atomic-block-components/stock-indicator-frontend.js 1.01 kB +69 B (+7%) 🔍
build/atomic-block-components/stock-indicator.js 624 B +2 B (0%)
build/atomic-block-components/summary-frontend.js 1.31 kB +69 B (+6%) 🔍
build/atomic-block-components/tag-list-frontend.js 895 B +70 B (+8%) 🔍
build/atomic-block-components/title-frontend.js 1.28 kB +72 B (+6%) 🔍
build/atomic-block-components/title.js 933 B -1 B (0%)
build/attribute-filter-frontend.js 16.8 kB -51 B (0%)
build/attribute-filter.js 13 kB -7 B (0%)
build/cart-blocks/accepted-payment-methods-frontend.js 1.15 kB +1 B (0%)
build/cart-blocks/checkout-button-frontend.js 1.15 kB -2 B (0%)
build/cart-blocks/express-payment-frontend.js 5.19 kB +6 B (0%)
build/cart-blocks/filled-cart-frontend.js 767 B +1 B (0%)
build/cart-blocks/items-frontend.js 298 B -1 B (0%)
build/cart-blocks/line-items-frontend.js 5.51 kB +14 B (0%)
build/cart-blocks/order-summary-frontend.js 8.87 kB -3 B (0%)
build/cart-blocks/totals-frontend.js 321 B +1 B (0%)
build/cart-frontend.js 45.5 kB -53 B (0%)
build/cart.js 43.7 kB +30 B (0%)
build/checkout-blocks/actions-frontend.js 1.41 kB +1 B (0%)
build/checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 4.22 kB +3 B (0%)
build/checkout-blocks/billing-address-frontend.js 887 B -1 B (0%)
build/checkout-blocks/contact-information-frontend.js 2.94 kB +2 B (0%)
build/checkout-blocks/express-payment-frontend.js 5.48 kB +14 B (0%)
build/checkout-blocks/order-note-frontend.js 1.13 kB +2 B (0%)
build/checkout-blocks/order-summary-frontend.js 11.3 kB +6 B (0%)
build/checkout-blocks/payment-frontend.js 7.76 kB +10 B (0%)
build/checkout-blocks/shipping-address-frontend.js 974 B -2 B (0%)
build/checkout-blocks/terms-frontend.js 1.22 kB -1 B (0%)
build/checkout-blocks/totals-frontend.js 323 B -1 B (0%)
build/checkout-frontend.js 47.7 kB -50 B (0%)
build/checkout.js 45.2 kB +20 B (0%)
build/featured-category.js 8.61 kB -1 B (0%)
build/mini-cart-component-frontend.js 14.4 kB +91 B (+1%)
build/mini-cart-contents.js 3.84 kB +7 B (0%)
build/mini-cart-frontend.js 1.71 kB -95 B (-5%)
build/mini-cart.js 6.39 kB -2 B (0%)
build/price-filter-frontend.js 12.6 kB -58 B (0%)
build/price-filter.js 8.47 kB -32 B (0%)
build/product-best-sellers.js 7.36 kB -4 B (0%)
build/product-categories.js 3.17 kB -2 B (0%)
build/product-new.js 7.66 kB +2 B (0%)
build/product-on-sale.js 7.98 kB -4 B (0%)
build/product-search.js 2.19 kB +1 B (0%)
build/product-tag.js 7.81 kB +1 B (0%)
build/products-by-attribute.js 8.38 kB -3 B (0%)
build/reviews-by-category.js 11.5 kB +2 B (0%)
build/reviews-by-product.js 12.6 kB +5 B (0%)
build/reviews-frontend.js 7.34 kB -1 B (0%)
build/single-product-frontend.js 22.1 kB -78 B (0%)
build/single-product.js 10 kB +6 B (0%)
build/stock-filter-frontend.js 6.5 kB -104 B (-2%)
build/stock-filter.js 6.58 kB -112 B (-2%)
build/vendors--atomic-block-components/add-to-cart--cart-blocks/order-summary--checkout-blocks/billing-ad--c5eb4dcd-frontend.js 19 kB +8 B (0%)
build/vendors--atomic-block-components/add-to-cart-frontend.js 7.51 kB +1 B (0%)
build/wc-blocks-editor-style-rtl.css 4.85 kB +1 B (0%)
build/wc-blocks-style-rtl.css 22.2 kB +62 B (0%)
build/wc-blocks-style.css 22.2 kB +75 B (0%)
build/wc-blocks-vendors.js 69.7 kB +5 B (0%)
build/wc-blocks.js 2.62 kB +1 B (0%)
build/atomic-block-components/add-to-cart--atomic-block-components/category-list--atomic-block-components--68f6c1c4.js 203 B +203 B (new file) 🆕
ℹ️ View Unchanged
Filename Size
build/atomic-block-components/category-list.js 500 B
build/atomic-block-components/price.js 1.69 kB
build/atomic-block-components/rating.js 719 B
build/atomic-block-components/sale-badge.js 685 B
build/atomic-block-components/sku-frontend.js 386 B
build/atomic-block-components/sku.js 386 B
build/atomic-block-components/summary.js 923 B
build/atomic-block-components/tag-list.js 499 B
build/blocks-checkout.js 17.6 kB
build/cart-blocks/empty-cart-frontend.js 345 B
build/checkout-blocks/fields-frontend.js 344 B
build/checkout-blocks/shipping-methods-frontend.js 4.81 kB
build/featured-product.js 9.62 kB
build/handpicked-products.js 7.09 kB
build/legacy-template.js 2.18 kB
build/price-format.js 1.18 kB
build/product-category.js 8.49 kB
build/product-top-rated.js 7.9 kB
build/vendors--atomic-block-components/price--cart-blocks/line-items--cart-blocks/order-summary--checkout--8a3571de-frontend.js 5.71 kB
build/vendors--cart-blocks/line-items--checkout-blocks/order-summary-frontend.js 3.14 kB
build/vendors--cart-blocks/order-summary--checkout-blocks/billing-address--checkout-blocks/order-summary---eb4d2cec-frontend.js 4.74 kB
build/wc-blocks-data.js 8.84 kB
build/wc-blocks-editor-style.css 4.85 kB
build/wc-blocks-google-analytics.js 1.56 kB
build/wc-blocks-middleware.js 949 B
build/wc-blocks-registry.js 2.7 kB
build/wc-blocks-shared-context.js 1.52 kB
build/wc-blocks-shared-hocs.js 1.14 kB
build/wc-blocks-vendors-style-rtl.css 1.28 kB
build/wc-blocks-vendors-style.css 1.28 kB
build/wc-payment-method-bacs.js 816 B
build/wc-payment-method-cheque.js 811 B
build/wc-payment-method-cod.js 909 B
build/wc-payment-method-paypal.js 837 B
build/wc-settings.js 2.61 kB

compressed-size-action

@tjcafferkey
Copy link
Contributor

So, I'm not saying we should add the test case 3 above, but I feel that in the interest of trying to keep PRs small and focused, and iterate fast, it would be best to exclude that from this PR and instead open a new issue with tests for the Legacy Block itself.

What are your thoughts?

I think this is a good idea @sunyatasattva, thank you for proposing it. If it reduces the scope of this PR and can be done in a follow-up issue I think that is totally fine. At the moment we have zero tests, so if this means we get some tests sooner with a view to iterate then I am all for that! 👍🏻

@sunyatasattva sunyatasattva force-pushed the test/5656-fse-single-product branch from e276591 to b90736c Compare February 10, 2022 18:27
tests/e2e/utils.js Outdated Show resolved Hide resolved
Comment on lines +130 to +137
*
* There are two different possible site editor pages:
*
* 1. `themes.php?page=gutenberg-edit-site` is the one used and available if the Gutenberg plugin is enabled.
* 2. `site-editor.php` is the one available in WP Core.
*
* @param {string} query String to be serialized as query portion of URL.
* @param {'core' | 'gutenberg'} [editorContext='core'] Whether to go to the Gutenberg URL or the Core one.
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL - thanks for all the included insights!

Copy link
Contributor

Choose a reason for hiding this comment

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

I was curious and had a look at the util on gutenberg side and the query params seems to be used as JSON object but I've noticed we are using it as url search string.

There is a wrong typing information on the visitSiteEditor util. if we passed query as a string to visitSiteEditor it would fail or at least the query part can produce unexpected results, no? The addQueryArgs used underneath seems to expect an object of query params but then gets mutated into a string with addQueryArgs

visitAdminPage does indeed expect a string. I think we should handle the query to ensure it's compatible with both paths if we want to make both of them available.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a wrong typing information on the visitSiteEditor util. if we passed query as a string to visitSiteEditor it would fail or at least the query part can produce unexpected results, no? The addQueryArgs used underneath seems to expect an object of query params but then gets mutated into a string with addQueryArgs

Good catch! I must have typed it early when I didn't use the query contructor util and then forgot to change it. The woes of not having TS!

visitAdminPage does indeed expect a string. I think we should handle the query to ensure it's compatible with both paths if we want to make both of them available.

I was curious and had a look at the util on gutenberg side and the query params seems to be used as JSON object but I've noticed we are using it as url search string.

Not sure I understand what you mean in those two, could you elaborate?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry placed the comment marker above implementation because I referred to the comment first. It's about the goToSiteEditor method right under and the error in typing I mentioned above.

https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/3963eabb3efdd1820f2f8c323d01c9a9b2ba2c8d/tests/e2e/utils.js#L139-L146

We accept query as string but visitSiteEditor if context is gutenberg expects object.

Comment on lines +51 to +58
const SELECTORS = {
blocks: {
paragraph: blockSelector( 'core/paragraph' ),
singleProduct: legacyBlockSelector(
'WooCommerce Single Product Block'
),
},
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense for universal selectors and selector functions above to be part of utils?
We already seem to have some SELECTORS there.

I could imagine this could grow one day to earn its own file :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my opinion and experience with Puppeteer, it's not recommended to have one huge selectors object. In fact, the correct way would be to use the Page Object Pattern, which I am discussing with the Gutenberg fellas (they are actually also agreeing, it's just a matter of a huge refactor).

In this case, my intention is to separate selectors which are universally useful, and selectors which are specific to a test case/test file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Had a quick look at Page Object Pattern, looks really interesting. If you had a link to the discussions on this I'd love to learn more!

*/
export async function elementExists( selector, root = page ) {
return !! ( await root.$( selector ) );
}
Copy link
Contributor

Choose a reason for hiding this comment

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

would it make sense to split into "general" utils and user flow utils? Ie. repeated user actions related to particular domain.

I liked how you laid it out in Gutenberg repo 🎉 where different domains (ie. site-editor, particular block type etc.) would have their files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does make sense, I agree. Will edit!

tests/mocks/emptytheme/theme.json Outdated Show resolved Hide resolved
Copy link
Contributor

@tomasztunik tomasztunik left a comment

Choose a reason for hiding this comment

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

👌

@github-actions github-actions bot added this to the 7.1.0 milestone Feb 21, 2022
@sunyatasattva sunyatasattva merged commit 64c90e6 into trunk Feb 21, 2022
@sunyatasattva sunyatasattva deleted the test/5656-fse-single-product branch February 21, 2022 10:01
tarhi-saad pushed a commit that referenced this pull request Feb 26, 2022
* Add empty block theme to mock E2E tests
* Install empty theme in the test WP instance
*
* @return {Promise<boolean>} Whether the element exists or not
*/
export async function elementExists( selector, root = page ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We could use instead of this the toMatchElement utility that we already have via expect-puppeteer.

Expect an element be present in the page or element.

@sunyatasattva @tomasztunik

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ralucaStan Oh but they are not mutually exclusive. toMatchElement is an assertion, this is not supposed to be an assertion. It can be used for example as a guard clause. Or you can see how it is used here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, thank you for explaining it to me. The example helped. Maybe it would be good to add a few words about the purpose, so that we don't end up using it in places where toMatchElement might be better. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! I agree, I didn't think about it, I'll add it to my notes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
focus: FSE Work related to prepare WooCommerce for FSE. skip-changelog PRs that you don't want to appear in the changelog.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Store Editing Templates: Add E2E tests for Single Product block template
4 participants