Skip to content

Commit

Permalink
[E2E] Stabilize Product Collection "on sale" tests (#44796)
Browse files Browse the repository at this point in the history
  • Loading branch information
WunderBart committed Feb 21, 2024
1 parent 6b9e732 commit 045df6f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@ test.describe( 'Product Collection', () => {
pageObject,
} ) => {
await pageObject.setNumberOfColumns( 2 );
await expect(
await pageObject.productTemplate.getAttribute( 'class' )
).toContain( 'columns-2' );
await expect( pageObject.productTemplate ).toHaveClass(
/columns-2/
);

await pageObject.setNumberOfColumns( 4 );
await expect(
await pageObject.productTemplate.getAttribute( 'class' )
).toContain( 'columns-4' );
await expect( pageObject.productTemplate ).toHaveClass(
/columns-4/
);

await pageObject.publishAndGoToFrontend();

await expect(
await pageObject.productTemplate.getAttribute( 'class' )
).toContain( 'columns-4' );
await expect( pageObject.productTemplate ).toHaveClass(
/columns-4/
);
} );

test( 'Order By - sort products by title in descending order correctly', async ( {
Expand All @@ -93,39 +93,28 @@ test.describe( 'Product Collection', () => {
} );

// Products can be filtered based on 'on sale' status.
test( 'Products can be filtered based on "on sale" status.', async ( {
test( 'Products can be filtered based on "on sale" status', async ( {
pageObject,
} ) => {
// On each page we show 9 products.
await expect( pageObject.products ).toHaveCount( 9 );
// All products should not be on sale.
await expect(
await pageObject.productImages.filter( {
hasText: 'Product on sale',
} )
).not.toHaveCount( 9 );
const allProducts = pageObject.products;
const salePoducts = pageObject.products.filter( {
hasText: 'Product on sale',
} );

await expect( allProducts ).toHaveCount( 9 );
await expect( salePoducts ).toHaveCount( 6 );

await pageObject.setShowOnlyProductsOnSale( {
onSale: true,
} );

// In test data we have only 6 products on sale
await expect( pageObject.products ).toHaveCount( 6 );

// Expect all shown products to be on sale.
await expect(
await pageObject.productImages.filter( {
hasText: 'Product on sale',
} )
).toHaveCount( await pageObject.productImages.count() );
await expect( allProducts ).toHaveCount( 6 );
await expect( salePoducts ).toHaveCount( 6 );

await pageObject.publishAndGoToFrontend();
await expect( pageObject.products ).toHaveCount( 6 );
await expect(
await pageObject.productImages.filter( {
hasText: 'Product on sale',
} )
).toHaveCount( await pageObject.productImages.count() );

await expect( allProducts ).toHaveCount( 6 );
await expect( salePoducts ).toHaveCount( 6 );
} );

test( 'Products can be filtered based on selection in handpicked products option', async ( {
Expand Down Expand Up @@ -449,18 +438,18 @@ test.describe( 'Product Collection', () => {
maxPageToShow: 2,
} );

await expect( await pageObject.products ).toHaveCount( 3 );
await expect( pageObject.products ).toHaveCount( 3 );

await pageObject.setDisplaySettings( {
itemsPerPage: 2,
offset: 0,
maxPageToShow: 2,
} );
await expect( await pageObject.products ).toHaveCount( 2 );
await expect( pageObject.products ).toHaveCount( 2 );

await pageObject.publishAndGoToFrontend();

await expect( await pageObject.products ).toHaveCount( 2 );
await expect( pageObject.products ).toHaveCount( 2 );

const paginationNumbers =
pageObject.pagination.locator( '.page-numbers' );
Expand Down Expand Up @@ -959,13 +948,13 @@ test.describe( 'Product Collection', () => {
collection: 'productCatalog',
} );

await expect(
expect(
url.searchParams.has( 'productCollectionQueryContext[id]' )
).toBeTruthy();

// There shouldn't be collection in the query context
// Because Product Catalog isn't a collection
await expect(
expect(
url.searchParams.has(
'productCollectionQueryContext[collection]'
)
Expand All @@ -982,8 +971,8 @@ test.describe( 'Product Collection', () => {
const collectionName = url.searchParams.get(
'productCollectionQueryContext[collection]'
);
await expect( collectionName ).toBeTruthy();
await expect( collectionName ).toBe(
expect( collectionName ).toBeTruthy();
expect( collectionName ).toBe(
'woocommerce/product-collection/on-sale'
);
} );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Stabilize the 'Products can be filtered based on "on sale" status' E2E test.

0 comments on commit 045df6f

Please sign in to comment.