Migrate cart/checkout tax tests to Playwright (https://github.com/woocommerce/woocommerce-blocks/pull/11954)
This commit is contained in:
parent
0d84dca852
commit
d32be3f47b
|
@ -1,80 +0,0 @@
|
|||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import {
|
||||
shopper,
|
||||
getExpectedTaxes,
|
||||
getTaxesFromCurrentPage,
|
||||
getTaxesFromOrderSummaryPage,
|
||||
showTaxes,
|
||||
SIMPLE_VIRTUAL_PRODUCT_NAME,
|
||||
} from '../../../../utils';
|
||||
import { Taxes, Products } from '../../../fixtures/fixture-data';
|
||||
|
||||
const taxRates = Taxes();
|
||||
const productWooSingle1 = Products().find(
|
||||
( prod ) => prod.name === 'Woo Single #1'
|
||||
);
|
||||
|
||||
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE < 2 ) {
|
||||
// Skips all the tests if it's a WooCommerce Core process environment.
|
||||
// eslint-disable-next-line jest/no-focused-tests, jest/expect-expect
|
||||
test.only( `Skipping Cart & Checkout tests`, () => {} );
|
||||
}
|
||||
|
||||
describe.skip( 'Shopper → Cart & Checkout → Taxes', () => {
|
||||
beforeEach( async () => {
|
||||
await shopper.block.emptyCart();
|
||||
} );
|
||||
|
||||
describe( '"Enable tax rate calculations" is unchecked in WC settings -> general', () => {
|
||||
it( 'User cannot view the tax on Cart, Checkout & Order Summary', async () => {
|
||||
await showTaxes( false );
|
||||
await shopper.block.goToShop();
|
||||
await shopper.addToCartFromShopPage( SIMPLE_VIRTUAL_PRODUCT_NAME );
|
||||
await shopper.block.goToCart();
|
||||
|
||||
const cartTaxes = await getTaxesFromCurrentPage();
|
||||
expect( cartTaxes ).toEqual( [] );
|
||||
|
||||
await shopper.block.goToCheckout();
|
||||
const checkoutTaxes = await getTaxesFromCurrentPage();
|
||||
expect( checkoutTaxes ).toEqual( [] );
|
||||
|
||||
await shopper.block.fillInCheckoutWithTestData();
|
||||
await shopper.block.placeOrder();
|
||||
await page.waitForSelector( 'h1.entry-title' );
|
||||
const orderSummaryTaxes = await getTaxesFromOrderSummaryPage(
|
||||
taxRates.filter( ( taxRate ) => taxRate.country === 'US' )
|
||||
);
|
||||
expect( orderSummaryTaxes ).toEqual( [] );
|
||||
} );
|
||||
} );
|
||||
|
||||
describe( '"Enable tax rate calculations" is checked in WC settings -> general', () => {
|
||||
it( 'User can view the tax on Cart, Checkout & Order Summary', async () => {
|
||||
await showTaxes( true );
|
||||
await shopper.block.goToShop();
|
||||
await shopper.addToCartFromShopPage( SIMPLE_VIRTUAL_PRODUCT_NAME );
|
||||
await shopper.block.goToCart();
|
||||
|
||||
const expectedTaxes = getExpectedTaxes( taxRates, 'US', [
|
||||
productWooSingle1,
|
||||
] );
|
||||
const cartTaxes = await getTaxesFromCurrentPage();
|
||||
expect( cartTaxes.sort() ).toEqual( expectedTaxes.sort() );
|
||||
|
||||
await shopper.block.goToCheckout();
|
||||
const checkoutTaxes = await getTaxesFromCurrentPage();
|
||||
expect( checkoutTaxes.sort() ).toEqual( expectedTaxes.sort() );
|
||||
|
||||
await shopper.block.fillInCheckoutWithTestData();
|
||||
await shopper.block.placeOrder();
|
||||
await page.waitForSelector( 'h1.entry-title' );
|
||||
const orderSummaryTaxes = await getTaxesFromOrderSummaryPage(
|
||||
taxRates.filter( ( taxRate ) => taxRate.country === 'US' )
|
||||
);
|
||||
expect( orderSummaryTaxes.sort() ).toEqual( expectedTaxes.sort() );
|
||||
} );
|
||||
} );
|
||||
} );
|
|
@ -0,0 +1,102 @@
|
|||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { expect, test as base } from '@woocommerce/e2e-playwright-utils';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import {
|
||||
DISCOUNTED_PRODUCT_NAME,
|
||||
REGULAR_PRICED_PRODUCT_NAME,
|
||||
} from '../checkout/constants';
|
||||
import { CheckoutPage } from '../checkout/checkout.page';
|
||||
|
||||
const test = base.extend< { checkoutPageObject: CheckoutPage } >( {
|
||||
checkoutPageObject: async ( { page }, use ) => {
|
||||
const pageObject = new CheckoutPage( {
|
||||
page,
|
||||
} );
|
||||
await use( pageObject );
|
||||
},
|
||||
} );
|
||||
|
||||
test.describe( 'Shopper → Taxes', () => {
|
||||
test( 'Tax visibility on Cart/Checkout/OrderSummary blocks depends on "Enable tax rate calculations" option in WC settings -> general', async ( {
|
||||
requestUtils,
|
||||
frontendUtils,
|
||||
page,
|
||||
checkoutPageObject,
|
||||
} ) => {
|
||||
// Turn off tax display.
|
||||
await requestUtils.rest( {
|
||||
method: 'PUT',
|
||||
path: 'wc/v3/settings/general/woocommerce_calc_taxes',
|
||||
data: { value: 'no' },
|
||||
} );
|
||||
await frontendUtils.goToShop();
|
||||
await frontendUtils.addToCart( DISCOUNTED_PRODUCT_NAME );
|
||||
await frontendUtils.addToCart( REGULAR_PRICED_PRODUCT_NAME );
|
||||
await frontendUtils.goToCart();
|
||||
|
||||
let cartSidebar = page.locator(
|
||||
'.wp-block-woocommerce-cart-totals-block'
|
||||
);
|
||||
const taxRow = cartSidebar
|
||||
.locator( '.wc-block-components-totals-taxes' )
|
||||
.getByText( 'Tax' );
|
||||
await expect( taxRow ).toBeHidden();
|
||||
|
||||
// Move to Checkout and look for Tax row.
|
||||
await frontendUtils.goToCheckout();
|
||||
let checkoutSidebar = page.locator(
|
||||
'.wp-block-woocommerce-checkout-totals-block'
|
||||
);
|
||||
const checkoutTaxRow = checkoutSidebar
|
||||
.locator( '.wc-block-components-totals-taxes' )
|
||||
.getByText( 'Tax' );
|
||||
await expect( checkoutTaxRow ).toBeHidden();
|
||||
|
||||
// Check out and look for tax on order confirmation page.
|
||||
await checkoutPageObject.fillInCheckoutWithTestData();
|
||||
await checkoutPageObject.placeOrder();
|
||||
const taxOnOrderConfirmation = page.getByText( 'Tax:' );
|
||||
await expect( taxOnOrderConfirmation ).toBeHidden();
|
||||
|
||||
// Empty the cart (it should be empty already, but just in case).
|
||||
await frontendUtils.emptyCart();
|
||||
|
||||
// Turn on tax display.
|
||||
await requestUtils.rest( {
|
||||
method: 'PUT',
|
||||
path: 'wc/v3/settings/general/woocommerce_calc_taxes',
|
||||
data: { value: 'yes' },
|
||||
} );
|
||||
await frontendUtils.goToShop();
|
||||
await frontendUtils.addToCart( DISCOUNTED_PRODUCT_NAME );
|
||||
await frontendUtils.addToCart( REGULAR_PRICED_PRODUCT_NAME );
|
||||
await frontendUtils.goToCart();
|
||||
|
||||
cartSidebar = page.locator( '.wp-block-woocommerce-cart-totals-block' );
|
||||
const visibleTaxRow = cartSidebar
|
||||
.locator( '.wc-block-components-totals-taxes' )
|
||||
.getByText( 'Tax' );
|
||||
await expect( visibleTaxRow ).toBeVisible();
|
||||
|
||||
// Move to Checkout and look for Tax row.
|
||||
await frontendUtils.goToCheckout();
|
||||
checkoutSidebar = page.locator(
|
||||
'.wp-block-woocommerce-checkout-totals-block'
|
||||
);
|
||||
const visibleCheckoutTaxRow = checkoutSidebar
|
||||
.locator( '.wc-block-components-totals-taxes' )
|
||||
.getByText( 'Tax' );
|
||||
await expect( visibleCheckoutTaxRow ).toBeVisible();
|
||||
|
||||
// Check out and look for tax on order confirmation page.
|
||||
await checkoutPageObject.fillInCheckoutWithTestData();
|
||||
await checkoutPageObject.placeOrder();
|
||||
const visibleTaxOnOrderConfirmation = page.getByText( 'Tax:' );
|
||||
await expect( visibleTaxOnOrderConfirmation ).toBeVisible();
|
||||
} );
|
||||
} );
|
|
@ -46,7 +46,7 @@ export class FrontendUtils {
|
|||
|
||||
async goToCheckout() {
|
||||
await this.page.goto( '/checkout', {
|
||||
waitUntil: 'commit',
|
||||
waitUntil: 'domcontentloaded',
|
||||
} );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue