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
await addAProductToCart( page, productId );
await addAProductToCart( page, productId2 );
await addAProductToCart( page, productId2 );
await addAProductToCart( page, productId2, 2 );
} );
test.afterAll( async ( { baseURL } ) => {

View File

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

View File

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

View File

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