Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Product Gallery: Add e2e tests for crop image option (#11559)
Browse files Browse the repository at this point in the history
  • Loading branch information
roykho authored Nov 6, 2023
1 parent 45f2045 commit 0bd57df
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
1 change: 1 addition & 0 deletions assets/js/blocks/product-gallery/block-settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const ProductGalleryBlockSettings = ( {
cropImages: ! cropImages,
} )
}
className="wc-block-product-gallery__crop-images"
/>
<ToggleControl
label={ __(
Expand Down
4 changes: 2 additions & 2 deletions src/Utils/ProductGalleryUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ public static function maybe_generate_intermediate_image( $attachment_id, $size
$image_path = wp_get_original_image_path( $attachment_id );
$image_metadata = wp_get_attachment_metadata( $attachment_id );

// If image doesn't exist, we can't generate the intermediate size. Bail.
if ( ! isset( $image_metadata['path'] ) ) {
// If image sizes are not available. Bail.
if ( ! isset( $image_metadata['width'], $image_metadata['height'] ) ) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ const blockData = {
name: 'woocommerce/product-gallery',
selectors: {
frontend: {},
editor: {},
editor: {
settings: {
cropImagesOption:
'.wc-block-product-gallery__crop-images .components-form-toggle__input',
},
},
},
slug: 'single-product',
productPage: '/product/logo-collection/',
Expand Down Expand Up @@ -234,4 +239,45 @@ test.describe( `${ blockData.name }`, () => {
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();
} );
} );

0 comments on commit 0bd57df

Please sign in to comment.