diff --git a/tests/e2e-tests/specs/wp-admin/wp-admin-coupon-new.test.js b/tests/e2e-tests/specs/wp-admin/wp-admin-coupon-new.test.js new file mode 100644 index 00000000000..f5292ebb5ac --- /dev/null +++ b/tests/e2e-tests/specs/wp-admin/wp-admin-coupon-new.test.js @@ -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.' + ); + + } ); +} ); diff --git a/tests/e2e-tests/specs/wp-admin/wp-admin-order-new.test.js b/tests/e2e-tests/specs/wp-admin/wp-admin-order-new.test.js new file mode 100644 index 00000000000..57a1d0e72fe --- /dev/null +++ b/tests/e2e-tests/specs/wp-admin/wp-admin-order-new.test.js @@ -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.' + ); + } ); +} ); diff --git a/tests/e2e-tests/specs/wp-admin/wp-admin-product-new.test.js b/tests/e2e-tests/specs/wp-admin/wp-admin-product-new.test.js index 2306067e810..bbb916188a1 100644 --- a/tests/e2e-tests/specs/wp-admin/wp-admin-product-new.test.js +++ b/tests/e2e-tests/specs/wp-admin/wp-admin-product-new.test.js @@ -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.' + ); } ); } ); diff --git a/tests/e2e-tests/utils/flows.js b/tests/e2e-tests/utils/flows.js index fc5d06720f6..2194f849a98 100644 --- a/tests/e2e-tests/utils/flows.js +++ b/tests/e2e-tests/utils/flows.js @@ -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', diff --git a/tests/e2e-tests/utils/index.js b/tests/e2e-tests/utils/index.js index d79b004b789..bf4689d689f 100644 --- a/tests/e2e-tests/utils/index.js +++ b/tests/e2e-tests/utils/index.js @@ -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,