Merge pull request #24532 from woocommerce/new/wp-admin-new-order-coupon-e2e-test

Add 2 new Puppeteer e2e tests: new coupon & new order
This commit is contained in:
Julia Amosova 2019-10-25 12:19:47 +02:00 committed by GitHub
commit c7d81903ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 156 additions and 3 deletions

View File

@ -0,0 +1,46 @@
/**
* @format
*/
/**
* External dependencies
*/
import { activatePlugin } from '@wordpress/e2e-test-utils';
/**
* Internal dependencies
*/
import { StoreOwnerFlow } from '../../utils/flows';
import { clickTab, verifyPublishAndTrash } from "../../utils";
describe( 'Add New Coupon Page', () => {
beforeAll( async () => {
await activatePlugin( 'woocommerce' );
} );
it( 'can create new coupon', async () => {
// Go to "add coupon" page
await StoreOwnerFlow.openNewCoupon();
// Make sure we're on the add coupon page
await expect( page.title() ).resolves.toMatch( 'Add new coupon' );
// Fill in coupon code and description
await expect( page ).toFill( '#title', 'code-' + new Date().getTime().toString() );
await expect( page ).toFill( '#woocommerce-coupon-description', 'test coupon' );
// Set general coupon data
await clickTab( 'General' );
await expect( page ).toSelect( '#discount_type', 'Fixed cart discount' );
await expect( page ).toFill( '#coupon_amount', '100' );
// Publish coupon, verify that it was published. Trash coupon, verify that it was trashed.
await verifyPublishAndTrash(
'#publish',
'#message',
'Coupon updated.',
'1 coupon moved to the Trash.'
);
} );
} );

View File

@ -0,0 +1,42 @@
/**
* @format
*/
/**
* External dependencies
*/
import { activatePlugin } from '@wordpress/e2e-test-utils';
/**
* Internal dependencies
*/
import { StoreOwnerFlow } from '../../utils/flows';
import { verifyPublishAndTrash } from "../../utils";
describe( 'Add New Order Page', () => {
beforeAll( async () => {
await activatePlugin( 'woocommerce' );
} );
it( 'can create new order', async () => {
// Go to "add order" page
await StoreOwnerFlow.openNewOrder();
// Make sure we're on the add order page
await expect( page.title() ).resolves.toMatch( 'Add new order' );
// Set order data
await expect( page ).toSelect( '#order_status', 'Processing' );
await expect( page ).toFill( 'input[name=order_date]', '2018-12-13' );
await expect( page ).toFill( 'input[name=order_date_hour]', '18' );
await expect( page ).toFill( 'input[name=order_date_minute]', '55' );
// Create order, verify that it was created. Trash order, verify that it was trashed.
await verifyPublishAndTrash(
'.order_actions li .save_order',
'#message',
'Order updated.',
'1 order moved to the Trash.'
);
} );
} );

View File

@ -51,7 +51,14 @@ describe( 'Add New Product Page', () => {
await clickTab( 'General' );
await expect( page ).toFill( '#_regular_price', '9.99' );
await verifyPublishAndTrash();
// Publish product, verify that it was published. Trash product, verify that it was trashed.
await verifyPublishAndTrash(
'#publish',
'.updated.notice',
'Product published.',
'Move to Trash',
'1 product moved to the Trash.'
);
} );
it( 'can create product with variations', async () => {
@ -170,6 +177,13 @@ describe( 'Add New Product Page', () => {
await page.focus( 'button.save-variation-changes' );
await expect( page ).toClick( 'button.save-variation-changes', { text: 'Save changes' } );
await verifyPublishAndTrash();
// Publish product, verify that it was published. Trash product, verify that it was trashed.
await verifyPublishAndTrash(
'#publish',
'.updated.notice',
'Product published.',
'Move to Trash',
'1 product moved to the Trash.'
);
} );
} );

View File

@ -4,10 +4,24 @@
const baseUrl = process.env.WP_BASE_URL;
const WP_ADMIN_NEW_COUPON = baseUrl + '/wp-admin/post-new.php?post_type=shop_coupon';
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_WC_SETTINGS = baseUrl + '/wp-admin/admin.php?page=wc-settings&tab=';
const StoreOwnerFlow = {
openNewCoupon: async () => {
await page.goto( WP_ADMIN_NEW_COUPON, {
waitUntil: 'networkidle0',
} );
},
openNewOrder: async () => {
await page.goto( WP_ADMIN_NEW_ORDER, {
waitUntil: 'networkidle0',
} );
},
openNewProduct: async () => {
await page.goto( WP_ADMIN_NEW_PRODUCT, {
waitUntil: 'networkidle0',

View File

@ -23,7 +23,7 @@ const clearAndFillInput = async ( selector, value ) => {
/**
* Click a tab (on post type edit screen).
*
* @param {string} tabName Tab label.
* @param {string} tabName Tab label
*/
const clickTab = async ( tabName ) => {
await expect( page ).toClick( '.wc-tabs > li > a', { text: tabName } );
@ -75,6 +75,42 @@ const uiUnblocked = async () => {
await page.waitForFunction( () => ! Boolean( document.querySelector( '.blockUI' ) ) );
};
/**
* Publish, verify that item was published. Trash, verify that item was trashed.
*
* @param {string} button (Publish)
* @param {string} publishNotice
* @param {string} publishVerification
* @param {string} trashVerification
*/
const verifyPublishAndTrash = async ( button, publishNotice, publishVerification, trashVerification ) => {
// Wait for auto save
await page.waitFor( 2000 );
// Publish
await expect( page ).toClick( button );
await page.waitForSelector( publishNotice );
// Verify
await expect( page ).toMatchElement( publishNotice, { text: publishVerification } );
if ( button === '.order_actions li .save_order' ) {
await expect( page ).toMatchElement( '#select2-order_status-container', { text: 'Processing' } );
await expect( page ).toMatchElement(
'#woocommerce-order-notes .note_content',
{
text: 'Order status changed from Pending payment to Processing.',
}
);
}
// Trash
await expect( page ).toClick( 'a', { text: "Move to Trash" } );
await page.waitForSelector( '#message' );
// Verify
await expect( page ).toMatchElement( publishNotice, { text: trashVerification } );
};
/**
* Verify that checkbox is set.
*
@ -120,6 +156,7 @@ module.exports = {
setCheckbox,
unsetCheckbox,
uiUnblocked,
verifyPublishAndTrash,
verifyCheckboxIsSet,
verifyCheckboxIsUnset,
verifyValueOfInputField,