Add E2E tests for grouped products (#45964)

* Add E2E tests for grouped products

* Add check

* Add changelog

* Fix tests

* Remove comment
This commit is contained in:
Fernando Marichal 2024-03-27 11:40:31 -03:00 committed by GitHub
parent 3cfd3893b4
commit df90c91f08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 163 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Add E2E tests for grouped products #45964

View File

@ -0,0 +1,159 @@
const { test } = require( '../../../../fixtures/block-editor-fixtures' );
const { expect } = require( '@playwright/test' );
const { clickOnTab } = require( '../../../../utils/simple-products' );
const { api } = require( '../../../../utils' );
const NEW_EDITOR_ADD_PRODUCT_URL =
'wp-admin/admin.php?page=wc-admin&path=%2Fadd-product';
const isTrackingSupposedToBeEnabled = !! process.env.ENABLE_TRACKING;
const productData = {
name: `Grouped product Name ${ new Date().getTime().toString() }`,
summary: 'This is a product summary',
};
const groupedProductsData = [
{
name: `Product name 1 ${ new Date().getTime().toString() }`,
productPrice: '400',
type: 'simple',
},
{
name: `Product name 2 ${ new Date().getTime().toString() }`,
productPrice: '600',
type: 'simple',
},
];
const productIds = [];
test.describe( 'General tab', () => {
test.describe( 'Grouped product', () => {
test.beforeAll( async () => {
for ( const product of groupedProductsData ) {
const id = await api.create.product( product );
productIds.push( id );
}
} );
test.afterAll( async () => {
for ( const productId of productIds ) {
await api.deletePost.product( productId );
}
} );
test.skip(
isTrackingSupposedToBeEnabled,
'The block product editor is not being tested'
);
test( 'can create a grouped product', async ( { page } ) => {
await page.goto( NEW_EDITOR_ADD_PRODUCT_URL );
await clickOnTab( 'General', page );
await page
.getByPlaceholder( 'e.g. 12 oz Coffee Mug' )
.fill( productData.name );
await page
.locator(
'[data-template-block-id="basic-details"] .components-summary-control'
)
.last()
.fill( productData.summary );
await page
.getByRole( 'button', {
name: 'Change product type',
} )
.click();
await page
.locator( '.components-dropdown__content' )
.getByText( 'Grouped product' )
.click();
await page.waitForResponse(
( response ) =>
response.url().includes( '/wp-json/wc/v3/products/' ) &&
response.status() === 200
);
await page
.locator( '[data-title="Product section"]' )
.getByText( 'Add products' )
.click();
await page
.getByRole( 'heading', {
name: 'Add products to this group',
} )
.isVisible();
for ( const product of groupedProductsData ) {
await page
.locator(
'.woocommerce-add-products-modal__form-group-content'
)
.getByPlaceholder( 'Search for products' )
.fill( product.name );
await page.getByText( product.name ).click();
}
await page
.locator( '.woocommerce-add-products-modal__actions' )
.getByRole( 'button', {
name: 'Add',
} )
.click();
await page
.locator( '.woocommerce-product-header__actions' )
.getByRole( 'button', {
name: 'Publish',
} )
.click();
await page
.locator( '.woocommerce-product-publish-panel__header' )
.getByRole( 'button', {
name: 'Publish',
} )
.click();
const element = page.locator( 'div.components-snackbar__content' );
const textContent = await element.innerText();
await expect( textContent ).toMatch( 'Product type changed.' );
await page.waitForResponse(
( response ) =>
response.url().includes( '/wp-json/wc/v3/products/' ) &&
response.status() === 200
);
const title = page.locator( '.woocommerce-product-header__title' );
// Save product ID
const productIdRegex = /product%2F(\d+)/;
const url = page.url();
const productIdMatch = productIdRegex.exec( url );
const productId = productIdMatch ? productIdMatch[ 1 ] : null;
await expect( productId ).toBeDefined();
await expect( title ).toHaveText( productData.name );
await page.goto( `/?post_type=product&p=${ productId }` );
await expect(
page.getByRole( 'heading', { name: productData.name } )
).toBeVisible();
for ( const product of groupedProductsData ) {
await expect(
page.getByRole( 'link', { name: product.name } ).first()
).toBeVisible();
}
} );
} );
} );