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

E2E: Product Query: Popular filters presets #7749

Merged
merged 48 commits into from
Jan 5, 2023
Merged

Conversation

dinhtungdu
Copy link
Member

@dinhtungdu dinhtungdu commented Nov 25, 2022

Fixes #7933

This PR adds E2E tests to verify the functionalities of Popular filters presets. The failed test is related to Gutenberg 14.8.0. The Popular Filter tests are passing: https://github.com/woocommerce/woocommerce-blocks/actions/runs/3805026894/jobs/6472662871#step:12:241

Testing

Automated Tests

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

To run the Gutenberg only test locally:

  1. Change the directory to the plugin root directory in the terminal.
  2. Destroy the current wp-env instance: npm run wp-env destroy
  3. Setup Gutenberg config for wp-env: node bin/wp-env-with-gutenberg.js
  4. Spin up new test environment: npm run wp-env start
  5. Run the test with GUTENBERG_EDITOR_CONTEXT set to gutenberg: GUTENBERG_EDITOR_CONTEXT=gutenberg npm run test:e2e tests/e2e/specs/backend/product-query/popular-filters.test.ts

@dinhtungdu dinhtungdu self-assigned this Nov 25, 2022
@dinhtungdu dinhtungdu added skip-changelog PRs that you don't want to appear in the changelog. category: tests block-type: product-query Issues related to/affecting all product-query variations. labels Nov 25, 2022
@github-actions
Copy link
Contributor

The release ZIP for this PR is accessible via:

https://wcblocks.wpcomstaging.com/wp-content/uploads/woocommerce-gutenberg-products-block-7749.zip

@github-actions
Copy link
Contributor

github-actions bot commented Nov 25, 2022

Size Change: -532 B (0%)

Total Size: 1.01 MB

Filename Size Change
build/active-filters-frontend.js 7.8 kB +59 B (+1%)
build/active-filters-wrapper-frontend.js 6.07 kB +57 B (+1%)
build/active-filters.js 7.38 kB +59 B (+1%)
build/all-products-frontend.js 11.4 kB +145 B (+1%)
build/all-products.js 33.5 kB +61 B (0%)
build/attribute-filter-frontend.js 22.8 kB +71 B (0%)
build/attribute-filter-wrapper-frontend.js 5.07 kB -2.6 kB (-34%) 🎉
build/attribute-filter.js 12.4 kB +64 B (+1%)
build/blocks-checkout.js 39.5 kB -2 B (0%)
build/cart-blocks/cart-accepted-payment-methods-frontend.js 1.38 kB +1 B (0%)
build/cart-blocks/cart-cross-sells-products-frontend.js 9.64 kB +6 B (0%)
build/cart-blocks/cart-express-payment--checkout-blocks/express-payment-frontend.js 5.08 kB +1 B (0%)
build/cart-blocks/cart-line-items--mini-cart-contents-block/products-table-frontend.js 5.29 kB +1 B (0%)
build/cart-blocks/cart-line-items-frontend.js 1.07 kB +1 B (0%)
build/cart-blocks/empty-cart-frontend.js 344 B +1 B (0%)
build/cart-blocks/filled-cart-frontend.js 782 B -1 B (0%)
build/cart-blocks/order-summary-heading-frontend.js 456 B +1 B (0%)
build/cart-blocks/order-summary-shipping-frontend.js 14.6 kB +1 B (0%)
build/cart-frontend.js 28.1 kB -4 B (0%)
build/cart.js 46.9 kB -1 B (0%)
build/checkout-blocks/actions-frontend.js 1.86 kB -1 B (0%)
build/checkout-blocks/order-summary-discount-frontend.js 2.29 kB +1 B (0%)
build/checkout-blocks/shipping-address-frontend.js 1.11 kB +1 B (0%)
build/checkout-blocks/totals-frontend.js 325 B +1 B (0%)
build/checkout-frontend.js 29.4 kB +7 B (0%)
build/checkout.js 40.9 kB +1 B (0%)
build/filter-wrapper-frontend.js 13.8 kB +25 B (0%)
build/mini-cart-component-frontend.js 20 kB -6 B (0%)
build/mini-cart-contents-block/products-table-frontend.js 590 B -1 B (0%)
build/price-filter-frontend.js 13.7 kB +66 B (0%)
build/price-filter-wrapper-frontend.js 7.08 kB +67 B (+1%)
build/price-filter.js 8.45 kB +70 B (+1%)
build/product-add-to-cart-frontend.js 6.71 kB -2 B (0%)
build/product-add-to-cart.js 8.48 kB -2 B (0%)
build/product-button-frontend.js 2.16 kB +4 B (0%)
build/product-category-list-frontend.js 1.14 kB +2 B (0%)
build/product-image-frontend.js 2.16 kB +7 B (0%)
build/product-image.js 3.93 kB -3 B (0%)
build/product-query.js 5.88 kB -56 B (-1%)
build/product-rating-frontend.js 1.59 kB +2 B (0%)
build/product-sale-badge-frontend.js 1.39 kB +4 B (0%)
build/product-stock-indicator-frontend.js 1.27 kB +8 B (+1%)
build/product-tag-list-frontend.js 1.14 kB +1 B (0%)
build/product-title.js 3.31 kB +1 B (0%)
build/rating-filter-frontend.js 21.2 kB +80 B (0%)
build/rating-filter-wrapper-frontend.js 6.26 kB +77 B (+1%)
build/rating-filter.js 7.45 kB +68 B (+1%)
build/single-product-frontend.js 17.3 kB +2 B (0%)
build/stock-filter-frontend.js 20.9 kB +80 B (0%)
build/stock-filter-wrapper-frontend.js 3.16 kB -2.7 kB (-46%) 🎉
build/stock-filter.js 8.19 kB +65 B (+1%)
build/vendors--attribute-filter-wrapper--cart-blocks/cart-cross-sells-products--cart-blocks/order-summary--cde4eab5-frontend.js 6.86 kB -1 B (0%)
build/vendors--attribute-filter-wrapper--rating-filter-wrapper--stock-filter-wrapper-frontend.js 7.7 kB +1 B (0%)
build/vendors--cart-blocks/cart-cross-sells-products--product-add-to-cart-frontend.js 7.53 kB +1 B (0%)
build/wc-blocks-data.js 21.2 kB +5 B (0%)
build/wc-blocks-registry.js 2.92 kB +1 B (0%)
build/wc-blocks-shared-hocs.js 1.88 kB +154 B (+9%) 🔍
build/wc-blocks-vendors.js 62.7 kB +72 B (0%)
build/attribute-filter-wrapper--stock-filter-wrapper-frontend.js 3.44 kB +3.44 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size
build/all-reviews.js 7.65 kB
build/cart-blocks/cart-cross-sells-frontend.js 253 B
build/cart-blocks/cart-express-payment-frontend.js 720 B
build/cart-blocks/cart-items-frontend.js 299 B
build/cart-blocks/cart-order-summary-frontend.js 1.25 kB
build/cart-blocks/cart-totals-frontend.js 322 B
build/cart-blocks/order-summary-coupon-form-frontend.js 1.78 kB
build/cart-blocks/order-summary-discount-frontend.js 2.13 kB
build/cart-blocks/order-summary-fee-frontend.js 273 B
build/cart-blocks/order-summary-subtotal-frontend.js 273 B
build/cart-blocks/order-summary-taxes-frontend.js 436 B
build/cart-blocks/proceed-to-checkout-frontend.js 1.24 kB
build/checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 3.86 kB
build/checkout-blocks/billing-address-frontend.js 1.12 kB
build/checkout-blocks/contact-information-frontend.js 2 kB
build/checkout-blocks/express-payment-frontend.js 1.14 kB
build/checkout-blocks/fields-frontend.js 343 B
build/checkout-blocks/order-note-frontend.js 1.14 kB
build/checkout-blocks/order-summary-cart-items-frontend.js 3.67 kB
build/checkout-blocks/order-summary-coupon-form-frontend.js 1.93 kB
build/checkout-blocks/order-summary-fee-frontend.js 275 B
build/checkout-blocks/order-summary-frontend.js 1.25 kB
build/checkout-blocks/order-summary-shipping-frontend.js 14.6 kB
build/checkout-blocks/order-summary-subtotal-frontend.js 273 B
build/checkout-blocks/order-summary-taxes-frontend.js 436 B
build/checkout-blocks/payment-frontend.js 8.34 kB
build/checkout-blocks/shipping-methods-frontend.js 4.57 kB
build/checkout-blocks/terms-frontend.js 1.56 kB
build/customer-account.js 3.08 kB
build/featured-category.js 13.1 kB
build/featured-product.js 13.3 kB
build/filter-wrapper.js 2.4 kB
build/general-style-rtl.css 1.29 kB
build/general-style.css 1.29 kB
build/handpicked-products.js 7.22 kB
build/legacy-template.js 2.85 kB
build/mini-cart-contents-block/empty-cart-frontend.js 366 B
build/mini-cart-contents-block/filled-cart-frontend.js 388 B
build/mini-cart-contents-block/footer-frontend.js 2.81 kB
build/mini-cart-contents-block/items-frontend.js 237 B
build/mini-cart-contents-block/shopping-button-frontend.js 313 B
build/mini-cart-contents-block/title-frontend.js 368 B
build/mini-cart-contents.js 16.7 kB
build/mini-cart-frontend.js 1.88 kB
build/mini-cart.js 4.26 kB
build/price-format.js 1.19 kB
build/product-add-to-cart--product-button--product-category-list--product-image--product-price--product-r--a0326d00.js 226 B
build/product-add-to-cart--product-button--product-image--product-rating--product-title.js 151 B
build/product-best-sellers.js 7.58 kB
build/product-button--product-category-list--product-image--product-price--product-rating--product-sale-b--e17c7c01.js 443 B
build/product-button--product-image--product-rating--product-sale-badge--product-title.js 302 B
build/product-button.js 3.84 kB
build/product-categories.js 2.36 kB
build/product-category-list.js 502 B
build/product-category.js 8.57 kB
build/product-new.js 7.57 kB
build/product-on-sale.js 7.89 kB
build/product-price-frontend.js 2.18 kB
build/product-price.js 1.54 kB
build/product-rating.js 919 B
build/product-sale-badge.js 814 B
build/product-search.js 2.62 kB
build/product-sku-frontend.js 629 B
build/product-sku.js 377 B
build/product-stock-indicator.js 645 B
build/product-summary-frontend.js 1.53 kB
build/product-summary.js 919 B
build/product-tag-list.js 497 B
build/product-tag.js 8.06 kB
build/product-title-frontend.js 1.59 kB
build/product-top-rated.js 7.81 kB
build/products-by-attribute.js 8.5 kB
build/reviews-by-category.js 11.2 kB
build/reviews-by-product.js 12.3 kB
build/reviews-frontend.js 6.88 kB
build/single-product.js 9.96 kB
build/vendors--cart-blocks/cart-cross-sells-products--cart-blocks/cart-line-items--cart-blocks/cart-order--671ca56f-frontend.js 5.26 kB
build/vendors--cart-blocks/cart-cross-sells-products--cart-blocks/order-summary-shipping--checkout-blocks--18f9376a-frontend.js 19.1 kB
build/vendors--cart-blocks/cart-line-items--checkout-blocks/order-summary-cart-items--mini-cart-contents---233ab542-frontend.js 3.14 kB
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/billing-address--checkout-blocks/order--5b8feb0b-frontend.js 4.82 kB
build/vendors--checkout-blocks/shipping-methods-frontend.js 9.48 kB
build/wc-blocks-editor-style-rtl.css 5.41 kB
build/wc-blocks-editor-style.css 5.41 kB
build/wc-blocks-google-analytics.js 1.56 kB
build/wc-blocks-middleware.js 931 B
build/wc-blocks-shared-context.js 1.52 kB
build/wc-blocks-style-rtl.css 24.8 kB
build/wc-blocks-style.css 24.8 kB
build/wc-blocks-vendors-style-rtl.css 1.95 kB
build/wc-blocks-vendors-style.css 1.95 kB
build/wc-blocks.js 2.63 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.6 kB

compressed-size-action

@github-actions
Copy link
Contributor

github-actions bot commented Nov 25, 2022

TypeScript Errors Report

Files with errors: 439
Total errors: 2096

🎉 🎉 This PR does not introduce new TS errors.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 3, 2022

This PR has been marked as stale because it has not seen any activity within the past 7 days. Our team uses this tool to help surface pull requests that have slipped through review.

If deemed still relevant, the pr can be kept active by ensuring it's up to date with the main branch and removing the stale label.

@github-actions github-actions bot added the status: stale Stale issues and PRs have had no updates for 60 days. label Dec 3, 2022
@dinhtungdu
Copy link
Member Author

dinhtungdu commented Dec 29, 2022

@gigitux FYI this will create conflicts to your PR #7956:

  • The local constants and utilities are exported from common.ts as I mentioned in our chat.
  • getFormElementIdByLabel gets an update to accept class with or without leading ..

@dinhtungdu dinhtungdu marked this pull request as draft December 29, 2022 15:35
@dinhtungdu dinhtungdu marked this pull request as ready for review December 30, 2022 05:46
@woocommercebot woocommercebot requested a review from a team December 30, 2022 05:47
Copy link
Contributor

@sunyatasattva sunyatasattva left a comment

Choose a reason for hiding this comment

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

