2021-02-11 16:47:58 +00:00
|
|
|
/* eslint-disable jest/no-export, jest/no-disabled-tests */
|
2021-02-12 10:18:25 +00:00
|
|
|
|
2021-02-11 16:47:58 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
const {
|
2021-02-12 10:18:25 +00:00
|
|
|
shopper,
|
2021-02-11 16:47:58 +00:00
|
|
|
merchant,
|
2021-02-12 10:18:25 +00:00
|
|
|
createSimpleProduct,
|
2021-02-11 16:47:58 +00:00
|
|
|
addShippingZoneAndMethod,
|
2021-02-11 18:05:50 +00:00
|
|
|
clearAndFillInput,
|
2021-02-12 10:18:25 +00:00
|
|
|
selectOptionInSelect2,
|
2021-03-13 19:49:45 +00:00
|
|
|
evalAndClick,
|
2021-03-17 17:48:06 +00:00
|
|
|
uiUnblocked,
|
2021-02-11 16:47:58 +00:00
|
|
|
} = require( '@woocommerce/e2e-utils' );
|
|
|
|
|
2021-02-12 10:18:25 +00:00
|
|
|
const config = require( 'config' );
|
2021-03-16 08:02:52 +00:00
|
|
|
const simpleProductPrice = config.has( 'products.simple.price' ) ? config.get( 'products.simple.price' ) : '9.99';
|
2021-02-12 10:18:25 +00:00
|
|
|
const simpleProductName = config.get( 'products.simple.name' );
|
|
|
|
const california = 'California, United States (US)';
|
|
|
|
const sanFranciscoZIP = '94107';
|
2021-02-11 18:05:50 +00:00
|
|
|
const shippingZoneNameUS = 'US with Flat rate';
|
2021-02-12 15:10:23 +00:00
|
|
|
const shippingZoneNameFL = 'CA with Free shipping';
|
2021-02-11 18:05:50 +00:00
|
|
|
const shippingZoneNameSF = 'SF with Local pickup';
|
2021-02-11 16:47:58 +00:00
|
|
|
|
|
|
|
const runAddNewShippingZoneTest = () => {
|
|
|
|
describe('WooCommerce Shipping Settings - Add new shipping zone', () => {
|
|
|
|
beforeAll(async () => {
|
|
|
|
await merchant.login();
|
2021-02-12 10:18:25 +00:00
|
|
|
await createSimpleProduct();
|
2021-03-13 17:54:48 +00:00
|
|
|
await merchant.openSettings('shipping');
|
|
|
|
|
2021-03-17 17:48:06 +00:00
|
|
|
// Delete existing shipping zones.
|
2021-03-13 17:54:48 +00:00
|
|
|
try {
|
2021-03-17 17:48:06 +00:00
|
|
|
let zone = await page.$( '.wc-shipping-zone-delete' );
|
|
|
|
if ( zone ) {
|
|
|
|
// WP action links aren't clickable because they are hidden with a left=-9999 style.
|
|
|
|
await page.evaluate(() => {
|
|
|
|
document.querySelector('.wc-shipping-zone-name .row-actions')
|
|
|
|
.style
|
|
|
|
.left = '0';
|
|
|
|
});
|
|
|
|
while ( zone ) {
|
|
|
|
await evalAndClick( '.wc-shipping-zone-delete' );
|
|
|
|
await uiUnblocked();
|
|
|
|
zone = await page.$( '.wc-shipping-zone-delete' );
|
|
|
|
}
|
|
|
|
}
|
2021-03-13 17:54:48 +00:00
|
|
|
} catch (error) {
|
2021-03-17 17:48:06 +00:00
|
|
|
// Prevent an error here causing the test to fail.
|
2021-03-13 17:54:48 +00:00
|
|
|
}
|
2021-02-11 16:47:58 +00:00
|
|
|
});
|
|
|
|
|
2021-02-11 18:05:50 +00:00
|
|
|
it('add shipping zone for San Francisco with free Local pickup', async () => {
|
2021-02-12 17:19:48 +00:00
|
|
|
// Add a new shipping zone for San Francisco 94107, CA, US with Local pickup
|
2021-02-12 16:43:01 +00:00
|
|
|
await addShippingZoneAndMethod(shippingZoneNameSF, california, sanFranciscoZIP, 'local_pickup');
|
2021-02-12 15:10:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('add shipping zone for California with Free shipping', async () => {
|
2021-02-12 17:19:48 +00:00
|
|
|
// Add a new shipping zone for CA, US with Free shipping
|
2021-02-12 16:43:01 +00:00
|
|
|
await addShippingZoneAndMethod(shippingZoneNameFL, california, ' ', 'free_shipping');
|
2021-02-12 15:10:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('add shipping zone for the US with Flat rate', async () => {
|
|
|
|
// Add a new shipping zone for the US with Flat rate
|
|
|
|
await addShippingZoneAndMethod(shippingZoneNameUS);
|
|
|
|
|
|
|
|
// Set Flat rate cost
|
2021-03-17 17:48:06 +00:00
|
|
|
await expect(page).toClick('a.wc-shipping-zone-method-settings', {text: 'Flat rate'});
|
2021-02-12 15:10:23 +00:00
|
|
|
await clearAndFillInput('#woocommerce_flat_rate_cost', '10');
|
2021-03-17 17:48:06 +00:00
|
|
|
await expect(page).toClick('.wc-backbone-modal-main button#btn-ok');
|
2021-02-12 10:18:25 +00:00
|
|
|
await merchant.logout();
|
2021-02-11 16:47:58 +00:00
|
|
|
});
|
2021-02-12 10:18:25 +00:00
|
|
|
|
|
|
|
it('allows customer to pay for a Flat rate shipping method', async() => {
|
|
|
|
await shopper.login();
|
|
|
|
|
|
|
|
// Add product to cart as a shopper
|
|
|
|
await shopper.goToShop();
|
|
|
|
await shopper.addToCartFromShopPage(simpleProductName);
|
|
|
|
await shopper.goToCart();
|
|
|
|
|
|
|
|
// Set shipping country to United States (US)
|
|
|
|
await expect(page).toClick('a.shipping-calculator-button');
|
2021-02-12 15:10:23 +00:00
|
|
|
await expect(page).toClick('#select2-calc_shipping_country-container');
|
2021-02-12 10:18:25 +00:00
|
|
|
await selectOptionInSelect2('United States (US)');
|
|
|
|
|
|
|
|
// Set shipping state to New York
|
|
|
|
await expect(page).toClick('#select2-calc_shipping_state-container');
|
|
|
|
await selectOptionInSelect2('New York');
|
|
|
|
await expect(page).toClick('button[name="calc_shipping"]');
|
2021-03-13 11:26:28 +00:00
|
|
|
|
|
|
|
// Set shipping postcode to 10010
|
|
|
|
await clearAndFillInput('#calc_shipping_postcode', '10010');
|
|
|
|
await expect(page).toClick('button[name="calc_shipping"]');
|
2021-02-12 15:10:23 +00:00
|
|
|
|
2021-02-12 17:19:48 +00:00
|
|
|
// Verify shipping costs
|
2021-02-12 15:10:23 +00:00
|
|
|
await page.waitForSelector('.order-total');
|
2021-02-18 11:49:04 +00:00
|
|
|
await expect(page).toMatchElement('.shipping .amount', {text: '$10.00'});
|
2021-03-16 08:02:52 +00:00
|
|
|
await expect(page).toMatchElement('.order-total .amount', {text: `$1${simpleProductPrice}`});
|
2021-03-13 18:43:29 +00:00
|
|
|
});
|
2021-02-12 10:18:25 +00:00
|
|
|
|
|
|
|
it('allows customer to benefit from a Free shipping if in CA', async () => {
|
2021-03-13 18:43:29 +00:00
|
|
|
await page.reload();
|
2021-02-12 15:10:23 +00:00
|
|
|
// Set shipping state to California
|
|
|
|
await expect(page).toClick('a.shipping-calculator-button');
|
|
|
|
await expect(page).toClick('#select2-calc_shipping_state-container');
|
|
|
|
await selectOptionInSelect2('California');
|
|
|
|
|
2021-02-12 17:19:48 +00:00
|
|
|
// Set shipping postcode to 94000
|
2021-02-12 15:10:23 +00:00
|
|
|
await clearAndFillInput('#calc_shipping_postcode', '94000');
|
|
|
|
await expect(page).toClick('button[name="calc_shipping"]');
|
|
|
|
|
2021-02-12 17:19:48 +00:00
|
|
|
// Verify shipping method and cost
|
2021-02-12 15:10:23 +00:00
|
|
|
await page.waitForSelector('.order-total');
|
|
|
|
await expect(page).toMatchElement('.shipping ul#shipping_method > li', {text: 'Free shipping'});
|
2021-03-16 08:02:52 +00:00
|
|
|
await expect(page).toMatchElement('.order-total .amount', {text: `$${simpleProductPrice}`});
|
2021-03-13 18:43:29 +00:00
|
|
|
});
|
2021-02-12 10:18:25 +00:00
|
|
|
|
2021-02-12 15:10:23 +00:00
|
|
|
it('allows customer to benefit from a free Local pickup if in SF', async () => {
|
2021-03-13 18:43:29 +00:00
|
|
|
await page.reload();
|
2021-02-12 15:10:23 +00:00
|
|
|
// Set shipping postcode to 94107
|
|
|
|
await expect(page).toClick('a.shipping-calculator-button');
|
|
|
|
await clearAndFillInput('#calc_shipping_postcode', '94107');
|
|
|
|
await expect(page).toClick('button[name="calc_shipping"]');
|
|
|
|
|
2021-02-12 17:19:48 +00:00
|
|
|
// Verify shipping method and cost
|
2021-02-12 15:10:23 +00:00
|
|
|
await page.waitForSelector('.order-total');
|
2021-02-18 11:49:04 +00:00
|
|
|
await expect(page).toMatchElement('.shipping ul#shipping_method > li', {text: 'Local pickup'});
|
2021-03-16 08:02:52 +00:00
|
|
|
await expect(page).toMatchElement('.order-total .amount', {text: `$${simpleProductPrice}`});
|
2021-02-12 15:10:23 +00:00
|
|
|
|
|
|
|
await shopper.removeFromCart(simpleProductName);
|
2021-03-13 18:43:29 +00:00
|
|
|
});
|
2021-02-11 16:47:58 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = runAddNewShippingZoneTest;
|