From 2c628a29389a9d34ba7189cd14055fa80913d49f Mon Sep 17 00:00:00 2001 From: Karol Manijak <20098064+kmanijak@users.noreply.github.com> Date: Mon, 15 Jan 2024 11:25:49 +0100 Subject: [PATCH] Product Collection: add E2E tests to Editor filters - by tag and by stock status (#43548) * Add test to check Product Collection filtering by tags * Set single product out of stock and unskip the test for stock status * Add changelog * Use more specific selector * Update variables holding products in products.sh to keep the same convention --- .../tests/e2e/bin/scripts/products.sh | 16 +++++++----- .../product-collection.block_theme.spec.ts | 26 +++++++++++++++---- ...n-add-e2e-tests-which-require-fixture-data | 4 +++ 3 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 plugins/woocommerce/changelog/42284-product-collection-add-e2e-tests-which-require-fixture-data diff --git a/plugins/woocommerce-blocks/tests/e2e/bin/scripts/products.sh b/plugins/woocommerce-blocks/tests/e2e/bin/scripts/products.sh index e17e9b11eb0..84219b2d547 100644 --- a/plugins/woocommerce-blocks/tests/e2e/bin/scripts/products.sh +++ b/plugins/woocommerce-blocks/tests/e2e/bin/scripts/products.sh @@ -15,20 +15,24 @@ wp wc product_cat update $hoodies_category_id --parent=$clothing_category_id --u # This is a hacky work around to fix product gallery images not being imported # This sets up the product Hoodie to have product gallery images for e2e testing -post_id=$(wp post list --post_type=product --field=ID --name="Hoodie" --format=ids) +hoodie_product_id=$(wp post list --post_type=product --field=ID --name="Hoodie" --format=ids) image1=$(wp post list --post_type=attachment --field=ID --name="hoodie-with-logo-2.jpg" --format=ids) image2=$(wp post list --post_type=attachment --field=ID --name="hoodie-green-1.jpg" --format=ids) image3=$(wp post list --post_type=attachment --field=ID --name="hoodie-2.jpg" --format=ids) -wp post meta update $post_id _product_image_gallery "$image1,$image2,$image3" +wp post meta update $hoodie_product_id _product_image_gallery "$image1,$image2,$image3" # Create a tag, so we can add tests for tag-related blocks and templates. tag_id=$(wp wc product_tag create --name="Recommended" --slug="recommended" --description="Curated products selected by our experts" --porcelain --user=1) -wp wc product update $post_id --tags="[ { \"id\": $tag_id } ]" --user=1 +wp wc product update $hoodie_product_id --tags="[ { \"id\": $tag_id } ]" --user=1 # This is a non-hacky work around to set up the cross sells product. -product_id=$(wp post list --post_type=product --field=ID --name="Cap" --format=ids) -crossell_id=$(wp post list --post_type=product --field=ID --name="Beanie" --format=ids) -wp post meta update $crossell_id _crosssell_ids "$product_id" +cap_product_id=$(wp post list --post_type=product --field=ID --name="Cap" --format=ids) +beanie_product_id=$(wp post list --post_type=product --field=ID --name="Beanie" --format=ids) +wp post meta update $beanie_product_id _crosssell_ids "$cap_product_id" + +# Set a product out of stock +tshirt_with_logo_product_id=$(wp post list --post_type=product --field=ID --name="T-Shirt with Logo" --format=ids) +wp wc product update $tshirt_with_logo_product_id --in_stock=false --user=1 # Enable attribute archives. attribute_ids=$(wp wc product_attribute list --fields=id --format=ids --user=1) diff --git a/plugins/woocommerce-blocks/tests/e2e/tests/product-collection/product-collection.block_theme.spec.ts b/plugins/woocommerce-blocks/tests/e2e/tests/product-collection/product-collection.block_theme.spec.ts index fd438c77712..5b3f6ce2ac6 100644 --- a/plugins/woocommerce-blocks/tests/e2e/tests/product-collection/product-collection.block_theme.spec.ts +++ b/plugins/woocommerce-blocks/tests/e2e/tests/product-collection/product-collection.block_theme.spec.ts @@ -186,6 +186,20 @@ test.describe( 'Product Collection', () => { ); } ); + test( 'Products can be filtered based on tags.', async ( { + pageObject, + } ) => { + const filterName = 'Product tags'; + await pageObject.addFilter( 'Show Taxonomies' ); + await pageObject.setFilterComboboxValue( filterName, [ + 'Recommended', + ] ); + await expect( pageObject.productTitles ).toHaveText( [ 'Hoodie' ] ); + + await pageObject.publishAndGoToFrontend(); + await expect( pageObject.productTitles ).toHaveText( [ 'Hoodie' ] ); + } ); + test( 'Products can be filtered based on product attributes like color, size etc.', async ( { pageObject, } ) => { @@ -203,20 +217,22 @@ test.describe( 'Product Collection', () => { await expect( pageObject.products ).toHaveCount( 1 ); } ); - // TODO There are no products with stock status 'Out of stock' in test data. - // eslint-disable-next-line playwright/no-skipped-test - test.skip( 'Products can be filtered based on stock status (in stock, out of stock, or backorder).', async ( { + test( 'Products can be filtered based on stock status (in stock, out of stock, or backorder).', async ( { pageObject, } ) => { await pageObject.setFilterComboboxValue( 'Stock status', [ 'Out of stock', ] ); - await expect( pageObject.products ).toHaveCount( 1 ); + await expect( pageObject.productTitles ).toHaveText( [ + 'T-Shirt with Logo', + ] ); await pageObject.publishAndGoToFrontend(); - await expect( pageObject.products ).toHaveCount( 1 ); + await expect( pageObject.productTitles ).toHaveText( [ + 'T-Shirt with Logo', + ] ); } ); test.describe( 'Inherit query from template', () => { diff --git a/plugins/woocommerce/changelog/42284-product-collection-add-e2e-tests-which-require-fixture-data b/plugins/woocommerce/changelog/42284-product-collection-add-e2e-tests-which-require-fixture-data new file mode 100644 index 00000000000..0bf341904ca --- /dev/null +++ b/plugins/woocommerce/changelog/42284-product-collection-add-e2e-tests-which-require-fixture-data @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +Product Collection: Add E2E tests for Editor filters: by tag and by stock status