Merge pull request #29623 from woocommerce/e2e/28485-resets
[WIP] Reset a test site
This commit is contained in:
commit
d496e8e3db
|
@ -4,7 +4,7 @@ import {
|
|||
switchUserToTest,
|
||||
clearLocalStorage,
|
||||
setBrowserViewport,
|
||||
factories,
|
||||
withRestApi,
|
||||
} from '@woocommerce/e2e-utils';
|
||||
|
||||
const { merchant } = require( '@woocommerce/e2e-utils' );
|
||||
|
@ -38,50 +38,13 @@ async function trashExistingPosts() {
|
|||
await switchUserToTest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Use api package to delete products.
|
||||
*
|
||||
* @return {Promise} Promise resolving once products have been trashed.
|
||||
*/
|
||||
async function deleteAllProducts() {
|
||||
const repository = SimpleProduct.restRepository( factories.api.withDefaultPermalinks );
|
||||
let products;
|
||||
|
||||
products = await repository.list();
|
||||
while ( products.length > 0 ) {
|
||||
for( let p = 0; p < products.length; p++ ) {
|
||||
await repository.delete( products[ p ].id );
|
||||
}
|
||||
products = await repository.list();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use api package to delete coupons.
|
||||
*
|
||||
* @return {Promise} Promise resolving once coupons have been trashed.
|
||||
*/
|
||||
async function deleteAllCoupons() {
|
||||
const repository = Coupon.restRepository( factories.api.withDefaultPermalinks );
|
||||
let coupons;
|
||||
|
||||
coupons = await repository.list();
|
||||
|
||||
while ( coupons.length > 0 ) {
|
||||
for (let c = 0; c < coupons.length; c++ ) {
|
||||
await repository.delete( coupons[ c ].id );
|
||||
}
|
||||
coupons = await repository.list();
|
||||
}
|
||||
}
|
||||
|
||||
// Before every test suite run, delete all content created by the test. This ensures
|
||||
// other posts/comments/etc. aren't dirtying tests and tests don't depend on
|
||||
// each other's side-effects.
|
||||
beforeAll( async () => {
|
||||
await trashExistingPosts();
|
||||
await deleteAllProducts();
|
||||
await deleteAllCoupons();
|
||||
await withRestApi.deleteAllProducts();
|
||||
await withRestApi.deleteAllCoupons();
|
||||
await clearLocalStorage();
|
||||
await setBrowserViewport( 'large' );
|
||||
} );
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
# Unreleased
|
||||
|
||||
## Added
|
||||
|
||||
- Support for re-running setup and shopper tests
|
||||
|
||||
## Fixed
|
||||
|
||||
- Checkout create account test would fail if configuration value `addresses.customer.billing.email` was not `john.doe@example.com`
|
||||
|
||||
# 0.1.3
|
||||
|
||||
## Added
|
||||
|
|
|
@ -30,6 +30,11 @@ runShopperTests();
|
|||
|
||||
```
|
||||
|
||||
## Retrying/Re-running tests
|
||||
|
||||
On a new site, the setup and activation tests prepare the site for the remainder of the tests. To retry/rerun the test suite on a site where setup/onboarding test have already run use the environment variable `E2E_RETEST=1`.
|
||||
|
||||
|
||||
## Test functions
|
||||
|
||||
The functions to access the core tests are:
|
||||
|
|
|
@ -1,22 +1,44 @@
|
|||
/* eslint-disable jest/no-export, jest/no-disabled-tests */
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
const {
|
||||
merchant,
|
||||
completeOnboardingWizard,
|
||||
withRestApi,
|
||||
addShippingZoneAndMethod,
|
||||
IS_RETEST_MODE,
|
||||
} = require( '@woocommerce/e2e-utils' );
|
||||
|
||||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
const config = require( 'config' );
|
||||
const {
|
||||
it,
|
||||
describe,
|
||||
} = require( '@jest/globals' );
|
||||
|
||||
const shippingZoneNameUS = config.get( 'addresses.customer.shipping.country' );
|
||||
|
||||
const runOnboardingFlowTest = () => {
|
||||
describe('Store owner can go through store Onboarding', () => {
|
||||
if ( IS_RETEST_MODE ) {
|
||||
it('can reset onboarding to default settings', async () => {
|
||||
await withRestApi.resetOnboarding();
|
||||
});
|
||||
|
||||
it('can reset shipping zones to default settings', async () => {
|
||||
await withRestApi.deleteAllShippingZones();
|
||||
});
|
||||
|
||||
it('can reset to default settings', async () => {
|
||||
await withRestApi.resetSettingsGroupToDefault('general');
|
||||
await withRestApi.resetSettingsGroupToDefault('products');
|
||||
await withRestApi.resetSettingsGroupToDefault('tax');
|
||||
});
|
||||
}
|
||||
|
||||
it('can start and complete onboarding when visiting the site for the first time.', async () => {
|
||||
await merchant.runSetupWizard();
|
||||
|
@ -33,24 +55,26 @@ const runTaskListTest = () => {
|
|||
});
|
||||
// Query for all tasks on the list
|
||||
const taskListItems = await page.$$('.woocommerce-list__item-title');
|
||||
expect(taskListItems).toHaveLength(6);
|
||||
expect(taskListItems.length).toBeInRange( 5, 6 );
|
||||
|
||||
const [ setupTaskListItem ] = await page.$x( '//div[contains(text(),"Set up shipping")]' );
|
||||
await Promise.all([
|
||||
// Work around for https://github.com/woocommerce/woocommerce-admin/issues/6761
|
||||
if ( taskListItems.length == 6 ) {
|
||||
// Click on "Set up shipping" task to move to the next step
|
||||
setupTaskListItem.click(),
|
||||
const [ setupTaskListItem ] = await page.$x( '//div[contains(text(),"Set up shipping")]' );
|
||||
await setupTaskListItem.click();
|
||||
await page.waitForNavigation({waitUntil: 'networkidle0'});
|
||||
|
||||
// Wait for shipping setup section to load
|
||||
page.waitForNavigation({waitUntil: 'networkidle0'}),
|
||||
]);
|
||||
// Wait for "Proceed" button to become active
|
||||
await page.waitForSelector('button.is-primary:not(:disabled)');
|
||||
await page.waitFor(3000);
|
||||
|
||||
// Wait for "Proceed" button to become active
|
||||
await page.waitForSelector('button.is-primary:not(:disabled)');
|
||||
await page.waitFor(3000);
|
||||
|
||||
// Click on "Proceed" button to save shipping settings
|
||||
await page.click('button.is-primary');
|
||||
await page.waitFor(3000);
|
||||
// Click on "Proceed" button to save shipping settings
|
||||
await page.click('button.is-primary');
|
||||
await page.waitFor(3000);
|
||||
} else {
|
||||
await merchant.openNewShipping();
|
||||
await addShippingZoneAndMethod(shippingZoneNameUS);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
@ -6,7 +6,6 @@ const { HTTPClientFactory } = require( '@woocommerce/api' );
|
|||
const {
|
||||
it,
|
||||
describe,
|
||||
beforeAll,
|
||||
} = require( '@jest/globals' );
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
uiUnblocked,
|
||||
setCheckbox,
|
||||
settingsPageSaveChanges,
|
||||
withRestApi,
|
||||
} = require( '@woocommerce/e2e-utils' );
|
||||
|
||||
/**
|
||||
|
@ -22,14 +23,16 @@ const {
|
|||
|
||||
const config = require( 'config' );
|
||||
const simpleProductName = config.get( 'products.simple.name' );
|
||||
const customerBilling = config.get( 'addresses.customer.billing' );
|
||||
|
||||
const runCheckoutCreateAccountTest = () => {
|
||||
describe('Shopper Checkout Create Account', () => {
|
||||
beforeAll(async () => {
|
||||
await merchant.login();
|
||||
await createSimpleProduct();
|
||||
await withRestApi.deleteCustomerByEmail( customerBilling.email );
|
||||
|
||||
// Set checkbox for creating an account during checkout
|
||||
await merchant.login();
|
||||
await merchant.openSettings('account');
|
||||
await setCheckbox('#woocommerce_enable_signup_and_login_from_checkout');
|
||||
await settingsPageSaveChanges();
|
||||
|
@ -44,7 +47,7 @@ const runCheckoutCreateAccountTest = () => {
|
|||
|
||||
it('can create an account during checkout', async () => {
|
||||
// Fill all the details for a new customer
|
||||
await shopper.fillBillingDetails(config.get('addresses.customer.billing'));
|
||||
await shopper.fillBillingDetails( customerBilling );
|
||||
await uiUnblocked();
|
||||
|
||||
// Set checkbox for creating account during checkout
|
||||
|
@ -58,7 +61,7 @@ const runCheckoutCreateAccountTest = () => {
|
|||
it('can verify that the customer has been created', async () => {
|
||||
await merchant.login();
|
||||
await merchant.openAllUsersView();
|
||||
await expect(page).toMatchElement('td.email.column-email > a', {text: 'john.doe@example.com'});
|
||||
await expect(page).toMatchElement('td.email.column-email > a', { text: customerBilling.email });
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
@ -7,25 +7,29 @@ const {
|
|||
merchant,
|
||||
setCheckbox,
|
||||
settingsPageSaveChanges,
|
||||
withRestApi,
|
||||
} = require( '@woocommerce/e2e-utils' );
|
||||
|
||||
const customerEmailAddress = 'john.doe.test@example.com';
|
||||
|
||||
const runMyAccountCreateAccountTest = () => {
|
||||
describe('Shopper My Account Create Account', () => {
|
||||
beforeAll(async () => {
|
||||
await withRestApi.deleteCustomerByEmail( customerEmailAddress );
|
||||
await merchant.login();
|
||||
|
||||
// Set checkbox in the settings to enable registration in my account
|
||||
await merchant.openSettings('account');
|
||||
await setCheckbox('#woocommerce_enable_myaccount_registration');
|
||||
await settingsPageSaveChanges();
|
||||
|
||||
|
||||
await merchant.logout();
|
||||
});
|
||||
|
||||
it('can create a new account via my account', async () => {
|
||||
await shopper.gotoMyAccount();
|
||||
await page.waitForSelector('.woocommerce-form-register');
|
||||
await expect(page).toFill('input#reg_email', 'john.doe.test@example.com');
|
||||
await expect(page).toFill('input#reg_email', customerEmailAddress);
|
||||
await expect(page).toClick('button[name="register"]');
|
||||
await page.waitForNavigation({waitUntil: 'networkidle0'});
|
||||
await expect(page).toMatchElement('h1', 'My account');
|
||||
|
@ -33,7 +37,7 @@ const runMyAccountCreateAccountTest = () => {
|
|||
// Verify user has been created successfully
|
||||
await merchant.login();
|
||||
await merchant.openAllUsersView();
|
||||
await expect(page).toMatchElement('td.email.column-email > a', {text: 'john.doe.test@example.com'});
|
||||
await expect(page).toMatchElement('td.email.column-email > a', {text: customerEmailAddress});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
# Unreleased
|
||||
|
||||
## Added
|
||||
|
||||
- `toBeInRange` expect numeric range matcher
|
||||
|
||||
# 0.2.1
|
||||
|
||||
|
|
|
@ -101,6 +101,23 @@ function removePageEvents() {
|
|||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an expect range matcher.
|
||||
* @see https://jestjs.io/docs/expect#expectextendmatchers
|
||||
*/
|
||||
expect.extend({
|
||||
toBeInRange: function (received, floor, ceiling) {
|
||||
const pass = received >= floor && received <= ceiling;
|
||||
const condition = pass ? 'not to be' : 'to be';
|
||||
|
||||
return {
|
||||
message: () =>
|
||||
`expected ${received} ${condition} within range ${floor} - ${ceiling}`,
|
||||
pass,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Adds a page event handler to emit uncaught exception to process if one of
|
||||
* the observed console logging types is encountered.
|
||||
|
|
|
@ -1,6 +1,15 @@
|
|||
# Unreleased
|
||||
|
||||
## Added
|
||||
|
||||
- `emptyCart()` Shopper flow helper that empties the cart
|
||||
- constants
|
||||
- `WP_ADMIN_POST_TYPE`
|
||||
- `WP_ADMIN_NEW_POST_TYPE`
|
||||
- `WP_ADMIN_ALL_COUPONS_VIEW`
|
||||
- `WP_ADMIN_WC_HOME`
|
||||
- `IS_RETEST_MODE`
|
||||
- `withRestApi` flow containing utility functions that manage data with the rest api
|
||||
|
||||
# 0.1.4
|
||||
|
||||
|
|
|
@ -31,6 +31,50 @@ describe( 'Cart page', () => {
|
|||
} );
|
||||
~~~
|
||||
|
||||
### Retries
|
||||
|
||||
This package provides support for enabling retries in tests:
|
||||
|
||||
- In the test environment set `E2E_RETEST=1`.
|
||||
- To add conditional logic to your tests use the boolean constant `IS_RETEST_MODE`.
|
||||
|
||||
### Available constants
|
||||
|
||||
#### Dashboard
|
||||
|
||||
- `WP_ADMIN_LOGIN` - WordPress login
|
||||
- `WP_ADMIN_DASHBOARD` - WordPress dashboard
|
||||
- `WP_ADMIN_PLUGINS` - Plugin list
|
||||
- `WP_ADMIN_PERMALINK_SETTINGS` - Permalink settings
|
||||
- `WP_ADMIN_ALL_USERS_VIEW` - WordPress user list
|
||||
- `WP_ADMIN_POST_TYPE` - Post listing
|
||||
- `WP_ADMIN_NEW_POST_TYPE` - New post
|
||||
- `WP_ADMIN_ALL_COUPONS_VIEW` - Coupons list
|
||||
- `WP_ADMIN_NEW_COUPON` - New coupon
|
||||
- `WP_ADMIN_ALL_ORDERS_VIEW` - Orders list
|
||||
- `WP_ADMIN_NEW_ORDER` - New Order
|
||||
- `WP_ADMIN_ALL_PRODUCTS_VIEW` - Products list
|
||||
- `WP_ADMIN_NEW_PRODUCT` - New product
|
||||
- `WP_ADMIN_IMPORT_PRODUCTS` - Import products
|
||||
- `WP_ADMIN_PLUGIN_PAGE` - Plugin settings page root
|
||||
- `WP_ADMIN_WC_HOME` - WooCommerce home screen
|
||||
- `WP_ADMIN_SETUP_WIZARD` - WooCommerce setup/onboarding wizard
|
||||
- `WP_ADMIN_ANALYTICS_PAGES` - WooCommerce analytics page root
|
||||
- `WP_ADMIN_WC_SETTINGS` - WooCommerce settings page root
|
||||
- `WP_ADMIN_NEW_SHIPPING_ZONE` - WooCommerce new shipping zone
|
||||
|
||||
#### Front end
|
||||
|
||||
- `SHOP_PAGE` - Shop page
|
||||
- `SHOP_PRODUCT_PAGE` - Single product page
|
||||
- `SHOP_CART_PAGE` - Cart page
|
||||
- `SHOP_CHECKOUT_PAGE` - Checkout page
|
||||
- `SHOP_MY_ACCOUNT_PAGE` - Customer account page
|
||||
- `MY_ACCOUNT_ORDERS` - Customer orders
|
||||
- `MY_ACCOUNT_DOWNLOADS` - Customer downloads
|
||||
- `MY_ACCOUNT_ADDRESSES` - Customer addresses
|
||||
- `MY_ACCOUNT_ACCOUNT_DETAILS` - Customer account details
|
||||
|
||||
## Test Function
|
||||
|
||||
### Merchant `merchant`
|
||||
|
@ -82,6 +126,17 @@ describe( 'Cart page', () => {
|
|||
| `searchForProduct` | | Searching for a product name and landing on its detail page |
|
||||
| `emptyCart` | | Removes any products and coupons that are in the cart |
|
||||
|
||||
### REST API `withRestApi`
|
||||
|
||||
| Function | Parameters | Description |
|
||||
|----------|------------|-------------|
|
||||
| `resetOnboarding` | | Reset onboarding settings |
|
||||
| `deleteAllCoupons` | | Permanently delete all coupons |
|
||||
| `deleteAllProducts` | | Permanently delete all products |
|
||||
| `deleteAllShippingZones` | | Permanently delete all shipping zones except the default |
|
||||
| `deleteCustomerByEmail` | `emailAddress` | Delete customer user account. Posts are reassigned to user ID 1 |
|
||||
| `resetSettingsGroupToDefault` | `settingsGroup` | Reset settings in settings group to default except `select` fields |
|
||||
|
||||
### Page Utilities
|
||||
|
||||
| Function | Parameters | Description |
|
||||
|
|
|
@ -5,14 +5,15 @@
|
|||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { merchant } from './flows';
|
||||
import { merchant, IS_RETEST_MODE } from './flows';
|
||||
import {
|
||||
clickTab,
|
||||
uiUnblocked,
|
||||
verifyCheckboxIsUnset,
|
||||
selectOptionInSelect2,
|
||||
setCheckbox,
|
||||
unsetCheckbox
|
||||
unsetCheckbox,
|
||||
clearAndFillInput,
|
||||
} from './page-utils';
|
||||
import factories from './factories';
|
||||
|
||||
|
@ -81,23 +82,20 @@ const completeOnboardingWizard = async () => {
|
|||
// Click on "Continue" button to move to the next step
|
||||
await page.click( 'button.is-primary', { text: 'Continue' } );
|
||||
|
||||
// Wait for usage tracking pop-up window to appear
|
||||
await page.waitForSelector( '.components-modal__header-heading' );
|
||||
await expect( page ).toMatchElement(
|
||||
'.components-modal__header-heading', { text: 'Build a better WooCommerce' }
|
||||
);
|
||||
// Wait for usage tracking pop-up window to appear on a new site
|
||||
if ( ! IS_RETEST_MODE ) {
|
||||
await page.waitForSelector('.components-modal__header-heading');
|
||||
await expect(page).toMatchElement(
|
||||
'.components-modal__header-heading', {text: 'Build a better WooCommerce'}
|
||||
);
|
||||
|
||||
// Query for "Continue" buttons
|
||||
const continueButtons = await page.$$( 'button.is-primary' );
|
||||
expect( continueButtons ).toHaveLength( 2 );
|
||||
// Query for "Continue" buttons
|
||||
const continueButtons = await page.$$( 'button.is-primary' );
|
||||
expect( continueButtons ).toHaveLength( 2 );
|
||||
|
||||
await Promise.all( [
|
||||
// Click on "Continue" button of the usage pop-up window to move to the next step
|
||||
continueButtons[1].click(),
|
||||
|
||||
// Wait for "In which industry does the store operate?" section to load
|
||||
page.waitForNavigation( { waitUntil: 'networkidle0' } ),
|
||||
] );
|
||||
await continueButtons[1].click();
|
||||
}
|
||||
await page.waitForNavigation( { waitUntil: 'networkidle0' } );
|
||||
|
||||
// Industry section
|
||||
|
||||
|
@ -158,6 +156,10 @@ const completeOnboardingWizard = async () => {
|
|||
await waitAndClickPrimary();
|
||||
|
||||
// End of onboarding wizard
|
||||
if ( IS_RETEST_MODE ) {
|
||||
// Home screen modal can't be reset via the rest api.
|
||||
return;
|
||||
}
|
||||
|
||||
// Wait for homescreen welcome modal to appear
|
||||
await page.waitForSelector( '.woocommerce__welcome-modal__page-content__header' );
|
||||
|
|
|
@ -2,32 +2,60 @@
|
|||
* External dependencies
|
||||
*/
|
||||
const config = require( 'config' );
|
||||
|
||||
const baseUrl = config.get( 'url' );
|
||||
|
||||
/**
|
||||
* WordPress core dashboard pages.
|
||||
* @type {string}
|
||||
*/
|
||||
export const WP_ADMIN_LOGIN = baseUrl + 'wp-login.php';
|
||||
export const WP_ADMIN_DASHBOARD = baseUrl + 'wp-admin';
|
||||
export const WP_ADMIN_PLUGINS = baseUrl + 'wp-admin/plugins.php';
|
||||
export const WP_ADMIN_SETUP_WIZARD = baseUrl + 'wp-admin/admin.php?page=wc-admin';
|
||||
export const WP_ADMIN_ALL_ORDERS_VIEW = baseUrl + 'wp-admin/edit.php?post_type=shop_order';
|
||||
export const WP_ADMIN_ALL_PRODUCTS_VIEW = baseUrl + 'wp-admin/edit.php?post_type=product';
|
||||
export const WP_ADMIN_NEW_COUPON = baseUrl + 'wp-admin/post-new.php?post_type=shop_coupon';
|
||||
export const WP_ADMIN_NEW_ORDER = baseUrl + 'wp-admin/post-new.php?post_type=shop_order';
|
||||
export const WP_ADMIN_NEW_PRODUCT = baseUrl + 'wp-admin/post-new.php?post_type=product';
|
||||
export const WP_ADMIN_WC_SETTINGS = baseUrl + 'wp-admin/admin.php?page=wc-settings&tab=';
|
||||
export const WP_ADMIN_PERMALINK_SETTINGS = baseUrl + 'wp-admin/options-permalink.php';
|
||||
export const WP_ADMIN_NEW_SHIPPING_ZONE = baseUrl + 'wp-admin/admin.php?page=wc-settings&tab=shipping&zone_id=new';
|
||||
export const WP_ADMIN_ANALYTICS_PAGES = baseUrl + 'wp-admin/admin.php?page=wc-admin&path=%2Fanalytics%2F';
|
||||
export const WP_ADMIN_ALL_USERS_VIEW = baseUrl + 'wp-admin/users.php';
|
||||
export const WP_ADMIN_IMPORT_PRODUCTS = baseUrl + 'wp-admin/edit.php?post_type=product&page=product_importer';
|
||||
|
||||
export const WP_ADMIN_DASHBOARD = baseUrl + 'wp-admin/';
|
||||
export const WP_ADMIN_PLUGINS = WP_ADMIN_DASHBOARD + 'plugins.php';
|
||||
export const WP_ADMIN_PERMALINK_SETTINGS = WP_ADMIN_DASHBOARD + 'options-permalink.php';
|
||||
export const WP_ADMIN_ALL_USERS_VIEW = WP_ADMIN_DASHBOARD + 'users.php';
|
||||
/**
|
||||
* WooCommerce core post type pages.
|
||||
* @type {string}
|
||||
*/
|
||||
export const WP_ADMIN_POST_TYPE = WP_ADMIN_DASHBOARD + 'edit.php?post_type=';
|
||||
export const WP_ADMIN_NEW_POST_TYPE = WP_ADMIN_DASHBOARD + 'post-new.php?post_type=';
|
||||
export const WP_ADMIN_ALL_COUPONS_VIEW = WP_ADMIN_POST_TYPE + 'shop_coupon';
|
||||
export const WP_ADMIN_NEW_COUPON = WP_ADMIN_NEW_POST_TYPE + 'shop_coupon';
|
||||
export const WP_ADMIN_ALL_ORDERS_VIEW = WP_ADMIN_POST_TYPE + 'shop_order';
|
||||
export const WP_ADMIN_NEW_ORDER = WP_ADMIN_NEW_POST_TYPE + 'shop_order';
|
||||
export const WP_ADMIN_ALL_PRODUCTS_VIEW = WP_ADMIN_POST_TYPE + 'product';
|
||||
export const WP_ADMIN_NEW_PRODUCT = WP_ADMIN_NEW_POST_TYPE + 'product';
|
||||
export const WP_ADMIN_IMPORT_PRODUCTS = WP_ADMIN_ALL_PRODUCTS_VIEW + '&page=product_importer';
|
||||
/**
|
||||
* WooCommerce settings pages.
|
||||
* @type {string}
|
||||
*/
|
||||
export const WP_ADMIN_PLUGIN_PAGE = WP_ADMIN_DASHBOARD + 'admin.php?page=';
|
||||
export const WP_ADMIN_WC_HOME = WP_ADMIN_PLUGIN_PAGE + 'wc-admin';
|
||||
export const WP_ADMIN_SETUP_WIZARD = WP_ADMIN_WC_HOME + '&path=%2Fsetup-wizard';
|
||||
export const WP_ADMIN_ANALYTICS_PAGES = WP_ADMIN_WC_HOME + '&path=%2Fanalytics%2F';
|
||||
export const WP_ADMIN_WC_SETTINGS = WP_ADMIN_PLUGIN_PAGE + 'wc-settings&tab=';
|
||||
export const WP_ADMIN_NEW_SHIPPING_ZONE = WP_ADMIN_WC_SETTINGS + 'shipping&zone_id=new';
|
||||
/**
|
||||
* Shop pages.
|
||||
* @type {string}
|
||||
*/
|
||||
export const SHOP_PAGE = baseUrl + 'shop';
|
||||
export const SHOP_PRODUCT_PAGE = baseUrl + '?p=';
|
||||
export const SHOP_CART_PAGE = baseUrl + 'cart';
|
||||
export const SHOP_CHECKOUT_PAGE = baseUrl + 'checkout/';
|
||||
export const SHOP_MY_ACCOUNT_PAGE = baseUrl + 'my-account/';
|
||||
/**
|
||||
* Customer account pages.
|
||||
* @type {string}
|
||||
*/
|
||||
export const MY_ACCOUNT_ORDERS = SHOP_MY_ACCOUNT_PAGE + 'orders';
|
||||
export const MY_ACCOUNT_DOWNLOADS = SHOP_MY_ACCOUNT_PAGE + 'downloads';
|
||||
export const MY_ACCOUNT_ADDRESSES = SHOP_MY_ACCOUNT_PAGE + 'edit-address';
|
||||
export const MY_ACCOUNT_ACCOUNT_DETAILS = SHOP_MY_ACCOUNT_PAGE + 'edit-account';
|
||||
|
||||
export const MY_ACCOUNT_ORDERS = baseUrl + 'my-account/orders';
|
||||
export const MY_ACCOUNT_DOWNLOADS = baseUrl + 'my-account/downloads';
|
||||
export const MY_ACCOUNT_ADDRESSES = baseUrl + 'my-account/edit-address';
|
||||
export const MY_ACCOUNT_ACCOUNT_DETAILS = baseUrl + 'my-account/edit-account';
|
||||
/**
|
||||
* Test control flags.
|
||||
* @type {boolean}
|
||||
*/
|
||||
export const IS_RETEST_MODE = process.env.E2E_RETEST == '1';
|
||||
|
|
|
@ -5,10 +5,12 @@ const flowConstants = require( './constants' );
|
|||
const flowExpressions = require( './expressions' );
|
||||
const merchant = require( './merchant' );
|
||||
const shopper = require( './shopper' );
|
||||
const { withRestApi } = require( './with-rest-api' );
|
||||
|
||||
module.exports = {
|
||||
...flowConstants,
|
||||
...flowExpressions,
|
||||
merchant,
|
||||
shopper,
|
||||
withRestApi,
|
||||
};
|
||||
|
|
|
@ -18,11 +18,13 @@ const {
|
|||
WP_ADMIN_PERMALINK_SETTINGS,
|
||||
WP_ADMIN_PLUGINS,
|
||||
WP_ADMIN_SETUP_WIZARD,
|
||||
WP_ADMIN_WC_HOME,
|
||||
WP_ADMIN_WC_SETTINGS,
|
||||
WP_ADMIN_NEW_SHIPPING_ZONE,
|
||||
WP_ADMIN_ANALYTICS_PAGES,
|
||||
WP_ADMIN_ALL_USERS_VIEW,
|
||||
WP_ADMIN_IMPORT_PRODUCTS,
|
||||
WP_ADMIN_IMPORT_PRODUCTS,
|
||||
IS_RETEST_MODE,
|
||||
} = require( './constants' );
|
||||
|
||||
const baseUrl = config.get( 'url' );
|
||||
|
@ -120,7 +122,8 @@ const merchant = {
|
|||
},
|
||||
|
||||
runSetupWizard: async () => {
|
||||
await page.goto( WP_ADMIN_SETUP_WIZARD, {
|
||||
const setupWizard = IS_RETEST_MODE ? WP_ADMIN_SETUP_WIZARD : WP_ADMIN_WC_HOME;
|
||||
await page.goto( setupWizard, {
|
||||
waitUntil: 'networkidle0',
|
||||
} );
|
||||
},
|
||||
|
|
|
@ -0,0 +1,149 @@
|
|||
import factories from '../factories';
|
||||
import {Coupon, Setting, SimpleProduct} from '@woocommerce/api';
|
||||
|
||||
const client = factories.api.withDefaultPermalinks;
|
||||
const onboardingProfileEndpoint = '/wc-admin/onboarding/profile';
|
||||
const shippingZoneEndpoint = '/wc/v3/shipping/zones';
|
||||
const userEndpoint = '/wp/v2/users';
|
||||
|
||||
/**
|
||||
* Utility function to delete all merchant created data store objects.
|
||||
*
|
||||
* @param repository
|
||||
* @param defaultObjectId
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const deleteAllRepositoryObjects = async ( repository, defaultObjectId = null ) => {
|
||||
let objects;
|
||||
const minimum = defaultObjectId == null ? 0 : 1;
|
||||
|
||||
objects = await repository.list();
|
||||
while ( objects.length > minimum ) {
|
||||
for (let o = 0; o < objects.length; o++ ) {
|
||||
// Skip default data store object
|
||||
if ( objects[ o ].id == defaultObjectId ) {
|
||||
continue;
|
||||
}
|
||||
await repository.delete( objects[ o ].id );
|
||||
}
|
||||
objects = await repository.list();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Utility functions that use the REST API to process the requested function.
|
||||
*/
|
||||
export const withRestApi = {
|
||||
/**
|
||||
* Reset onboarding to equivalent of new site.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
resetOnboarding: async () => {
|
||||
const onboardingReset = {
|
||||
completed: false,
|
||||
industry: [],
|
||||
business_extensions: [],
|
||||
skipped: false,
|
||||
product_types: [],
|
||||
product_count: '0',
|
||||
selling_venues: 'no',
|
||||
revenue: 'none',
|
||||
theme: '',
|
||||
setup_client: false,
|
||||
wccom_connected: false,
|
||||
};
|
||||
|
||||
const response = await client.put( onboardingProfileEndpoint, onboardingReset );
|
||||
expect( response.statusCode ).toEqual( 200 );
|
||||
},
|
||||
/**
|
||||
* Use api package to delete coupons.
|
||||
*
|
||||
* @return {Promise} Promise resolving once coupons have been deleted.
|
||||
*/
|
||||
deleteAllCoupons: async () => {
|
||||
const repository = Coupon.restRepository( client );
|
||||
await deleteAllRepositoryObjects( repository );
|
||||
},
|
||||
/**
|
||||
* Use api package to delete products.
|
||||
*
|
||||
* @return {Promise} Promise resolving once products have been deleted.
|
||||
*/
|
||||
deleteAllProducts: async () => {
|
||||
const repository = SimpleProduct.restRepository( client );
|
||||
await deleteAllRepositoryObjects( repository );
|
||||
},
|
||||
/**
|
||||
* Use api package to delete shipping zones.
|
||||
*
|
||||
* @return {Promise} Promise resolving once shipping zones have been deleted.
|
||||
*/
|
||||
deleteAllShippingZones: async () => {
|
||||
const shippingZones = await client.get( shippingZoneEndpoint );
|
||||
if ( shippingZones.data && shippingZones.data.length ) {
|
||||
for ( let z = 0; z < shippingZones.data.length; z++ ) {
|
||||
// The data store doesn't support deleting the default zone.
|
||||
if ( shippingZones.data[z].id == 0 ) {
|
||||
continue;
|
||||
}
|
||||
const response = await client.delete( shippingZoneEndpoint + `/${shippingZones.data[z].id}?force=true` );
|
||||
expect( response.statusCode ).toBe( 200 );
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Delete a customer account by their email address if the user exists.
|
||||
*
|
||||
* @param emailAddress Customer user account email address.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
deleteCustomerByEmail: async ( emailAddress ) => {
|
||||
const query = {
|
||||
search: emailAddress,
|
||||
context: 'edit',
|
||||
};
|
||||
const customers = await client.get( userEndpoint, query );
|
||||
|
||||
if ( customers.data && customers.data.length ) {
|
||||
for ( let c = 0; c < customers.data.length; c++ ) {
|
||||
const deleteUser = {
|
||||
id: customers.data[c].id,
|
||||
force: true,
|
||||
reassign: 1,
|
||||
}
|
||||
await client.delete( userEndpoint + `/${ deleteUser.id }`, deleteUser );
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Reset a settings group to default values except selects.
|
||||
* @param settingsGroup
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
resetSettingsGroupToDefault: async ( settingsGroup ) => {
|
||||
const settingsClient = Setting.restRepository( client );
|
||||
const settings = await settingsClient.list( settingsGroup );
|
||||
if ( ! settings.length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
for ( let s = 0; s < settings.length; s++ ) {
|
||||
// The rest api doesn't allow selects to be set to ''.
|
||||
if ( settings[s].type == 'select' && settings[s].default == '' ) {
|
||||
continue;
|
||||
}
|
||||
const defaultSetting = {
|
||||
group_id: settingsGroup,
|
||||
id: settings[s].id,
|
||||
value: settings[s].default,
|
||||
};
|
||||
|
||||
const response = await settingsClient.update( settingsGroup, defaultSetting.id, defaultSetting );
|
||||
// Multi-selects have a default '' but return an empty [].
|
||||
if ( settings[s].type != 'multiselect' ) {
|
||||
expect( response.value ).toBe( defaultSetting.value );
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue