Merge branch 'trunk' into add/e2e-create-order-component

This commit is contained in:
Greg 2021-08-18 12:52:25 -06:00 committed by GitHub
commit 58d1b707ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 91 additions and 28 deletions

View File

@ -1,5 +1,3 @@
/* eslint-disable jest/no-export, jest/no-disabled-tests */
/**
* Internal dependencies
*/
@ -10,7 +8,7 @@ const {
addShippingZoneAndMethod,
clearAndFillInput,
selectOptionInSelect2,
deleteAllShippingZones,
withRestApi,
} = require( '@woocommerce/e2e-utils' );
/**
@ -35,8 +33,8 @@ const runAddNewShippingZoneTest = () => {
describe('WooCommerce Shipping Settings - Add new shipping zone', () => {
beforeAll(async () => {
await createSimpleProduct();
await withRestApi.deleteAllShippingZones();
await merchant.login();
await deleteAllShippingZones();
});
it('add shipping zone for San Francisco with free Local pickup', async () => {
@ -86,7 +84,7 @@ const runAddNewShippingZoneTest = () => {
it('allows customer to benefit from a Free shipping if in CA', async () => {
await page.reload();
// Set shipping state to California
await expect(page).toClick('a.shipping-calculator-button');
await expect(page).toClick('#select2-calc_shipping_state-container');

View File

@ -1,16 +1,12 @@
/* eslint-disable jest/no-export, jest/no-disabled-tests, jest/expect-expect */
/**
* Internal dependencies
*/
const {
shopper,
merchant,
createSimpleProduct,
addShippingZoneAndMethod,
clearAndFillInput,
uiUnblocked,
selectOptionInSelect2,
withRestApi,
} = require( '@woocommerce/e2e-utils' );
/**
@ -43,29 +39,21 @@ const runCartCalculateShippingTest = () => {
await createSimpleProduct(firstProductName);
await createSimpleProduct(secondProductName, secondProductPrice);
await merchant.login();
await merchant.openNewShipping();
await withRestApi.resetSettingsGroupToDefault( 'general' );
// Add a new shipping zone Germany with Free shipping
await addShippingZoneAndMethod(shippingZoneNameDE, shippingCountryDE, ' ', 'free_shipping');
await withRestApi.addShippingZoneAndMethod(shippingZoneNameDE, shippingCountryDE, ' ', 'free_shipping');
// Add a new shipping zone for France with Flat rate & Local pickup
await addShippingZoneAndMethod(shippingZoneNameFR, shippingCountryFR, ' ', 'flat_rate');
await page.waitFor(1000); // to avoid flakiness in headless
await page.click('a.wc-shipping-zone-method-settings', {text: 'Flat rate'});
await clearAndFillInput('#woocommerce_flat_rate_cost', '5');
await page.click('.wc-backbone-modal-main button#btn-ok');
// Add additional method Local pickup for the same location
await page.waitFor(1000); // to avoid flakiness in headless
await page.click('button.wc-shipping-zone-add-method', {text:'Add shipping method'});
await page.waitForSelector('.wc-shipping-zone-method-selector');
await page.select('select[name="add_method_id"]', 'local_pickup');
await page.click('button#btn-ok');
await page.waitForSelector('#zone_locations');
await merchant.logout();
await withRestApi.addShippingZoneAndMethod(shippingZoneNameFR, shippingCountryFR, ' ', 'flat_rate', '5', ['local_pickup']);
await shopper.emptyCart();
});
afterAll(async () => {
await withRestApi.deleteAllShippingZones();
});
it('allows customer to calculate Free Shipping if in Germany', async () => {
await shopper.goToShop();
await shopper.addToCartFromShopPage(firstProductName);
@ -76,6 +64,7 @@ const runCartCalculateShippingTest = () => {
await expect(page).toClick('#select2-calc_shipping_country-container');
await selectOptionInSelect2('Germany');
await expect(page).toClick('button[name="calc_shipping"]');
await uiUnblocked();
// Verify shipping costs
await page.waitForSelector('.order-total');
@ -84,13 +73,14 @@ const runCartCalculateShippingTest = () => {
});
it('allows customer to calculate Flat rate and Local pickup if in France', async () => {
await page.reload();
await page.reload( { waitUntil: ['networkidle0', 'domcontentloaded'] } );
// Set shipping country to France
await expect(page).toClick('a.shipping-calculator-button');
await expect(page).toClick('#select2-calc_shipping_country-container');
await selectOptionInSelect2('France');
await expect(page).toClick('button[name="calc_shipping"]');
await uiUnblocked();
// Verify shipping costs
await page.waitForSelector('.order-total');
@ -119,13 +109,14 @@ const runCartCalculateShippingTest = () => {
});
it('should show correct total cart price with 2 products without flat rate', async () => {
await page.reload();
await page.reload( { waitUntil: ['networkidle0', 'domcontentloaded'] } );
// Set shipping country to Spain
await expect(page).toClick('a.shipping-calculator-button');
await expect(page).toClick('#select2-calc_shipping_country-container');
await selectOptionInSelect2('Spain');
await expect(page).toClick('button[name="calc_shipping"]');
await uiUnblocked();
// Verify shipping costs
await page.waitForSelector('.order-total');

View File

@ -17,6 +17,7 @@
- Added `deleteAllShippingClasses()` which permanently deletes all shipping classes using the API
- Added `statuses` optional parameter to `deleteAllRepositoryObjects()` to delete on specific statuses
- Added `createOrder()` component util that creates an order using the API with the passed in details
- Updated `addShippingZoneAndMethod` to use the API instead of UI to create shipping zones
# 0.1.5

View File

@ -93,6 +93,79 @@ export const withRestApi = {
const repository = Order.restRepository( client );
await deleteAllRepositoryObjects( repository, null, orderStatuses );
},
/**
* Adds a shipping zone along with a shipping method using the API.
*
* @param zoneName Shipping zone name.
* @param zoneLocation Shiping zone location. Defaults to country:US. For states use: state:US:CA.
* @param zipCode Shipping zone zip code. Default is no zip code.
* @param zoneMethod Shipping method type. Defaults to flat_rate (use also: free_shipping or local_pickup).
* @param cost Shipping method cost. Default is no cost.
* @param additionalZoneMethods Array of additional zone methods to add to the shipping zone.
*/
addShippingZoneAndMethod: async (
zoneName,
zoneLocation = 'country:US',
zipCode = '',
zoneMethod = 'flat_rate',
cost = '',
additionalZoneMethods = [] ) => {
const path = 'wc/v3/shipping/zones';
const response = await client.post( path, { name: zoneName } );
expect(response.statusCode).toEqual(201);
let zoneId = response.data.id;
// Select shipping zone location
let [ zoneType, zoneCode ] = zoneLocation.split(/:(.+)/);
let zoneLocationPayload = [
{
code: zoneCode,
type: zoneType,
}
];
// Fill shipping zone postcode if provided
if ( zipCode ) {
zoneLocationPayload.push( {
code: zipCode,
type: "postcode",
} );
}
const locationResponse = await client.put( path + `/${zoneId}/locations`, zoneLocationPayload );
expect(locationResponse.statusCode).toEqual(200);
// Add shipping zone method
let methodPayload = {
method_id: zoneMethod
}
const methodsResponse = await client.post( path + `/${zoneId}/methods`, methodPayload );
expect(methodsResponse.statusCode).toEqual(200);
let methodId = methodsResponse.data.id;
// Add in cost, if provided
if ( cost ) {
let costPayload = {
settings: {
cost: cost
}
}
const costResponse = await client.put( path + `/${zoneId}/methods/${methodId}`, costPayload );
expect(costResponse.statusCode).toEqual(200);
}
// Add any additional zones, if provided
if (additionalZoneMethods.length > 0) {
for ( let z = 0; z < additionalZoneMethods.length; z++ ) {
let response = await client.post( path + `/${zoneId}/methods`, { method_id: additionalZoneMethods[z] } );
expect(response.statusCode).toEqual(200);
}
}
},
/**
* Use api package to delete shipping zones.
*