Added new tests for the merchant order refund flow

This commit is contained in:
zhongruige 2020-12-10 21:27:04 -07:00
parent 1add2556d6
commit 2caac87d03
9 changed files with 150 additions and 14 deletions

View File

@ -2,6 +2,7 @@
## Added ## Added
- Merchant Order Status Filter tests - Merchant Order Status Filter tests
- Merchant Order Refund tests
## Fixed ## Fixed

View File

@ -53,6 +53,7 @@ The functions to access the core tests are:
- `runProductSettingsTest` - Merchant can update product settings - `runProductSettingsTest` - Merchant can update product settings
- `runTaxSettingsTest` - Merchant can update tax settings - `runTaxSettingsTest` - Merchant can update tax settings
- `runOrderStatusFilterTest` - Merchant can filter orders by order status - `runOrderStatusFilterTest` - Merchant can filter orders by order status
- `runOrderRefundTest` - Merchant can refund an order
### Shopper ### Shopper

View File

@ -22,6 +22,7 @@ const runUpdateGeneralSettingsTest = require( './merchant/wp-admin-settings-gene
const runProductSettingsTest = require( './merchant/wp-admin-settings-product.test' ); const runProductSettingsTest = require( './merchant/wp-admin-settings-product.test' );
const runTaxSettingsTest = require( './merchant/wp-admin-settings-tax.test' ); const runTaxSettingsTest = require( './merchant/wp-admin-settings-tax.test' );
const runOrderStatusFiltersTest = require( './merchant/wp-admin-order-status-filters.test' ); const runOrderStatusFiltersTest = require( './merchant/wp-admin-order-status-filters.test' );
const runOrderRefundTest = require( './merchant/wp-admin-order-refund.test' );
const runSetupOnboardingTests = () => { const runSetupOnboardingTests = () => {
runActivationTest(); runActivationTest();
@ -46,6 +47,7 @@ const runMerchantTests = () => {
runProductSettingsTest(); runProductSettingsTest();
runTaxSettingsTest(); runTaxSettingsTest();
runOrderStatusFiltersTest(); runOrderStatusFiltersTest();
runOrderRefundTest();
} }
module.exports = { module.exports = {
@ -67,5 +69,6 @@ module.exports = {
runProductSettingsTest, runProductSettingsTest,
runTaxSettingsTest, runTaxSettingsTest,
runOrderStatusFiltersTest, runOrderStatusFiltersTest,
runOrderRefundTest,
runMerchantTests, runMerchantTests,
}; };

View File

@ -0,0 +1,71 @@
/* eslint-disable jest/no-export, jest/no-disabled-tests, jest/no-standalone-expect */
/**
* Internal dependencies
*/
const {
StoreOwnerFlow,
createSimpleProduct,
createSimpleOrder,
verifyCheckboxIsSet,
verifyValueOfInputField,
uiUnblocked,
addProductToOrder,
} = require( '@woocommerce/e2e-utils' );
const config = require( 'config' );
const simpleProductName = config.get( 'products.simple.name' );
let orderId;
const runRefundOrderTest = () => {
describe('WooCommerce Orders > Refund an order', () => {
beforeAll(async () => {
await StoreOwnerFlow.login();
await createSimpleProduct();
orderId = await createSimpleOrder();
await addProductToOrder(orderId, simpleProductName);
// Update order status to `Completed` so we can issue a refund
await StoreOwnerFlow.updateOrderStatus(orderId, 'Completed');
});
it('can issue a refund by quantity', async () => {
// Click the Refund button
await expect(page).toClick('button.refund-items');
// Verify the refund section shows
await page.waitForSelector('div.wc-order-refund-items', { visible: true });
await verifyCheckboxIsSet('#restock_refunded_items');
// Initiate a refund
await expect(page).toFill('.refund_order_item_qty', '1');
await expect(page).toFill('#refund_reason', 'No longer wanted');
await Promise.all([
verifyValueOfInputField('.refund_line_total', '9.99'),
verifyValueOfInputField('#refund_amount', '9.99'),
expect(page).toMatchElement('.do-manual-refund', { text: 'Refund £9.99 manually' }),
]);
await expect(page).toClick('.do-manual-refund');
await uiUnblocked();
await Promise.all([
// Verify the product line item shows the refunded quantity and amount
expect(page).toMatchElement('.quantity .refunded', { text: '-1' }),
expect(page).toMatchElement('.line_cost .refunded', { text: '-£9.99' }),
// Verify the refund shows in the list with the amount
expect(page).toMatchElement('.refund .description', { text: 'No longer wanted' }),
expect(page).toMatchElement('.refund > .line_cost', { text: '-£9.99' }),
]);
});
});
};
module.exports = runRefundOrderTest;

View File

@ -0,0 +1,6 @@
/*
* Internal dependencies
*/
const { runOrderRefundTest } = require( '@woocommerce/e2e-core-tests' );
runOrderRefundTest();

View File

@ -9,6 +9,11 @@
- `clickFilter()` util helper method that clicks on a list page filter - `clickFilter()` util helper method that clicks on a list page filter
- `moveAllItemsToTrash()` util helper method that checks every item in a list page and moves them to the trash - `moveAllItemsToTrash()` util helper method that checks every item in a list page and moves them to the trash
- `createSimpleOrder( status )` component which accepts an order status string and creates a basic order with that status - `createSimpleOrder( status )` component which accepts an order status string and creates a basic order with that status
- `addProductToOrder( orderId, productName )` component which adds the provided productName to the passed in orderId
## Changes
- `createSimpleOrder( status )` returns the ID of the order that was created
# 0.1.1 # 0.1.1

View File

@ -38,20 +38,22 @@ describe( 'Cart page', () => {
### Merchant `StoreOwnerFlow` ### Merchant `StoreOwnerFlow`
| Function | Description | | Function | Parameters | Description |
|----------|-------------| |----------|-------------|------------|
| `login` | Log in as merchant | | `login` | | Log in as merchant |
| `logout` | log out of merchant account | | `logout` | | Log out of merchant account |
| `openAllOrdersView` | Go to the orders listing | | `openAllOrdersView` | | Go to the orders listing |
| `openDashboard` | Go to the WordPress dashboard | | `openDashboard` | | Go to the WordPress dashboard |
| `openNewCoupon` | Go to the new coupon editor | | `openNewCoupon` | | Go to the new coupon editor |
| `openNewOrder` | Go to the new order editor | | `openNewOrder` | | Go to the new order editor |
| `openNewProduct` | Go to the new product editor | | `openNewProduct` | | Go to the new product editor |
| `openPermalinkSettings` | Go to Settings -> Permalinks | | `openPermalinkSettings` | | Go to Settings -> Permalinks |
| `openPlugins` | Go to the Plugins screen | | `openPlugins` | | Go to the Plugins screen |
| `openSettings` | Go to WooCommerce -> Settings | | `openSettings` | | Go to WooCommerce -> Settings |
| `runSetupWizard` | Open the onboarding profiler | | `runSetupWizard` | | Open the onboarding profiler |
|----------|-------------| | `goToOrder` | `orderId` | Go to view a single order |
| `updateOrderStatus` | `orderId, status` | Update the status of an order |
|----------|-------------|-------------|
### Shopper `CustomerFlow` ### Shopper `CustomerFlow`

View File

@ -368,12 +368,41 @@ const createSimpleOrder = async ( orderStatus = 'Pending payment' ) => {
// Verify // Verify
await expect( page ).toMatchElement( '#message', { text: 'Order updated.' } ); await expect( page ).toMatchElement( '#message', { text: 'Order updated.' } );
const variablePostId = await page.$( '#post_ID' );
let variablePostIdValue = ( await ( await variablePostId.getProperty( 'value' ) ).jsonValue() );
return variablePostIdValue;
}; };
/**
* Adds a product to an order in the StoreOwnerFlow.
*
* @param orderId ID of the order to add the product to.
* @param productName Name of the product being added to the order.
*/
const addProductToOrder = async ( orderId, productName ) => {
await StoreOwnerFlow.goToOrder( orderId );
// Add a product to the order
await expect( page ).toClick( 'button.add-line-item' );
await expect( page ).toClick( 'button.add-order-item' );
await page.waitForSelector( '.wc-backbone-modal-header' );
await expect( page ).toClick( '.wc-backbone-modal-content .wc-product-search' );
await expect( page ).toFill( '#wc-backbone-modal-dialog + .select2-container .select2-search__field', productName );
await expect( page ).toClick( 'li[aria-selected="true"]' );
await page.click( '.wc-backbone-modal-content #btn-ok' );
await uiUnblocked();
// Verify the product we added shows as a line item now
await expect( page ).toMatchElement( '.wc-order-item-name', { text: productName } );
}
export { export {
completeOnboardingWizard, completeOnboardingWizard,
createSimpleProduct, createSimpleProduct,
createVariableProduct, createVariableProduct,
createSimpleOrder, createSimpleOrder,
verifyAndPublish, verifyAndPublish,
addProductToOrder,
}; };

View File

@ -25,6 +25,7 @@ const WP_ADMIN_NEW_ORDER = baseUrl + 'wp-admin/post-new.php?post_type=shop_order
const WP_ADMIN_NEW_PRODUCT = baseUrl + 'wp-admin/post-new.php?post_type=product'; const WP_ADMIN_NEW_PRODUCT = baseUrl + 'wp-admin/post-new.php?post_type=product';
const WP_ADMIN_WC_SETTINGS = baseUrl + 'wp-admin/admin.php?page=wc-settings&tab='; const WP_ADMIN_WC_SETTINGS = baseUrl + 'wp-admin/admin.php?page=wc-settings&tab=';
const WP_ADMIN_PERMALINK_SETTINGS = baseUrl + 'wp-admin/options-permalink.php'; const WP_ADMIN_PERMALINK_SETTINGS = baseUrl + 'wp-admin/options-permalink.php';
const WP_ADMIN_SINGLE_CPT_VIEW = ( postId ) => baseUrl + `wp-admin/post.php?post=${ postId }&action=edit`;
const SHOP_PAGE = baseUrl + 'shop'; const SHOP_PAGE = baseUrl + 'shop';
const SHOP_PRODUCT_PAGE = baseUrl + '?p='; const SHOP_PRODUCT_PAGE = baseUrl + '?p=';
@ -310,6 +311,23 @@ const StoreOwnerFlow = {
waitUntil: 'networkidle0', waitUntil: 'networkidle0',
} ); } );
}, },
goToOrder: async ( orderId ) => {
await page.goto( WP_ADMIN_SINGLE_CPT_VIEW( orderId ), {
waitUntil: 'networkidle0',
} );
},
updateOrderStatus: async ( orderId, status ) => {
await page.goto( WP_ADMIN_SINGLE_CPT_VIEW( orderId ), {
waitUntil: 'networkidle0',
} );
await expect( page ).toSelect( '#order_status', status );
await page.waitFor( 2000 );
await expect( page ).toClick( 'button.save_order' );
await page.waitForSelector( '#message' );
await expect( page ).toMatchElement( '#message', { text: 'Order updated.' } );
}
}; };
export { CustomerFlow, StoreOwnerFlow }; export { CustomerFlow, StoreOwnerFlow };