From 0bd57dfdec5b14ffd2f5ecc65c6259095506031c Mon Sep 17 00:00:00 2001 From: Roy Ho Date: Mon, 6 Nov 2023 07:17:25 -0800 Subject: [PATCH] Product Gallery: Add e2e tests for crop image option (#11559) --- .../product-gallery/block-settings/index.tsx | 1 + src/Utils/ProductGalleryUtils.php | 4 +- ...t-gallery.block_theme.side_effects.spec.ts | 48 ++++++++++++++++++- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/assets/js/blocks/product-gallery/block-settings/index.tsx b/assets/js/blocks/product-gallery/block-settings/index.tsx index cea7839f110..d396fc2da45 100644 --- a/assets/js/blocks/product-gallery/block-settings/index.tsx +++ b/assets/js/blocks/product-gallery/block-settings/index.tsx @@ -69,6 +69,7 @@ export const ProductGalleryBlockSettings = ( { cropImages: ! cropImages, } ) } + className="wc-block-product-gallery__crop-images" /> { await expect( page.locator( 'dialog' ) ).toBeHidden(); } ); } ); + + test( 'should show (square) cropped main product images when crop option is enabled', async ( { + page, + editorUtils, + pageObject, + } ) => { + await pageObject.addProductGalleryBlock( { cleanContent: true } ); + + const block = await pageObject.getMainImageBlock( { + page: 'editor', + } ); + + await expect( block ).toBeVisible(); + + await page + .locator( blockData.selectors.editor.settings.cropImagesOption ) + .click(); + + await editorUtils.saveTemplate(); + + await expect( + page.locator( blockData.selectors.editor.settings.cropImagesOption ) + ).toBeChecked(); + + await page.goto( blockData.productPage, { + waitUntil: 'commit', + } ); + + const image = await page + .locator( + 'img.wc-block-woocommerce-product-gallery-large-image__image' + ) + .first() + .boundingBox(); + + const height = image?.height; + const width = image?.width; + + // Allow 1 pixel of difference. + expect( width === height + 1 || width === height - 1 ).toBeTruthy(); + } ); } );