[e2e tests] Tag some e2e tests to help with test audit (#51044)

This commit is contained in:
Adrian Moldovan 2024-09-02 11:09:56 +01:00 committed by GitHub
parent 0f7773dd47
commit 74e96d689b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 684 additions and 603 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev

View File

@ -96,7 +96,7 @@ const test = baseTest.extend( {
}, },
} ); } );
test.describe( 'Restricted coupon management', { tag: '@services' }, () => { test.describe( 'Restricted coupon management', { tag: [ '@services' ] }, () => {
for ( const couponType of Object.keys( couponData ) ) { for ( const couponType of Object.keys( couponData ) ) {
test( `can create new ${ couponType } coupon`, async ( { test( `can create new ${ couponType } coupon`, async ( {
page, page,

View File

@ -130,157 +130,173 @@ test.describe(
} ); } );
} ); } );
test( 'allows customer to calculate Free Shipping in cart block if in Netherlands', async ( { test(
page, 'allows customer to calculate Free Shipping in cart block if in Netherlands',
context, { tag: [ '@could-be-unit-test' ] },
cartBlockPage, async ( { page, context, cartBlockPage } ) => {
} ) => { await context.clearCookies();
await context.clearCookies();
await addAProductToCart( page, product1Id ); await addAProductToCart( page, product1Id );
await page.goto( cartBlockPage.slug ); await page.goto( cartBlockPage.slug );
// Set shipping country to Netherlands // Set shipping country to Netherlands
await page.getByLabel( 'Add an address for shipping' ).click(); await page.getByLabel( 'Add an address for shipping' ).click();
await page await page
.getByRole( 'combobox' ) .getByRole( 'combobox' )
.first() .first()
.selectOption( 'Netherlands' ); .selectOption( 'Netherlands' );
await page.getByLabel( 'Postal code' ).fill( '1011AA' ); await page.getByLabel( 'Postal code' ).fill( '1011AA' );
await page.getByLabel( 'City' ).fill( 'Amsterdam' ); await page.getByLabel( 'City' ).fill( 'Amsterdam' );
await page.getByRole( 'button', { name: 'Update' } ).click(); await page.getByRole( 'button', { name: 'Update' } ).click();
// Verify shipping costs // Verify shipping costs
await expect( await expect(
page.getByRole( 'group' ).getByText( 'Free shipping' ) page.getByRole( 'group' ).getByText( 'Free shipping' )
).toBeVisible(); ).toBeVisible();
await expect( await expect(
page.getByRole( 'strong' ).getByText( 'Free', { exact: true } ) page
).toBeVisible(); .getByRole( 'strong' )
await expect( page.getByText( '$' ).nth( 2 ) ).toContainText( .getByText( 'Free', { exact: true } )
firstProductPrice ).toBeVisible();
); await expect( page.getByText( '$' ).nth( 2 ) ).toContainText(
} ); firstProductPrice
);
}
);
test( 'allows customer to calculate Flat rate and Local pickup in cart block if in Portugal', async ( { test(
page, 'allows customer to calculate Flat rate and Local pickup in cart block if in Portugal',
context, { tag: [ '@could-be-unit-test' ] },
cartBlockPage, async ( { page, context, cartBlockPage } ) => {
} ) => { await context.clearCookies();
await context.clearCookies();
await addAProductToCart( page, product1Id ); await addAProductToCart( page, product1Id );
await page.goto( cartBlockPage.slug ); await page.goto( cartBlockPage.slug );
// Set shipping country to Portugal // Set shipping country to Portugal
await page.getByLabel( 'Add an address for shipping' ).click(); await page.getByLabel( 'Add an address for shipping' ).click();
await page await page
.getByRole( 'combobox' ) .getByRole( 'combobox' )
.first() .first()
.selectOption( 'Portugal' ); .selectOption( 'Portugal' );
await page.getByLabel( 'Postal code' ).fill( '1000-001' ); await page.getByLabel( 'Postal code' ).fill( '1000-001' );
await page.getByLabel( 'City' ).fill( 'Lisbon' ); await page.getByLabel( 'City' ).fill( 'Lisbon' );
await page.getByRole( 'button', { name: 'Update' } ).click(); await page.getByRole( 'button', { name: 'Update' } ).click();
// Verify shipping costs // Verify shipping costs
await expect( await expect(
page.getByRole( 'group' ).getByText( 'Flat rate' ) page.getByRole( 'group' ).getByText( 'Flat rate' )
).toBeVisible(); ).toBeVisible();
await expect( page.getByText( 'Shipping$5.00Flat' ) ).toBeVisible(); await expect(
await expect( page.getByText( 'Shipping$5.00Flat' )
page.getByText( `$${ firstProductWithFlatRate }` ) ).toBeVisible();
).toBeVisible(); await expect(
page.getByText( `$${ firstProductWithFlatRate }` )
).toBeVisible();
// Set shipping to local pickup instead of flat rate // Set shipping to local pickup instead of flat rate
await page.getByRole( 'group' ).getByText( 'Local pickup' ).click(); await page
.getByRole( 'group' )
.getByText( 'Local pickup' )
.click();
// Verify updated shipping costs // Verify updated shipping costs
await expect( page.getByText( 'ShippingFreeLocal' ) ).toBeVisible(); await expect(
await expect( page.getByText( '$' ).nth( 2 ) ).toContainText( page.getByText( 'ShippingFreeLocal' )
firstProductPrice ).toBeVisible();
); await expect( page.getByText( '$' ).nth( 2 ) ).toContainText(
} ); firstProductPrice
);
}
);
test( 'should show correct total cart block price after updating quantity', async ( { test(
page, 'should show correct total cart block price after updating quantity',
context, { tag: [ '@could-be-unit-test' ] },
cartBlockPage, async ( { page, context, cartBlockPage } ) => {
} ) => { await context.clearCookies();
await context.clearCookies();
await addAProductToCart( page, product1Id ); await addAProductToCart( page, product1Id );
await page.goto( cartBlockPage.slug ); await page.goto( cartBlockPage.slug );
// Set shipping country to Portugal // Set shipping country to Portugal
await page.getByLabel( 'Add an address for shipping' ).click(); await page.getByLabel( 'Add an address for shipping' ).click();
await page await page
.getByRole( 'combobox' ) .getByRole( 'combobox' )
.first() .first()
.selectOption( 'Portugal' ); .selectOption( 'Portugal' );
await page.getByLabel( 'Postal code' ).fill( '1000-001' ); await page.getByLabel( 'Postal code' ).fill( '1000-001' );
await page.getByLabel( 'City' ).fill( 'Lisbon' ); await page.getByLabel( 'City' ).fill( 'Lisbon' );
await page.getByRole( 'button', { name: 'Update' } ).click(); await page.getByRole( 'button', { name: 'Update' } ).click();
// Increase product quantity and verify the updated price // Increase product quantity and verify the updated price
await page.getByLabel( 'Increase quantity of First' ).click(); await page.getByLabel( 'Increase quantity of First' ).click();
await expect( await expect(
page.getByText( page.getByText(
`$${ `$${
parseInt( firstProductPrice, 10 ) + parseInt( firstProductPrice, 10 ) +
parseInt( firstProductPrice, 10 ) + parseInt( firstProductPrice, 10 ) +
5 5
}`.toString() }`.toString()
) )
).toBeVisible(); ).toBeVisible();
} ); }
);
test( 'should show correct total cart block price with 2 different products and flat rate/local pickup', async ( { test(
page, 'should show correct total cart block price with 2 different products and flat rate/local pickup',
context, { tag: [ '@could-be-unit-test' ] },
cartBlockPage, async ( { page, context, cartBlockPage } ) => {
} ) => { await context.clearCookies();
await context.clearCookies();
await addAProductToCart( page, product1Id ); await addAProductToCart( page, product1Id );
await addAProductToCart( page, product2Id ); await addAProductToCart( page, product2Id );
await page.goto( cartBlockPage.slug ); await page.goto( cartBlockPage.slug );
// Set shipping country to Portugal // Set shipping country to Portugal
await page.getByLabel( 'Add an address for shipping' ).click(); await page.getByLabel( 'Add an address for shipping' ).click();
await page await page
.getByRole( 'combobox' ) .getByRole( 'combobox' )
.first() .first()
.selectOption( 'Portugal' ); .selectOption( 'Portugal' );
await page.getByLabel( 'Postal code' ).fill( '1000-001' ); await page.getByLabel( 'Postal code' ).fill( '1000-001' );
await page.getByLabel( 'City' ).fill( 'Lisbon' ); await page.getByLabel( 'City' ).fill( 'Lisbon' );
await page.getByRole( 'button', { name: 'Update' } ).click(); await page.getByRole( 'button', { name: 'Update' } ).click();
// Verify shipping costs // Verify shipping costs
await expect( await expect(
page.getByRole( 'group' ).getByText( 'Flat rate' ) page.getByRole( 'group' ).getByText( 'Flat rate' )
).toBeVisible(); ).toBeVisible();
await expect( page.getByText( 'Shipping$5.00Flat' ) ).toBeVisible(); await expect(
await expect( page.getByText( 'Shipping$5.00Flat' )
page.getByText( ).toBeVisible();
`$${ await expect(
parseInt( firstProductPrice, 10 ) + page.getByText(
parseInt( secondProductPrice, 10 ) + `$${
5 parseInt( firstProductPrice, 10 ) +
}`.toString() parseInt( secondProductPrice, 10 ) +
) 5
).toBeVisible(); }`.toString()
)
).toBeVisible();
// Set shipping to local pickup instead of flat rate // Set shipping to local pickup instead of flat rate
await page.getByRole( 'group' ).getByText( 'Local pickup' ).click(); await page
.getByRole( 'group' )
.getByText( 'Local pickup' )
.click();
// Verify updated shipping costs // Verify updated shipping costs
await expect( page.getByText( 'ShippingFreeLocal' ) ).toBeVisible(); await expect(
await expect( page.getByText( 'ShippingFreeLocal' )
page ).toBeVisible();
.locator( 'div' ) await expect(
.filter( { hasText: /^\$30\.00$/ } ) page
.locator( 'span' ) .locator( 'div' )
).toBeVisible(); .filter( { hasText: /^\$30\.00$/ } )
} ); .locator( 'span' )
).toBeVisible();
}
);
} }
); );

View File

@ -127,17 +127,111 @@ test.describe(
} ); } );
} ); } );
test( 'allows cart block to apply coupon of any type', async ( { test(
page, 'allows cart block to apply coupon of any type',
} ) => { { tag: [ '@could-be-unit-test' ] },
const totals = [ '$50.00', '$27.50', '$45.00' ]; async ( { page } ) => {
const totals = [ '$50.00', '$27.50', '$45.00' ];
// apply all coupon types // apply all coupon types
for ( let i = 0; i < coupons.length; i++ ) { for ( let i = 0; i < coupons.length; i++ ) {
await page
.getByRole( 'button', { name: 'Add a coupon' } )
.click();
await page
.getByLabel( 'Enter code' )
.fill( coupons[ i ].code );
await page.getByText( 'Apply', { exact: true } ).click();
await expect(
page
.locator(
'.wc-block-components-notice-banner__content'
)
.getByText(
`Coupon code "${ coupons[ i ].code }" has been applied to your cart.`
)
).toBeVisible();
await expect(
page.locator(
'.wc-block-components-totals-footer-item > .wc-block-components-totals-item__value'
)
).toHaveText( totals[ i ] );
await page
.getByLabel( `Remove coupon "${ coupons[ i ].code }"` )
.click();
await expect(
page
.locator(
'.wc-block-components-notice-banner__content'
)
.getByText(
`Coupon code "${ coupons[ i ].code }" has been removed from your cart.`
)
).toBeVisible();
}
}
);
test(
'allows cart block to apply multiple coupons',
{ tag: [ '@could-be-unit-test' ] },
async ( { page } ) => {
const totals = [ '$50.00', '$22.50', '$12.50' ];
const totalsReverse = [ '$17.50', '$45.00', '$55.00' ];
const discounts = [ '-$5.00', '-$32.50', '-$42.50' ];
// add all coupons and verify prices
for ( let i = 0; i < coupons.length; i++ ) {
await page
.getByRole( 'button', { name: 'Add a coupon' } )
.click();
await page
.getByLabel( 'Enter code' )
.fill( coupons[ i ].code );
await page.getByText( 'Apply', { exact: true } ).click();
await expect(
page
.locator(
'.wc-block-components-notice-banner__content'
)
.getByText(
`Coupon code "${ coupons[ i ].code }" has been applied to your cart.`
)
).toBeVisible();
await expect(
page.locator(
'.wc-block-components-totals-discount > .wc-block-components-totals-item__value'
)
).toHaveText( discounts[ i ] );
await expect(
page.locator(
'.wc-block-components-totals-footer-item > .wc-block-components-totals-item__value'
)
).toHaveText( totals[ i ] );
}
for ( let i = 0; i < coupons.length; i++ ) {
await page
.getByLabel( `Remove coupon "${ coupons[ i ].code }"` )
.click();
await expect(
page.locator(
'.wc-block-components-totals-footer-item > .wc-block-components-totals-item__value'
)
).toHaveText( totalsReverse[ i ] );
}
}
);
test(
'prevents cart block applying same coupon twice',
{ tag: [ '@could-be-unit-test' ] },
async ( { page } ) => {
// try to add two same coupons and verify the error message
await page await page
.getByRole( 'button', { name: 'Add a coupon' } ) .getByRole( 'button', { name: 'Add a coupon' } )
.click(); .click();
await page.getByLabel( 'Enter code' ).fill( coupons[ i ].code ); await page.getByLabel( 'Enter code' ).fill( coupons[ 0 ].code );
await page.getByText( 'Apply', { exact: true } ).click(); await page.getByText( 'Apply', { exact: true } ).click();
await expect( await expect(
page page
@ -145,114 +239,40 @@ test.describe(
'.wc-block-components-notice-banner__content' '.wc-block-components-notice-banner__content'
) )
.getByText( .getByText(
`Coupon code "${ coupons[ i ].code }" has been applied to your cart.` `Coupon code "${ coupons[ 0 ].code }" has been applied to your cart.`
) )
).toBeVisible(); ).toBeVisible();
await expect(
page.locator(
'.wc-block-components-totals-footer-item > .wc-block-components-totals-item__value'
)
).toHaveText( totals[ i ] );
await page
.getByLabel( `Remove coupon "${ coupons[ i ].code }"` )
.click();
await expect(
page
.locator(
'.wc-block-components-notice-banner__content'
)
.getByText(
`Coupon code "${ coupons[ i ].code }" has been removed from your cart.`
)
).toBeVisible();
}
} );
test( 'allows cart block to apply multiple coupons', async ( {
page,
} ) => {
const totals = [ '$50.00', '$22.50', '$12.50' ];
const totalsReverse = [ '$17.50', '$45.00', '$55.00' ];
const discounts = [ '-$5.00', '-$32.50', '-$42.50' ];
// add all coupons and verify prices
for ( let i = 0; i < coupons.length; i++ ) {
await page await page
.getByRole( 'button', { name: 'Add a coupon' } ) .getByRole( 'button', { name: 'Add a coupon' } )
.click(); .click();
await page.getByLabel( 'Enter code' ).fill( coupons[ i ].code ); await page.getByLabel( 'Enter code' ).fill( coupons[ 0 ].code );
await page.getByText( 'Apply', { exact: true } ).click(); await page.getByText( 'Apply', { exact: true } ).click();
await expect( await expect(
page page
.locator( .getByRole( 'alert' )
'.wc-block-components-notice-banner__content'
)
.getByText( .getByText(
`Coupon code "${ coupons[ i ].code }" has been applied to your cart.` `Coupon code "${ coupons[ 0 ].code }" has already been applied.`
) )
).toBeVisible(); ).toBeVisible();
await expect(
page.locator(
'.wc-block-components-totals-discount > .wc-block-components-totals-item__value'
)
).toHaveText( discounts[ i ] );
await expect(
page.locator(
'.wc-block-components-totals-footer-item > .wc-block-components-totals-item__value'
)
).toHaveText( totals[ i ] );
} }
);
for ( let i = 0; i < coupons.length; i++ ) { test(
'prevents cart block applying coupon with usage limit',
{ tag: [ '@could-be-unit-test' ] },
async ( { page } ) => {
// add coupon with usage limit
await page await page
.getByLabel( `Remove coupon "${ coupons[ i ].code }"` ) .getByRole( 'button', { name: 'Add a coupon' } )
.click(); .click();
await page.getByLabel( 'Enter code' ).fill( couponLimitedCode );
await page.getByText( 'Apply', { exact: true } ).click();
await expect( await expect(
page.locator( page
'.wc-block-components-totals-footer-item > .wc-block-components-totals-item__value' .getByRole( 'alert' )
) .getByText( 'Coupon usage limit has been reached.' )
).toHaveText( totalsReverse[ i ] ); ).toBeVisible();
} }
} ); );
test( 'prevents cart block applying same coupon twice', async ( {
page,
} ) => {
// try to add two same coupons and verify the error message
await page.getByRole( 'button', { name: 'Add a coupon' } ).click();
await page.getByLabel( 'Enter code' ).fill( coupons[ 0 ].code );
await page.getByText( 'Apply', { exact: true } ).click();
await expect(
page
.locator( '.wc-block-components-notice-banner__content' )
.getByText(
`Coupon code "${ coupons[ 0 ].code }" has been applied to your cart.`
)
).toBeVisible();
await page.getByRole( 'button', { name: 'Add a coupon' } ).click();
await page.getByLabel( 'Enter code' ).fill( coupons[ 0 ].code );
await page.getByText( 'Apply', { exact: true } ).click();
await expect(
page
.getByRole( 'alert' )
.getByText(
`Coupon code "${ coupons[ 0 ].code }" has already been applied.`
)
).toBeVisible();
} );
test( 'prevents cart block applying coupon with usage limit', async ( {
page,
} ) => {
// add coupon with usage limit
await page.getByRole( 'button', { name: 'Add a coupon' } ).click();
await page.getByLabel( 'Enter code' ).fill( couponLimitedCode );
await page.getByText( 'Apply', { exact: true } ).click();
await expect(
page
.getByRole( 'alert' )
.getByText( 'Coupon usage limit has been reached.' )
).toBeVisible();
} );
} }
); );

