Blocks E2E: Refactor Product Collection vs classic template test for stability (#49638)
This commit is contained in:
parent
7f797c041c
commit
720c1de6bf
|
@ -28,7 +28,6 @@ test.describe( 'Product Collection', () => {
|
||||||
pageObject,
|
pageObject,
|
||||||
} ) => {
|
} ) => {
|
||||||
await pageObject.createNewPostAndInsertBlock();
|
await pageObject.createNewPostAndInsertBlock();
|
||||||
expect( pageObject.productTemplate ).not.toBeNull();
|
|
||||||
await expect( pageObject.products ).toHaveCount( 9 );
|
await expect( pageObject.products ).toHaveCount( 9 );
|
||||||
await expect( pageObject.productImages ).toHaveCount( 9 );
|
await expect( pageObject.productImages ).toHaveCount( 9 );
|
||||||
await expect( pageObject.productTitles ).toHaveCount( 9 );
|
await expect( pageObject.productTitles ).toHaveCount( 9 );
|
||||||
|
@ -37,7 +36,6 @@ test.describe( 'Product Collection', () => {
|
||||||
|
|
||||||
await pageObject.publishAndGoToFrontend();
|
await pageObject.publishAndGoToFrontend();
|
||||||
|
|
||||||
expect( pageObject.productTemplate ).not.toBeNull();
|
|
||||||
await expect( pageObject.products ).toHaveCount( 9 );
|
await expect( pageObject.products ).toHaveCount( 9 );
|
||||||
await expect( pageObject.productImages ).toHaveCount( 9 );
|
await expect( pageObject.productImages ).toHaveCount( 9 );
|
||||||
await expect( pageObject.productTitles ).toHaveCount( 9 );
|
await expect( pageObject.productTitles ).toHaveCount( 9 );
|
||||||
|
@ -46,44 +44,6 @@ test.describe( 'Product Collection', () => {
|
||||||
} );
|
} );
|
||||||
|
|
||||||
test.describe( 'Renders correctly with all Product Elements', () => {
|
test.describe( 'Renders correctly with all Product Elements', () => {
|
||||||
const insertProductElements = async (
|
|
||||||
pageObject: ProductCollectionPage
|
|
||||||
) => {
|
|
||||||
// By default there are inner blocks:
|
|
||||||
// - woocommerce/product-image
|
|
||||||
// - core/post-title
|
|
||||||
// - woocommerce/product-price
|
|
||||||
// - woocommerce/product-button
|
|
||||||
// We're adding remaining ones
|
|
||||||
const productElements = [
|
|
||||||
{ name: 'woocommerce/product-rating', attributes: {} },
|
|
||||||
{ name: 'woocommerce/product-sku', attributes: {} },
|
|
||||||
{ name: 'woocommerce/product-stock-indicator', attributes: {} },
|
|
||||||
{ name: 'woocommerce/product-sale-badge', attributes: {} },
|
|
||||||
{
|
|
||||||
name: 'core/post-excerpt',
|
|
||||||
attributes: {
|
|
||||||
__woocommerceNamespace:
|
|
||||||
'woocommerce/product-collection/product-summary',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'core/post-terms',
|
|
||||||
attributes: { term: 'product_tag' },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'core/post-terms',
|
|
||||||
attributes: { term: 'product_cat' },
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
for ( const productElement of productElements ) {
|
|
||||||
await pageObject.insertBlockInProductCollection(
|
|
||||||
productElement
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const expectedProductContent = [
|
const expectedProductContent = [
|
||||||
'Beanie', // core/post-title
|
'Beanie', // core/post-title
|
||||||
'$20.00 Original price was: $20.00.$18.00Current price is: $18.00.', // woocommerce/product-price
|
'$20.00 Original price was: $20.00.$18.00Current price is: $18.00.', // woocommerce/product-price
|
||||||
|
@ -103,7 +63,7 @@ test.describe( 'Product Collection', () => {
|
||||||
page.locator( '[data-testid="product-image"]:visible' )
|
page.locator( '[data-testid="product-image"]:visible' )
|
||||||
).toHaveCount( 9 );
|
).toHaveCount( 9 );
|
||||||
|
|
||||||
await insertProductElements( pageObject );
|
await pageObject.insertProductElements();
|
||||||
await pageObject.publishAndGoToFrontend();
|
await pageObject.publishAndGoToFrontend();
|
||||||
|
|
||||||
for ( const content of expectedProductContent ) {
|
for ( const content of expectedProductContent ) {
|
||||||
|
@ -124,7 +84,7 @@ test.describe( 'Product Collection', () => {
|
||||||
editor.canvas.locator( '[data-testid="product-image"]:visible' )
|
editor.canvas.locator( '[data-testid="product-image"]:visible' )
|
||||||
).toHaveCount( 16 );
|
).toHaveCount( 16 );
|
||||||
|
|
||||||
await insertProductElements( pageObject );
|
await pageObject.insertProductElements();
|
||||||
await editor.saveSiteEditorEntities( {
|
await editor.saveSiteEditorEntities( {
|
||||||
isOnlyCurrentEntityDirty: true,
|
isOnlyCurrentEntityDirty: true,
|
||||||
} );
|
} );
|
||||||
|
@ -152,7 +112,7 @@ test.describe( 'Product Collection', () => {
|
||||||
editor.canvas.locator( '[data-testid="product-image"]:visible' )
|
editor.canvas.locator( '[data-testid="product-image"]:visible' )
|
||||||
).toHaveCount( 9 );
|
).toHaveCount( 9 );
|
||||||
|
|
||||||
await insertProductElements( pageObject );
|
await pageObject.insertProductElements();
|
||||||
await editor.saveSiteEditorEntities( {
|
await editor.saveSiteEditorEntities( {
|
||||||
isOnlyCurrentEntityDirty: true,
|
isOnlyCurrentEntityDirty: true,
|
||||||
} );
|
} );
|
||||||
|
@ -1350,39 +1310,59 @@ test.describe( 'Product Collection', () => {
|
||||||
test.describe( `${ templateTitle } template`, () => {
|
test.describe( `${ templateTitle } template`, () => {
|
||||||
test( 'Product Collection block matches with classic template block', async ( {
|
test( 'Product Collection block matches with classic template block', async ( {
|
||||||
pageObject,
|
pageObject,
|
||||||
|
requestUtils,
|
||||||
admin,
|
admin,
|
||||||
editor,
|
editor,
|
||||||
page,
|
page,
|
||||||
} ) => {
|
} ) => {
|
||||||
const getProductNamesFromClassicTemplate = async () => {
|
await pageObject.refreshLocators( 'frontend' );
|
||||||
const products = page.locator(
|
|
||||||
'.woocommerce-loop-product__title'
|
await page.goto( frontendPage );
|
||||||
);
|
|
||||||
await expect( products ).toHaveCount(
|
const productCollectionProductNames =
|
||||||
expectedProductsCount
|
await pageObject.getProductNames();
|
||||||
);
|
|
||||||
return products.allTextContents();
|
const template = await requestUtils.createTemplate(
|
||||||
};
|
'wp_template',
|
||||||
|
{
|
||||||
|
slug,
|
||||||
|
title: 'classic template test',
|
||||||
|
content: 'howdy',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
await admin.visitSiteEditor( {
|
await admin.visitSiteEditor( {
|
||||||
postId: `woocommerce/woocommerce//${ slug }`,
|
postId: template.id,
|
||||||
postType: 'wp_template',
|
postType: 'wp_template',
|
||||||
canvas: 'edit',
|
canvas: 'edit',
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
editor.canvas.getByText( 'howdy' )
|
||||||
|
).toBeVisible();
|
||||||
|
|
||||||
await editor.insertBlock( { name: legacyBlockName } );
|
await editor.insertBlock( { name: legacyBlockName } );
|
||||||
|
|
||||||
await editor.saveSiteEditorEntities( {
|
await editor.saveSiteEditorEntities( {
|
||||||
isOnlyCurrentEntityDirty: true,
|
isOnlyCurrentEntityDirty: true,
|
||||||
} );
|
} );
|
||||||
|
|
||||||
await page.goto( frontendPage );
|
await page.goto( frontendPage );
|
||||||
await pageObject.refreshLocators( 'frontend' );
|
|
||||||
|
|
||||||
const classicProducts =
|
const classicProducts = page.locator(
|
||||||
await getProductNamesFromClassicTemplate();
|
'.woocommerce-loop-product__title'
|
||||||
const productCollectionProducts =
|
);
|
||||||
await pageObject.getProductNames();
|
|
||||||
|
|
||||||
expect( classicProducts ).toEqual( productCollectionProducts );
|
await expect( classicProducts ).toHaveCount(
|
||||||
|
expectedProductsCount
|
||||||
|
);
|
||||||
|
|
||||||
|
const classicProductsNames =
|
||||||
|
await classicProducts.allTextContents();
|
||||||
|
|
||||||
|
expect( classicProductsNames ).toEqual(
|
||||||
|
productCollectionProductNames
|
||||||
|
);
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
@ -1460,7 +1440,7 @@ test.describe( 'Testing registerProductCollection', () => {
|
||||||
await pageObject.createNewPostAndInsertBlock(
|
await pageObject.createNewPostAndInsertBlock(
|
||||||
'myCustomCollection'
|
'myCustomCollection'
|
||||||
);
|
);
|
||||||
expect( pageObject.productTemplate ).not.toBeNull();
|
|
||||||
await expect( pageObject.products ).toHaveCount( 5 );
|
await expect( pageObject.products ).toHaveCount( 5 );
|
||||||
await expect( pageObject.productImages ).toHaveCount( 5 );
|
await expect( pageObject.productImages ).toHaveCount( 5 );
|
||||||
await expect( pageObject.productTitles ).toHaveCount( 5 );
|
await expect( pageObject.productTitles ).toHaveCount( 5 );
|
||||||
|
@ -1497,7 +1477,7 @@ test.describe( 'Testing registerProductCollection', () => {
|
||||||
await pageObject.createNewPostAndInsertBlock(
|
await pageObject.createNewPostAndInsertBlock(
|
||||||
'myCustomCollectionWithPreview'
|
'myCustomCollectionWithPreview'
|
||||||
);
|
);
|
||||||
expect( pageObject.productTemplate ).not.toBeNull();
|
|
||||||
await expect( pageObject.products ).toHaveCount( 9 );
|
await expect( pageObject.products ).toHaveCount( 9 );
|
||||||
await expect( pageObject.productImages ).toHaveCount( 9 );
|
await expect( pageObject.productImages ).toHaveCount( 9 );
|
||||||
await expect( pageObject.productTitles ).toHaveCount( 9 );
|
await expect( pageObject.productTitles ).toHaveCount( 9 );
|
||||||
|
@ -1556,7 +1536,7 @@ test.describe( 'Testing registerProductCollection', () => {
|
||||||
await pageObject.createNewPostAndInsertBlock(
|
await pageObject.createNewPostAndInsertBlock(
|
||||||
'myCustomCollectionWithAdvancedPreview'
|
'myCustomCollectionWithAdvancedPreview'
|
||||||
);
|
);
|
||||||
expect( pageObject.productTemplate ).not.toBeNull();
|
|
||||||
await expect( pageObject.products ).toHaveCount( 9 );
|
await expect( pageObject.products ).toHaveCount( 9 );
|
||||||
await expect( pageObject.productImages ).toHaveCount( 9 );
|
await expect( pageObject.productImages ).toHaveCount( 9 );
|
||||||
await expect( pageObject.productTitles ).toHaveCount( 9 );
|
await expect( pageObject.productTitles ).toHaveCount( 9 );
|
||||||
|
|
|
@ -220,6 +220,39 @@ class ProductCollectionPage {
|
||||||
|
|
||||||
return new URL( productResponse.url() );
|
return new URL( productResponse.url() );
|
||||||
}
|
}
|
||||||
|
async insertProductElements() {
|
||||||
|
// By default there are inner blocks:
|
||||||
|
// - woocommerce/product-image
|
||||||
|
// - core/post-title
|
||||||
|
// - woocommerce/product-price
|
||||||
|
// - woocommerce/product-button
|
||||||
|
// We're adding remaining ones
|
||||||
|
const productElements = [
|
||||||
|
{ name: 'woocommerce/product-rating', attributes: {} },
|
||||||
|
{ name: 'woocommerce/product-sku', attributes: {} },
|
||||||
|
{ name: 'woocommerce/product-stock-indicator', attributes: {} },
|
||||||
|
{ name: 'woocommerce/product-sale-badge', attributes: {} },
|
||||||
|
{
|
||||||
|
name: 'core/post-excerpt',
|
||||||
|
attributes: {
|
||||||
|
__woocommerceNamespace:
|
||||||
|
'woocommerce/product-collection/product-summary',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'core/post-terms',
|
||||||
|
attributes: { term: 'product_tag' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'core/post-terms',
|
||||||
|
attributes: { term: 'product_cat' },
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
for ( const productElement of productElements ) {
|
||||||
|
await this.insertBlockInProductCollection( productElement );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async publishAndGoToFrontend() {
|
async publishAndGoToFrontend() {
|
||||||
const postId = await this.editor.publishPost();
|
const postId = await this.editor.publishPost();
|
||||||
|
@ -670,7 +703,7 @@ class ProductCollectionPage {
|
||||||
|
|
||||||
async getProductNames() {
|
async getProductNames() {
|
||||||
const products = this.page.locator( '.wp-block-post-title' );
|
const products = this.page.locator( '.wp-block-post-title' );
|
||||||
return products.allTextContents();
|
return await products.allTextContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: patch
|
||||||
|
Type: dev
|
||||||
|
|
||||||
|
Another attempt to stabilize flaky Product Collection E2E tests.
|
Loading…
Reference in New Issue