I've got very little to comment about this PR: this is excellent work Tung!

Comment on lines +135 to +137
await expect( $productFiltersPanel ).toMatch( 'In stock' );
await expect( $productFiltersPanel ).toMatch( 'Out of stock' );
await expect( $productFiltersPanel ).toMatch( 'On backorder' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a big deal, but should this also be perhaps related to the fixture data?

We could have a loop on something like getFixtureProductsData( 'stock_statii' ) and make it more future proof?

Copy link
Member Author

Choose a reason for hiding this comment

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

  • Fixture doesn't have any information about all available statuses right now, we need to hard-code it if we want to get stock statuses from it.
  • In the future, if WC Core changes the default stock statuses, we will need to update the fixture as well. To me, updating this test or updating the fixture is similar. Test should be updated as the WC and WC Blocks update.
  • I checked WooCommerce REST API to see if there is any endpoint returning available stock status, but sadly there is none.
  • We can centeralize the reference for available stock status options, but it should be a utility or a constants, not in the fixture data.

it( 'Products are displayed in the correct order', async () => {
const { productQueryProducts, shortcodeProducts } =
await setupProductQueryShortcodeComparison(
'[products orderby="title" order="ASC" limit="9"]'
Copy link
Contributor

Choose a reason for hiding this comment

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

I would refactor these shortcodes in a variable above, to make them less buried and easier to spot.

Copy link
Member Author

Choose a reason for hiding this comment

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

I addressed this and your other comments in e60cf03

Comment on lines 55 to 59
it( 'Editor preview and block frontend display the same products', async () => {
const { previewProducts, frontEndProducts } =
await setupEditorFrontendComparison();
expect( frontEndProducts ).toEqual( previewProducts );
} );
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be repeated in every test case, why not just refactoring it to avoid duplicates?

Comment on lines 99 to 105
it( 'Products are displayed in the correct order', async () => {
const { productQueryProducts, shortcodeProducts } =
await setupProductQueryShortcodeComparison(
'[products best_selling="true" limit="9"]'
);
expect( productQueryProducts ).toEqual( shortcodeProducts );
} );
Copy link
Contributor

Choose a reason for hiding this comment

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

This is also repeated over and over, the only thing that's changing is the shortcode. So you could refactor it into a function that accepts a shortcode string and that would save lines of code and make it more maintainable.

Copy link
Contributor

@nefeline nefeline left a comment

Choose a reason for hiding this comment

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

Awesome to see these tests in place for the Advanced and Popular Filters, great work! I've added a few recommendations, mostly regarding code reuse and suggestions for the way the tests are organized, so they are more atomic/single-purposed.

Regarding the advanced filters tests, I've added a question and shared some insights over here.

When running the tests locally for popular-filters.test.ts, all of them are consistently passing, except for Best Selling > Editor preview and block frontend display the same products: previewProducts and frontEndProducts are not exactly the same.

'Show only products on sale'
);
await toggleAdvancedFilter( 'Sale status' );
await expect( $productFiltersPanel ).not.toMatch(
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about reusing more code here by extracting common/duplicated lines into utility functions to make the tests easier to read and maintain?

Copy link
Member Author

@dinhtungdu dinhtungdu Jan 3, 2023

Choose a reason for hiding this comment

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

Can you suggest something here? At the moment, I don't have a good idea to refactor this further.

From the test code I can see the test perform these step:

  1. Toggle the Sale status filter.
  2. Verify the panel contains the option label.
  3. Toggle the Sale status filter again.
  4. verify the panel doesn't contain the option label anymore.

I'm curious about what you read from the test. If we can do anything to increase the readability, I'm all in.

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 thinking something along these lines (for the editor preview test, for example):

const toggleSaleStatusFilter = async () => {
	await toggleAdvancedFilter( 'Sale status' );
	await setCheckbox( await getToggleIdByLabel( 'Show only products on sale' ) );
};

const removeSaleStatusFilter = async () => {
	await toggleAdvancedFilter( 'Sale status' );
	await unsetCheckbox( await getToggleIdByLabel( 'Show only products on sale' ) );
};

But that is super minor/a nit! The tests are now structured nicely, a-ok to keep them as-is :)

tests/e2e/specs/backend/product-query/common.ts Outdated Show resolved Hide resolved
@dinhtungdu
Copy link
Member Author

Thank you so much for your reviews! @sunyatasattva @nefeline. I addressed your reviews, can you please take another look at this?

When running the tests locally for popular-filters.test.ts, all of them are consistently passing, except for Best Selling > Editor preview and block frontend display the same products: previewProducts and frontEndProducts are not exactly the same.

I have the same issue running the test locally but can't reproduce it on the CI. Somehow, the tests are only flaky in the local machine, not in CI.

Copy link
Contributor

@sunyatasattva sunyatasattva left a comment

Choose a reason for hiding this comment

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

I like the changes! Thanks for refactoring away the duplicated code :)

Copy link
Contributor

@nefeline nefeline 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 the updates, great work 🚀 !! All tests are passing here, except for the 'Product Query > Popular Filters › Popular Filters is expanded by default': interesting that it doesn't fail on the CI: one more to the hall of fame of flaky tests.

@github-actions github-actions bot added this to the 9.4.0 milestone Jan 5, 2023
@dinhtungdu dinhtungdu merged commit 6fb8f7d into trunk Jan 5, 2023
@dinhtungdu dinhtungdu deleted the tests/popular-filters branch January 5, 2023 11:21
@gigitux gigitux added the type: technical debt This issue/PR represents/solves the technical debt of the project. label Jan 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block-type: product-query Issues related to/affecting all product-query variations. skip-changelog PRs that you don't want to appear in the changelog. type: technical debt This issue/PR represents/solves the technical debt of the project.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Product Query: [Tests] Add E2E tests for Popular Filters
4 participants