View File

@ -73,116 +73,132 @@ test.describe( 'Cart Block page', { tag: [ '@payments', '@services' ] }, () => {
} ); } );
} ); } );
test( 'can see empty cart, add and remove simple & cross sell product, increase to max quantity', async ( { test(
page, 'can see empty cart, add and remove simple & cross sell product, increase to max quantity',
testPage, { tag: [ '@could-be-unit-test' ] },
} ) => { async ( { page, testPage } ) => {
await goToPageEditor( { page } ); await goToPageEditor( { page } );
await fillPageTitle( page, testPage.title ); await fillPageTitle( page, testPage.title );
await insertBlockByShortcut( page, 'Cart' ); await insertBlockByShortcut( page, 'Cart' );
await publishPage( page, testPage.title ); await publishPage( page, testPage.title );
// go to the page to test empty cart block // go to the page to test empty cart block
await page.goto( testPage.slug ); await page.goto( testPage.slug );
await expect( await expect(
page.getByRole( 'heading', { name: testPage.title } ) page.getByRole( 'heading', { name: testPage.title } )
).toBeVisible(); ).toBeVisible();
await expect( await expect(
await page.getByText( 'Your cart is currently empty!' ).count() await page.getByText( 'Your cart is currently empty!' ).count()
).toBeGreaterThan( 0 ); ).toBeGreaterThan( 0 );
await expect( await expect(
page.getByRole( 'link', { name: 'Browse store' } ) page.getByRole( 'link', { name: 'Browse store' } )
).toBeVisible(); ).toBeVisible();
await page.getByRole( 'link', { name: 'Browse store' } ).click(); await page.getByRole( 'link', { name: 'Browse store' } ).click();
await expect( await expect(
page.getByRole( 'heading', { name: 'Shop' } ) page.getByRole( 'heading', { name: 'Shop' } )
).toBeVisible(); ).toBeVisible();
await addAProductToCart( page, product1Id ); await addAProductToCart( page, product1Id );
await page.goto( testPage.slug ); await page.goto( testPage.slug );
await expect( await expect(
page.getByRole( 'heading', { name: testPage.title } ) page.getByRole( 'heading', { name: testPage.title } )
).toBeVisible(); ).toBeVisible();
await expect( await expect(
page.getByRole( 'link', { name: simpleProductName, exact: true } ) page.getByRole( 'link', {
).toBeVisible(); name: simpleProductName,
await expect( page.getByText( simpleProductDesc ) ).toBeVisible(); exact: true,
await expect( } )
page.getByText( `Save $${ singleProductSalePrice }` ) ).toBeVisible();
).toBeVisible(); await expect( page.getByText( simpleProductDesc ) ).toBeVisible();
await expect(
page.getByText( `Save $${ singleProductSalePrice }` )
).toBeVisible();
// increase product quantity to its maximum // increase product quantity to its maximum
await expect( page.getByText( '2 left in stock' ) ).toBeVisible(); await expect( page.getByText( '2 left in stock' ) ).toBeVisible();
await page await page
.getByRole( 'button' ) .getByRole( 'button' )
.filter( { hasText: '', exact: true } ) .filter( { hasText: '', exact: true } )
.click(); .click();
await expect( await expect(
page.locator( page.locator(
'.wc-block-components-totals-footer-item > .wc-block-components-totals-item__value' '.wc-block-components-totals-footer-item > .wc-block-components-totals-item__value'
) )
).toContainText( `$${ doubleProductsPrice.toString() }` ); ).toContainText( `$${ doubleProductsPrice.toString() }` );
await expect( await expect(
page.getByRole( 'button' ).filter( { hasText: '', exact: true } ) page
).toBeDisabled(); .getByRole( 'button' )
.filter( { hasText: '', exact: true } )
).toBeDisabled();
// add cross-sell products to cart // add cross-sell products to cart
await expect( await expect(
page.getByRole( 'heading', { name: 'You may be interested in…' } ) page.getByRole( 'heading', {
).toBeVisible(); name: 'You may be interested in…',
await page } )
.getByLabel( `Add to cart: “${ simpleProductName } Cross-Sell 1”` ) ).toBeVisible();
.click(); await page
await expect( .getByLabel(
page `Add to cart: “${ simpleProductName } Cross-Sell 1”`
.locator( '.wc-block-cart-items' ) )
.getByText( `${ simpleProductName } Cross-Sell 1` ) .click();
).toBeVisible(); await expect(
await page page
.getByLabel( `Add to cart: “${ simpleProductName } Cross-Sell 2”` ) .locator( '.wc-block-cart-items' )
.click(); .getByText( `${ simpleProductName } Cross-Sell 1` )
await expect( ).toBeVisible();
page await page
.locator( '.wc-block-cart-items' ) .getByLabel(
.getByText( `${ simpleProductName } Cross-Sell 2` ) `Add to cart: “${ simpleProductName } Cross-Sell 2”`
).toBeVisible(); )
.click();
await expect(
page
.locator( '.wc-block-cart-items' )
.getByText( `${ simpleProductName } Cross-Sell 2` )
).toBeVisible();
await page.goto( testPage.slug ); await page.goto( testPage.slug );
await expect( await expect(
page.getByRole( 'heading', { name: testPage.title } ) page.getByRole( 'heading', { name: testPage.title } )
).toBeVisible(); ).toBeVisible();
await expect( await expect(
page.getByRole( 'heading', { name: 'You may be interested in…' } ) page.getByRole( 'heading', {
).toBeHidden(); name: 'You may be interested in…',
await expect( } )
page.locator( ).toBeHidden();
'.wc-block-components-totals-footer-item > .wc-block-components-totals-item__value' await expect(
) page.locator(
).toContainText( '.wc-block-components-totals-footer-item > .wc-block-components-totals-item__value'
`$${ singleProductWithCrossSellProducts.toString() }` )
); ).toContainText(
`$${ singleProductWithCrossSellProducts.toString() }`
);
// remove cross-sell products from cart // remove cross-sell products from cart
await page.locator( ':nth-match(:text("Remove item"), 3)' ).click(); await page.locator( ':nth-match(:text("Remove item"), 3)' ).click();
await page.locator( ':nth-match(:text("Remove item"), 2)' ).click(); await page.locator( ':nth-match(:text("Remove item"), 2)' ).click();
await expect( await expect(
page.getByRole( 'heading', { name: 'You may be interested in…' } ) page.getByRole( 'heading', {
).toBeVisible(); name: 'You may be interested in…',
} )
).toBeVisible();
// check if the link to proceed to the checkout exists // check if the link to proceed to the checkout exists
await expect( await expect(
page.getByRole( 'link', { page.getByRole( 'link', {
name: 'Proceed to Checkout', name: 'Proceed to Checkout',
} ) } )
).toBeVisible(); ).toBeVisible();
// remove product from cart // remove product from cart
await page.locator( ':text("Remove item")' ).click(); await page.locator( ':text("Remove item")' ).click();
await expect( await expect(
page.getByText( 'Your cart is currently empty!' ) page.getByText( 'Your cart is currently empty!' )
).toBeVisible(); ).toBeVisible();
await expect( await expect(
page.getByRole( 'link', { name: 'Browse store' } ) page.getByRole( 'link', { name: 'Browse store' } )
).toBeVisible(); ).toBeVisible();
} ); }
);
} ); } );

