Skip to content

Commit

Permalink
Add e2e tests for password-protected Single Product block template (#…
Browse files Browse the repository at this point in the history
…44304)

* Add e2e tests for password-protected Single Product block template

* Add changefile(s) from automation for the following project(s): woocommerce-blocks

* Fix tests

---------

Co-authored-by: github-actions <github-actions@github.com>
  • Loading branch information
2 people authored and samueljseay committed Feb 6, 2024
1 parent 030e028 commit 6b9b659
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
5 changes: 5 additions & 0 deletions plugins/woocommerce-blocks/tests/e2e/bin/scripts/products.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ wp post meta update $beanie_product_id _crosssell_ids "$cap_product_id"
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

# Make a product visible only with password.
sunglasses_product_id=$(wp post list --post_type=product --field=ID --name="Sunglasses" --format=ids)
wp post update $sunglasses_product_id --post_password="password" --user=1


# Enable attribute archives.
attribute_ids=$(wp wc product_attribute list --fields=id --format=ids --user=1)
if [ -n "$attribute_ids" ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ test.describe( 'Product Collection', () => {

await pageObject.publishAndGoToFrontend();

const frontendTitles =
await pageObject.productTitles.allInnerTexts();
expect(
await pageObject.productTitles.allInnerTexts()
frontendTitles.map( ( title ) =>
title.replace( 'Protected: ', '' )
)
).toStrictEqual( expectedTitles );
} );

Expand Down Expand Up @@ -181,8 +185,16 @@ test.describe( 'Product Collection', () => {
);

await pageObject.publishAndGoToFrontend();

const frontendAccessoriesProductNames = [
'Beanie',
'Beanie with Logo',
'Belt',
'Cap',
'Protected: Sunglasses',
];
await expect( pageObject.productTitles ).toHaveText(
accessoriesProductNames
frontendAccessoriesProductNames
);
} );

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* External dependencies
*/
import { test, expect } from '@woocommerce/e2e-playwright-utils';

// Sunglasses are defined as requering password in /bin/scripts/products.sh.
const productWithPasswordPermalink = '/product/sunglasses/';

test.describe( 'Single Product template', async () => {
test( 'shows password form in products protected with password', async ( {
page,
} ) => {
await page.goto( productWithPasswordPermalink );
await expect(
page.getByText( 'This content is password protected.' ).first()
).toBeVisible();
} );
} );
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: add
Comment: Add e2e tests for password-protected Single Product block template

0 comments on commit 6b9b659

Please sign in to comment.