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

Commit

Permalink
Refactor E2E price filter tests and update test scripts in global-setup
Browse files Browse the repository at this point in the history
Here are the key changes:
1. Refactored the way the 'wp action-scheduler run' command is run in the 'global-setup.ts' script. Now, it correctly separates the wp command from the arguments passed to it.
2. Consolidated the 'price-filter-with-all-products.block_theme.side_effects.spec.ts' and 'price-filter-with-classic-template.block_theme.side_effects.spec.ts' tests into a single 'price-filter.block_theme.side_effects.spec.ts' file. The new file contains tests for both scenarios: with all products block and with PHP classic template. Also, updated the product locator function to distinguish between classic templates and products beta block.
3. Deleted the original 'price-filter-with-all-products.block_theme.side_effects.spec.ts' and 'price-filter-with-classic-template.block_theme.side_effects.spec.ts' test files as they are no longer needed.
4. Updated the 'price-filter.page.ts' file to remove the 'waitForLoadState' method call after inserting the block in the editor and added logic to handle locating products in different scenarios (classic template vs products beta block).
  • Loading branch information
imanish003 committed Jul 3, 2023
1 parent 8c3efcb commit de415ce
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 124 deletions.
4 changes: 2 additions & 2 deletions tests/e2e-pw/global-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ const prepareAttributes = async ( config: FullConfig ) => {
* we need to process more than 1 batch of items.
*/
await cli(
`npm run wp-env run tests-cli wp action-scheduler run --hooks="woocommerce_run_product_attribute_lookup_regeneration_callback"`
`npm run wp-env run tests-cli -- wp action-scheduler run --hooks="woocommerce_run_product_attribute_lookup_regeneration_callback"`
);

await cli(
`npm run wp-env run tests-cli wp action-scheduler run --hooks="woocommerce_run_product_attribute_lookup_regeneration_callback"`
`npm run wp-env run tests-cli -- wp action-scheduler run --hooks="woocommerce_run_product_attribute_lookup_regeneration_callback"`
);
};

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* External dependencies
*/
import { test as base, expect } from '@woocommerce/e2e-playwright-utils';
import { cli } from '@woocommerce/e2e-utils';

/**
* Internal dependencies
*/
import PriceFilterPage, { blockData } from './price-filter.page';

const test = base.extend< { pageObject: PriceFilterPage } >( {
pageObject: async ( { page, admin, editor, templateApiUtils }, use ) => {
const pageObject = new PriceFilterPage( {
page,
editor,
admin,
templateApiUtils,
} );
await use( pageObject );
},
} );
/**
* It's taking lot of time to load Product catalog template page on slow machines.
* Therefore, increasing the timeout to 3 minutes.
*/
test.setTimeout( 3 * 60 * 1000 );

test.describe( `${ blockData.name } Block - with All products Block`, () => {
test( 'should show all products', async ( { pageObject } ) => {
await pageObject.addPriceFilterBlockToNewPostAndGoToFrontend();

const firstProductImage = await pageObject.locateFirstImage();
await expect( firstProductImage ).not.toHaveAttribute(
'src',
blockData.placeholderUrl
);

const allProductsBlock = await pageObject.locateAllProductsBlock();
const products = await allProductsBlock.getByRole( 'listitem' ).all();
expect( products ).toHaveLength( 9 );
} );

test( 'should show only products that match the filter', async ( {
pageObject,
} ) => {
await pageObject.addPriceFilterBlockToNewPostAndGoToFrontend();
await pageObject.setPriceFilterRange( 2, 3 );

const firstProductImage = await pageObject.locateFirstImage();
await expect( firstProductImage ).not.toHaveAttribute(
'src',
blockData.placeholderUrl
);

const allProductsBlock = await pageObject.locateAllProductsBlock();
const products = await allProductsBlock.getByRole( 'listitem' ).all();
expect( products ).toHaveLength( 1 );
} );
} );

test.describe( `${ blockData.name } Block - with PHP classic template`, () => {
test.beforeAll( async () => {
await cli(
'npm run wp-env run tests-cli -- wp option update wc_blocks_use_blockified_product_grid_block_as_template false'
);
} );

test.beforeEach( async ( { pageObject } ) => {
await pageObject.revertArchiveProductTemplate();
} );

test.afterEach( async ( { pageObject } ) => {
await pageObject.revertArchiveProductTemplate();
} );

test( 'should show all products', async ( { pageObject } ) => {
await pageObject.addPriceFilterBlockToProductCatalogAndGoToShop();

const products = await pageObject.locateAllProducts( {
isClassicTemplate: true,
} );
expect( products ).toHaveCount( 16 );
} );

test( 'should show only products that match the filter', async ( {
pageObject,
} ) => {
await pageObject.addPriceFilterBlockToProductCatalogAndGoToShop();
await pageObject.setPriceFilterRange( 2, 3 );

const products = await pageObject.locateAllProducts( {
isClassicTemplate: true,
} );
expect( products ).toHaveCount( 1 );
} );

test.afterAll( async () => {
await cli(
'npm run wp-env run tests-cli -- wp option update wc_blocks_use_blockified_product_grid_block_as_template true'
);
} );
} );
17 changes: 12 additions & 5 deletions tests/e2e-pw/tests/price-filter/price-filter.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ class PriceFilterPage {
},
} );

await this.page.waitForLoadState( 'networkidle' );

await this.editor.saveSiteEditorEntities();
await this.page.goto( `/shop`, { waitUntil: 'networkidle' } );
}
Expand Down Expand Up @@ -147,11 +145,20 @@ class PriceFilterPage {
} );
}

async locateAllProducts() {
const products = await this.page.locator(
async locateAllProducts(
{ isClassicTemplate } = {
isClassicTemplate: false,
}
) {
if ( isClassicTemplate ) {
return await this.page.locator( '.products .product' );
}

// If it's not a classic template, then it's products beta block.
// TODO Soon products beta block will be replaced by Product Collection block. Update this accordingly.
return await this.page.locator(
'.products-block-post-template .product'
);
return products;
}

/**
Expand Down

0 comments on commit de415ce

Please sign in to comment.