View File

@ -125,108 +125,120 @@ test.describe(
} ); } );
} ); } );
test( 'allows customer to calculate Free Shipping if in Germany', async ( { test(
page, 'allows customer to calculate Free Shipping if in Germany',
} ) => { { tag: [ '@could-be-unit-test' ] },
await page.goto( '/cart/' ); async ( { page } ) => {
// Set shipping country to Germany await page.goto( '/cart/' );
await page.locator( 'a.shipping-calculator-button' ).click(); // Set shipping country to Germany
await page await page.locator( 'a.shipping-calculator-button' ).click();
.locator( '#calc_shipping_country' ) await page
.selectOption( shippingCountryDE ); .locator( '#calc_shipping_country' )
await page.locator( 'button[name="calc_shipping"]' ).click(); .selectOption( shippingCountryDE );
await page.locator( 'button[name="calc_shipping"]' ).click();
// Verify shipping costs // Verify shipping costs
await expect( await expect(
page.locator( '.shipping ul#shipping_method > li' ) page.locator( '.shipping ul#shipping_method > li' )
).toContainText( 'Free shipping' ); ).toContainText( 'Free shipping' );
await expect( await expect(
page.locator( '.order-total .amount' ) page.locator( '.order-total .amount' )
).toContainText( firstProductPrice ); ).toContainText( firstProductPrice );
} ); }
);
test( 'allows customer to calculate Flat rate and Local pickup if in France', async ( { test(
page, 'allows customer to calculate Flat rate and Local pickup if in France',
} ) => { { tag: [ '@could-be-unit-test' ] },
await page.goto( '/cart/' ); async ( { page } ) => {
// Set shipping country to France await page.goto( '/cart/' );
await page.locator( 'a.shipping-calculator-button' ).click(); // Set shipping country to France
await page await page.locator( 'a.shipping-calculator-button' ).click();
.locator( '#calc_shipping_country' ) await page
.selectOption( shippingCountryFR ); .locator( '#calc_shipping_country' )
await page.locator( 'button[name="calc_shipping"]' ).click(); .selectOption( shippingCountryFR );
await page.locator( 'button[name="calc_shipping"]' ).click();
// Verify shipping costs // Verify shipping costs
await expect( page.locator( '.shipping .amount' ) ).toContainText( await expect(
'$5.00' page.locator( '.shipping .amount' )
); ).toContainText( '$5.00' );
await expect( await expect(
page.locator( '.order-total .amount' ) page.locator( '.order-total .amount' )
).toContainText( `$${ firstProductWithFlatRate }` ); ).toContainText( `$${ firstProductWithFlatRate }` );
// Set shipping to local pickup instead of flat rate // Set shipping to local pickup instead of flat rate
await page.locator( 'text=Local pickup' ).click(); await page.locator( 'text=Local pickup' ).click();
// Verify updated shipping costs // Verify updated shipping costs
await expect( await expect(
page.locator( '.order-total .amount' ).first() page.locator( '.order-total .amount' ).first()
).toContainText( `$${ firstProductPrice }` ); ).toContainText( `$${ firstProductPrice }` );
} ); }
);
test( 'should show correct total cart price after updating quantity', async ( { test(
page, 'should show correct total cart price after updating quantity',
} ) => { { tag: [ '@could-be-unit-test' ] },
await page.goto( '/cart/' ); async ( { page } ) => {
await page.locator( 'input.qty' ).fill( '4' ); await page.goto( '/cart/' );
await page.locator( 'text=Update cart' ).click(); await page.locator( 'input.qty' ).fill( '4' );
await page.locator( 'text=Update cart' ).click();
// Set shipping country to France // Set shipping country to France
await page.locator( 'a.shipping-calculator-button' ).click(); await page.locator( 'a.shipping-calculator-button' ).click();
await page await page
.locator( '#calc_shipping_country' ) .locator( '#calc_shipping_country' )
.selectOption( shippingCountryFR ); .selectOption( shippingCountryFR );
await page.locator( 'button[name="calc_shipping"]' ).click(); await page.locator( 'button[name="calc_shipping"]' ).click();
await expect( await expect(
page.locator( '.order-total .amount' ) page.locator( '.order-total .amount' )
).toContainText( `$${ fourProductsWithFlatRate }` ); ).toContainText( `$${ fourProductsWithFlatRate }` );
} ); }
);
test( 'should show correct total cart price with 2 products and flat rate', async ( { test(
page, 'should show correct total cart price with 2 products and flat rate',
} ) => { { tag: [ '@could-be-unit-test' ] },
await addAProductToCart( page, secondProductId ); async ( { page } ) => {
await addAProductToCart( page, secondProductId );
await page.goto( '/cart/' ); await page.goto( '/cart/' );
await page.locator( 'a.shipping-calculator-button' ).click(); await page.locator( 'a.shipping-calculator-button' ).click();
await page await page
.locator( '#calc_shipping_country' ) .locator( '#calc_shipping_country' )
.selectOption( shippingCountryFR ); .selectOption( shippingCountryFR );
await page.locator( 'button[name="calc_shipping"]' ).click(); await page.locator( 'button[name="calc_shipping"]' ).click();
await expect( page.locator( '.shipping .amount' ) ).toContainText( await expect(
'$5.00' page.locator( '.shipping .amount' )
); ).toContainText( '$5.00' );
await expect( await expect(
page.locator( '.order-total .amount' ) page.locator( '.order-total .amount' )
).toContainText( `$${ twoProductsWithFlatRate }` ); ).toContainText( `$${ twoProductsWithFlatRate }` );
} ); }
);
test( 'should show correct total cart price with 2 products without flat rate', async ( { test(
page, 'should show correct total cart price with 2 products without flat rate',
} ) => { { tag: [ '@could-be-unit-test' ] },
await addAProductToCart( page, secondProductId ); async ( { page } ) => {
await addAProductToCart( page, secondProductId );
// Set shipping country to Spain // Set shipping country to Spain
await page.goto( '/cart/' ); await page.goto( '/cart/' );
await page.locator( 'a.shipping-calculator-button' ).click(); await page.locator( 'a.shipping-calculator-button' ).click();
await page.locator( '#calc_shipping_country' ).selectOption( 'ES' ); await page
await page.locator( 'button[name="calc_shipping"]' ).click(); .locator( '#calc_shipping_country' )
.selectOption( 'ES' );
await page.locator( 'button[name="calc_shipping"]' ).click();
// Verify shipping costs // Verify shipping costs
await expect( await expect(
page.locator( '.order-total .amount' ) page.locator( '.order-total .amount' )
).toContainText( `$${ twoProductsTotal }` ); ).toContainText( `$${ twoProductsTotal }` );
} ); }
);
} }
); );

