Improve cart util and update relevant e2e tests (#48475)

* Improve cart util and update relevant tests

* Add changelog

* Remove focused test
This commit is contained in:
Veljko V 2024-06-13 21:47:45 +02:00 committed by GitHub
parent 29ee0ab6cf
commit a7fc9afa8e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 26 additions and 23 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev
E2E tests: improving cart util and updating relevant tests

View File

@ -293,8 +293,7 @@ test.describe( 'Shopper Cart & Checkout Block Tax Rounding', () => {
// all tests use the same products // all tests use the same products
await addAProductToCart( page, productId ); await addAProductToCart( page, productId );
await addAProductToCart( page, productId2 ); await addAProductToCart( page, productId2, 2 );
await addAProductToCart( page, productId2 );
} ); } );
test.afterAll( async ( { baseURL } ) => { test.afterAll( async ( { baseURL } ) => {

View File

@ -235,9 +235,8 @@ test.describe( 'Cart & Checkout Restricted Coupons', () => {
).toBeVisible(); ).toBeVisible();
// add a couple more in order to hit minimum spend // add a couple more in order to hit minimum spend
for ( let i = 0; i < 2; i++ ) { await addAProductToCart( page, firstProductId, 2 );
await addAProductToCart( page, firstProductId );
}
// passed because we're between 50 and 200 dollars // passed because we're between 50 and 200 dollars
await page.goto( '/cart/' ); await page.goto( '/cart/' );
await page await page
@ -280,9 +279,8 @@ test.describe( 'Cart & Checkout Restricted Coupons', () => {
).toBeVisible(); ).toBeVisible();
// add a couple more in order to hit minimum spend // add a couple more in order to hit minimum spend
for ( let i = 0; i < 2; i++ ) { await addAProductToCart( page, firstProductId, 2 );
await addAProductToCart( page, firstProductId );
}
// passed because we're between 50 and 200 dollars // passed because we're between 50 and 200 dollars
await page.goto( '/checkout/' ); await page.goto( '/checkout/' );
await page await page

View File

@ -57,6 +57,10 @@ test.describe( 'Checkout Block page', () => {
consumerSecret: process.env.CONSUMER_SECRET, consumerSecret: process.env.CONSUMER_SECRET,
version: 'wc/v3', version: 'wc/v3',
} ); } );
// make sure the currency is USD
await api.put( 'settings/general/woocommerce_currency', {
value: 'USD',
} );
// add product // add product
await api await api
.post( 'products', { .post( 'products', {
@ -287,8 +291,7 @@ test.describe( 'Checkout Block page', () => {
testPage, testPage,
} ) => { } ) => {
// this time we're going to add two products to the cart // this time we're going to add two products to the cart
await addAProductToCart( page, productId ); await addAProductToCart( page, productId, 2 );
await addAProductToCart( page, productId );
await page.goto( testPage.slug ); await page.goto( testPage.slug );
await expect( await expect(
@ -325,9 +328,7 @@ test.describe( 'Checkout Block page', () => {
testPage, testPage,
} ) => { } ) => {
// this time we're going to add three products to the cart // this time we're going to add three products to the cart
await addAProductToCart( page, productId ); await addAProductToCart( page, productId, 3 );
await addAProductToCart( page, productId );
await addAProductToCart( page, productId );
await page.goto( testPage.slug ); await page.goto( testPage.slug );
await expect( await expect(
@ -601,8 +602,7 @@ test.describe( 'Checkout Block page', () => {
testPage, testPage,
} ) => { } ) => {
// adding 2 products to the cart // adding 2 products to the cart
await addAProductToCart( page, productId ); await addAProductToCart( page, productId, 2 );
await addAProductToCart( page, productId );
await page.goto( testPage.slug ); await page.goto( testPage.slug );
await expect( await expect(
@ -727,8 +727,7 @@ test.describe( 'Checkout Block page', () => {
page, page,
testPage, testPage,
} ) => { } ) => {
await addAProductToCart( page, productId ); await addAProductToCart( page, productId, 2 );
await addAProductToCart( page, productId );
await page.goto( testPage.slug ); await page.goto( testPage.slug );
await expect( await expect(

View File

@ -1,9 +1,12 @@
const addAProductToCart = async ( page, productId ) => { const addAProductToCart = async ( page, productId, quantity = 1 ) => {
const responsePromise = page.waitForResponse( for ( let i = 0; i < quantity; i++ ) {
'**/wp-json/wc/store/v1/cart?**' const responsePromise = page.waitForResponse(
); '**/wp-json/wc/store/v1/cart?**'
await page.goto( `/shop/?add-to-cart=${ productId }` ); );
await responsePromise; await page.goto( `/shop/?add-to-cart=${ productId }` );
await responsePromise;
await page.getByRole( 'alert' ).waitFor( { state: 'visible' } );
}
}; };
module.exports = { module.exports = {