Consolidate and move password protected product test (#45752)

* Consolidate and move password protected product test

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

* Move test to non side effect and remove remaining empty test file

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Roy Ho 2024-03-21 07:44:30 -07:00 committed by GitHub
parent 40b14aea16
commit 5aac82b0fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 76 deletions

View File

@ -1,59 +0,0 @@
/**
* External dependencies
*/
import { test, expect } from '@woocommerce/e2e-playwright-utils';
import { cli } from '@woocommerce/e2e-utils';
const product = {
name: 'Protected Product',
slug: 'protected-product',
password: 'password',
};
test.describe( 'Single Product Template', () => {
let id: null | string = null;
test.beforeEach( async ( { admin, page } ) => {
await admin.visitAdminPage( `/post-new.php?post_type=product` );
const input = page.locator( '#title' );
await input.fill( product.name );
await page.getByRole( 'button', { name: 'Edit visibility' } ).click();
await page.locator( '#visibility-radio-password' ).click();
await page.locator( '#post_password' ).fill( product.password );
await page.waitForResponse( ( response ) =>
response.url().includes( 'admin-ajax.php' )
);
await page.locator( '#publish.button-primary' ).click();
await page.waitForSelector(
'#woocommerce-product-updated-message-view-product__link'
);
const url = new URL( page.url() );
const queryParams = new URLSearchParams( url.search );
id = queryParams.get( 'post' );
} );
test.afterAll( async () => {
await cli(
`npm run wp-env run tests-cli -- wp post delete ${ id } --force`
);
} );
test.describe( `should render a password input when the product is protected `, () =>
test( 'add product specific classes to the body', async ( {
page,
} ) => {
await page.goto( `/product/${ product.slug }` );
const placeholder = page.getByText(
'This content is password protected. To view it please enter your password below:'
);
await expect( placeholder ).toBeVisible();
await page.getByLabel( 'Password' ).fill( 'password' );
await page.getByRole( 'button', { name: 'Enter' } ).click();
await expect( placeholder ).toBeHidden();
} ) );
} );

View File

@ -54,3 +54,20 @@ for ( const { classes, product, frontendPage } of products ) {
} ); } );
} ) ); } ) );
} }
test( 'shows password form in products protected with password', async ( {
page,
} ) => {
// Sunglasses are defined as requiring password in /bin/scripts/products.sh.
await page.goto( '/product/sunglasses/' );
await expect(
page.getByText( 'This content is password protected.' ).first()
).toBeVisible();
// Verify after introducing the password, the page is visible.
await page.getByLabel( 'Password:' ).fill( 'password' );
await page.getByRole( 'button', { name: 'Enter' } ).click();
await expect(
page.getByRole( 'link', { name: 'Description' } )
).toBeVisible();
} );

View File

@ -8,23 +8,6 @@ test.describe( 'Single Product template', async () => {
await requestUtils.deleteAllTemplates( 'wp_template' ); await requestUtils.deleteAllTemplates( 'wp_template' );
} ); } );
test( 'shows password form in products protected with password', async ( {
page,
} ) => {
// Sunglasses are defined as requiring password in /bin/scripts/products.sh.
await page.goto( '/product/sunglasses/' );
await expect(
page.getByText( 'This content is password protected.' ).first()
).toBeVisible();
// Verify after introducing the password, the page is visible.
await page.getByLabel( 'Password:' ).fill( 'password' );
await page.getByRole( 'button', { name: 'Enter' } ).click();
await expect(
page.getByRole( 'link', { name: 'Description' } )
).toBeVisible();
} );
test( 'loads the Single Product template for a specific product', async ( { test( 'loads the Single Product template for a specific product', async ( {
admin, admin,
editorUtils, editorUtils,

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev
Comment: Consolidates/moves the redundant test for password protected product.