View File

@ -38,7 +38,7 @@ let productId,
test.describe( test.describe(
'Shopper Cart & Checkout Block Tax Display', 'Shopper Cart & Checkout Block Tax Display',
{ tag: [ '@payments', '@services', '@hpos' ] }, { tag: [ '@payments', '@services', '@hpos', '@could-be-unit-test' ] },
() => { () => {
test.use( { storageState: process.env.ADMINSTATE } ); test.use( { storageState: process.env.ADMINSTATE } );
test.beforeAll( async ( { baseURL } ) => { test.beforeAll( async ( { baseURL } ) => {
@ -240,7 +240,7 @@ test.describe(
test.describe( test.describe(
'Shopper Cart & Checkout Block Tax Rounding', 'Shopper Cart & Checkout Block Tax Rounding',
{ tag: [ '@payments', '@services' ] }, { tag: [ '@payments', '@services', '@could-be-unit-test' ] },
() => { () => {
test.beforeAll( async ( { baseURL } ) => { test.beforeAll( async ( { baseURL } ) => {
const api = new wcApi( { const api = new wcApi( {
@ -484,7 +484,7 @@ test.describe(
test.describe( test.describe(
'Shopper Cart & Checkout Block Tax Levels', 'Shopper Cart & Checkout Block Tax Levels',
{ tag: [ '@payments', '@services' ] }, { tag: [ '@payments', '@services', '@could-be-unit-test' ] },
() => { () => {
test.beforeAll( async ( { baseURL } ) => { test.beforeAll( async ( { baseURL } ) => {
const api = new wcApi( { const api = new wcApi( {
@ -809,7 +809,7 @@ test.describe(
test.describe( test.describe(
'Shipping Cart & Checkout Block Tax', 'Shipping Cart & Checkout Block Tax',
{ tag: [ '@payments', '@services' ] }, { tag: [ '@payments', '@services', '@could-be-unit-test' ] },
() => { () => {
test.beforeAll( async ( { baseURL } ) => { test.beforeAll( async ( { baseURL } ) => {
const api = new wcApi( { const api = new wcApi( {

View File

@ -24,7 +24,7 @@ let productId,
test.describe.serial( test.describe.serial(
'Tax rates in the cart and checkout', 'Tax rates in the cart and checkout',
{ tag: [ '@payments', '@services', '@hpos' ] }, { tag: [ '@payments', '@services', '@hpos', '@could-be-unit-test' ] },
() => { () => {
test.beforeAll( async ( { baseURL } ) => { test.beforeAll( async ( { baseURL } ) => {
const api = new wcApi( { const api = new wcApi( {

View File

@ -306,60 +306,65 @@ test.describe(
} ); } );
} ); } );
test( 'restores total when coupons are removed', async ( { test(
page, 'restores total when coupons are removed',
context, { tag: [ '@could-be-unit-test' ] },
} ) => { async ( { page, context } ) => {
await test.step( 'Load cart page and try restoring total when removed coupons', async () => { await test.step( 'Load cart page and try restoring total when removed coupons', async () => {
await addAProductToCart( page, firstProductId ); await addAProductToCart( page, firstProductId );
await page.goto( '/cart/' ); await page.goto( '/cart/' );
await page.locator( '#coupon_code' ).fill( coupons[ 0 ].code ); await page
await page .locator( '#coupon_code' )
.getByRole( 'button', { name: 'Apply coupon' } ) .fill( coupons[ 0 ].code );
.click(); await page
.getByRole( 'button', { name: 'Apply coupon' } )
.click();
// confirm numbers // confirm numbers
await expect( await expect(
page.locator( '.cart-discount .amount' ) page.locator( '.cart-discount .amount' )
).toContainText( discounts[ 0 ] ); ).toContainText( discounts[ 0 ] );
await expect( await expect(
page.locator( '.order-total .amount' ) page.locator( '.order-total .amount' )
).toContainText( totals[ 0 ] ); ).toContainText( totals[ 0 ] );
await page.locator( 'a.woocommerce-remove-coupon' ).click(); await page.locator( 'a.woocommerce-remove-coupon' ).click();
await expect( await expect(
page.locator( '.order-total .amount' ) page.locator( '.order-total .amount' )
).toContainText( '$20.00' ); ).toContainText( '$20.00' );
} ); } );
await context.clearCookies(); await context.clearCookies();
await test.step( 'Load checkout page and try restoring total when removed coupons', async () => { await test.step( 'Load checkout page and try restoring total when removed coupons', async () => {
await addAProductToCart( page, firstProductId ); await addAProductToCart( page, firstProductId );
await page.goto( '/checkout/' ); await page.goto( '/checkout/' );
await page await page
.locator( 'text=Click here to enter your code' ) .locator( 'text=Click here to enter your code' )
.click(); .click();
await page.locator( '#coupon_code' ).fill( coupons[ 0 ].code ); await page
await page.locator( 'text=Apply coupon' ).click(); .locator( '#coupon_code' )
.fill( coupons[ 0 ].code );
await page.locator( 'text=Apply coupon' ).click();
// confirm numbers // confirm numbers
await expect( await expect(
page.locator( '.cart-discount .amount' ) page.locator( '.cart-discount .amount' )
).toContainText( discounts[ 0 ] ); ).toContainText( discounts[ 0 ] );
await expect( await expect(
page.locator( '.order-total .amount' ) page.locator( '.order-total .amount' )
).toContainText( totals[ 0 ] ); ).toContainText( totals[ 0 ] );
await page.locator( 'a.woocommerce-remove-coupon' ).click(); await page.locator( 'a.woocommerce-remove-coupon' ).click();
await expect( await expect(
page.locator( '.order-total .amount' ) page.locator( '.order-total .amount' )
).toContainText( '$20.00' ); ).toContainText( '$20.00' );
} ); } );
} ); }
);
} }
); );

View File

@ -17,7 +17,7 @@ const awaitCartPageResponse = ( page ) =>
test.describe( test.describe(
'Cart & Checkout Restricted Coupons', 'Cart & Checkout Restricted Coupons',
{ tag: [ '@payments', '@services', '@hpos' ] }, { tag: [ '@payments', '@services', '@hpos', '@could-be-unit-test' ] },
() => { () => {
let firstProductId, let firstProductId,
secondProductId, secondProductId,

View File

@ -3,7 +3,7 @@ const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default;
test.describe( test.describe(
'Cart > Redirect to cart from shop', 'Cart > Redirect to cart from shop',
{ tag: [ '@payments', '@services' ] }, { tag: [ '@payments', '@services', '@not-e2e' ] },
() => { () => {
let productId; let productId;
const productName = 'A redirect product test'; const productName = 'A redirect product test';

View File

@ -81,100 +81,116 @@ test.describe( 'Cart page', { tag: [ '@payments', '@services' ] }, () => {
await responsePromise; await responsePromise;
} }
test( 'should display no item in the cart', async ( { page } ) => { test(
await page.goto( '/cart/' ); 'should display no item in the cart',
await expect( { tag: [ '@could-be-unit-test' ] },
page.getByText( 'Your cart is currently empty.' ) async ( { page } ) => {
).toBeVisible(); await page.goto( '/cart/' );
} ); await expect(
page.getByText( 'Your cart is currently empty.' )
test( 'should add the product to the cart from the shop page', async ( { ).toBeVisible();
page,
} ) => {
await goToShopPageAndAddProductToCart( page, productName );
await page.goto( '/cart/' );
await expect( page.locator( 'td.product-name' ) ).toContainText(
productName
);
} );
test( 'should increase item quantity when "Add to cart" of the same product is clicked', async ( {
page,
} ) => {
let qty = 2;
while ( qty-- ) {
await goToShopPageAndAddProductToCart( page, productName );
} }
);
await page.goto( '/cart/' ); test(
await expect( page.locator( 'input.qty' ) ).toHaveValue( '2' ); 'should add the product to the cart from the shop page',
} ); { tag: [ '@could-be-unit-test' ] },
async ( { page } ) => {
await goToShopPageAndAddProductToCart( page, productName );
test( 'should update quantity when updated via quantity input', async ( { await page.goto( '/cart/' );
page, await expect( page.locator( 'td.product-name' ) ).toContainText(
} ) => { productName
await goToShopPageAndAddProductToCart( page, productName ); );
}
);
await page.goto( '/cart/' ); test(
await page.locator( 'input.qty' ).fill( '2' ); 'should increase item quantity when "Add to cart" of the same product is clicked',
await page.locator( 'text=Update cart' ).click(); { tag: [ '@could-be-unit-test' ] },
async ( { page } ) => {
let qty = 2;
while ( qty-- ) {
await goToShopPageAndAddProductToCart( page, productName );
}
await expect( page.locator( '.order-total .amount' ) ).toContainText( await page.goto( '/cart/' );
`$${ twoProductPrice }` await expect( page.locator( 'input.qty' ) ).toHaveValue( '2' );
); }
} ); );
test( 'should remove the item from the cart when remove is clicked', async ( { test(
page, 'should update quantity when updated via quantity input',
} ) => { { tag: [ '@could-be-unit-test' ] },
await goToShopPageAndAddProductToCart( page, productName ); async ( { page } ) => {
await page.goto( '/cart/' ); await goToShopPageAndAddProductToCart( page, productName );
// make sure that the product is in the cart await page.goto( '/cart/' );
await expect( page.locator( '.order-total .amount' ) ).toContainText( await page.locator( 'input.qty' ).fill( '2' );
`$${ productPrice }` await page.locator( 'text=Update cart' ).click();
);
await page.locator( 'a.remove' ).click(); await expect(
page.locator( '.order-total .amount' )
).toContainText( `$${ twoProductPrice }` );
}
);
await expect( test(
page.getByText( `${ productName }” removed` ) 'should remove the item from the cart when remove is clicked',
).toBeVisible(); { tag: [ '@could-be-unit-test' ] },
await expect( async ( { page } ) => {
page.getByText( 'Your cart is currently empty' ) await goToShopPageAndAddProductToCart( page, productName );
).toBeVisible(); await page.goto( '/cart/' );
} );
test( 'should update subtotal in cart totals when adding product to the cart', async ( { // make sure that the product is in the cart
page, await expect(
} ) => { page.locator( '.order-total .amount' )
await goToShopPageAndAddProductToCart( page, productName ); ).toContainText( `$${ productPrice }` );
await page.goto( '/cart/' ); await page.locator( 'a.remove' ).click();
await expect( page.locator( '.cart-subtotal .amount' ) ).toContainText(
`$${ productPrice }`
);
await page.locator( 'input.qty' ).fill( '2' ); await expect(
await page.locator( 'text=Update cart' ).click(); page.getByText( `${ productName }” removed` )
).toBeVisible();
await expect(
page.getByText( 'Your cart is currently empty' )
).toBeVisible();
}
);
await expect( page.locator( '.order-total .amount' ) ).toContainText( test(
`$${ twoProductPrice }` 'should update subtotal in cart totals when adding product to the cart',
); { tag: [ '@could-be-unit-test' ] },
} ); async ( { page } ) => {
await goToShopPageAndAddProductToCart( page, productName );
test( 'should go to the checkout page when "Proceed to Checkout" is clicked', async ( { await page.goto( '/cart/' );
page, await expect(
} ) => { page.locator( '.cart-subtotal .amount' )
await goToShopPageAndAddProductToCart( page, productName ); ).toContainText( `$${ productPrice }` );
await page.goto( '/cart/' ); await page.locator( 'input.qty' ).fill( '2' );
await page.locator( 'text=Update cart' ).click();
await page.locator( '.checkout-button' ).click(); await expect(
page.locator( '.order-total .amount' )
).toContainText( `$${ twoProductPrice }` );
}
);
await expect( page.locator( '#order_review' ) ).toBeVisible(); test(
} ); 'should go to the checkout page when "Proceed to Checkout" is clicked',
{ tag: [ '@could-be-unit-test' ] },
async ( { page } ) => {
await goToShopPageAndAddProductToCart( page, productName );
await page.goto( '/cart/' );
await page.locator( '.checkout-button' ).click();
await expect( page.locator( '#order_review' ) ).toBeVisible();
}
);
test( 'can manage cross-sell products and maximum item quantity', async ( { test( 'can manage cross-sell products and maximum item quantity', async ( {
page, page,

View File

@ -72,51 +72,43 @@ async function runComingSoonTests( themeContext = '' ) {
} ); } );
} }
test.describe( test.describe( 'Launch Your Store front end - logged out', () => {
'Launch Your Store front end - logged out', test.afterAll( async ( { baseURL } ) => {
{ tag: [ '@payments', '@services' ] }, try {
() => { await setOption(
test.afterAll( async ( { baseURL } ) => { request,
try { baseURL,
await setOption( 'woocommerce_coming_soon',
request, 'no'
baseURL,
'woocommerce_coming_soon',
'no'
);
} catch ( error ) {
console.log( error );
}
} );
test.describe( 'Block Theme (Twenty Twenty Four)', () => {
test.beforeAll( async () => {
await activateTheme( 'twentytwentyfour' );
} );
test.afterAll( async () => {
// Reset theme to the default.
await activateTheme( DEFAULT_THEME );
} );
runComingSoonTests( test.step, test.use );
} );
test.describe( 'Classic Theme (Storefront)', () => {
test.beforeAll( async () => {
await activateTheme( 'storefront' );
} );
test.afterAll( async () => {
// Reset theme to the default.
await activateTheme( DEFAULT_THEME );
} );
runComingSoonTests(
test.step,
test.use,
'Classic Theme (Storefront)'
); );
} catch ( error ) {
console.log( error );
}
} );
test.describe( 'Block Theme (Twenty Twenty Four)', () => {
test.beforeAll( async () => {
await activateTheme( 'twentytwentyfour' );
} ); } );
}
); test.afterAll( async () => {
// Reset theme to the default.
await activateTheme( DEFAULT_THEME );
} );
runComingSoonTests( test.step, test.use );
} );
test.describe( 'Classic Theme (Storefront)', () => {
test.beforeAll( async () => {
await activateTheme( 'storefront' );
} );
test.afterAll( async () => {
// Reset theme to the default.
await activateTheme( DEFAULT_THEME );
} );
runComingSoonTests( test.step, test.use, 'Classic Theme (Storefront)' );
} );
} );

View File

@ -3,7 +3,7 @@ const { test, expect } = require( '@playwright/test' );
// test case for bug https://github.com/woocommerce/woocommerce/pull/46429 // test case for bug https://github.com/woocommerce/woocommerce/pull/46429
test.describe( test.describe(
'Check the title of the shop page after the page has been deleted', 'Check the title of the shop page after the page has been deleted',
{ tag: [ '@payments', '@services' ] }, { tag: [ '@payments', '@services', '@could-be-unit-test' ] },
() => { () => {
test.use( { storageState: process.env.ADMINSTATE } ); test.use( { storageState: process.env.ADMINSTATE } );
test.beforeEach( async ( { page } ) => { test.beforeEach( async ( { page } ) => {

View File

@ -6,7 +6,7 @@ const test = baseTest.extend( {
test( test(
'logged-in customer can comment on a post', 'logged-in customer can comment on a post',
{ tag: [ '@gutenberg', '@payments', '@services' ] }, { tag: [ '@non-critical' ] },
async ( { page } ) => { async ( { page } ) => {
await page.goto( 'hello-world/' ); await page.goto( 'hello-world/' );
await expect( await expect(