From 0b8d8d0e68269e4a3d853902b30dd210afc97ae9 Mon Sep 17 00:00:00 2001 From: Julia Amosova Date: Thu, 29 Aug 2019 17:09:42 +0100 Subject: [PATCH 1/2] Add 2 new Puppeteer e2e tests: new coupon & new order --- .../wp-admin/wp-admin-coupon-new.test.js | 47 +++++++++++++++++++ .../specs/wp-admin/wp-admin-order-new.test.js | 43 +++++++++++++++++ .../wp-admin/wp-admin-product-new.test.js | 39 +++++++-------- tests/e2e-tests/utils/flows.js | 14 ++++++ tests/e2e-tests/utils/index.js | 40 +++++++++++++++- 5 files changed, 160 insertions(+), 23 deletions(-) create mode 100644 tests/e2e-tests/specs/wp-admin/wp-admin-coupon-new.test.js create mode 100644 tests/e2e-tests/specs/wp-admin/wp-admin-order-new.test.js 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..4f2a017ecd8 --- /dev/null +++ b/tests/e2e-tests/specs/wp-admin/wp-admin-coupon-new.test.js @@ -0,0 +1,47 @@ +/** + * @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.', + 'Move to Trash', + '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..19c95de028d --- /dev/null +++ b/tests/e2e-tests/specs/wp-admin/wp-admin-order-new.test.js @@ -0,0 +1,43 @@ +/** + * @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.', + 'Move to trash', + '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 d29179cc093..2e48a6c3187 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 @@ -11,26 +11,7 @@ import { activatePlugin } from '@wordpress/e2e-test-utils'; * Internal dependencies */ import { StoreOwnerFlow } from '../../utils/flows'; -import { clickTab, uiUnblocked } from '../../utils'; - -const verifyPublishAndTrash = async () => { - // Wait for auto save - await page.waitFor( 2000 ); - - // Publish product - await expect( page ).toClick( '#publish' ); - await page.waitForSelector( '.updated.notice' ); - - // Verify - await expect( page ).toMatchElement( '.updated.notice', { text: 'Product published.' } ); - - // Trash product - await expect( page ).toClick( 'a', { text: 'Move to Trash' } ); - await page.waitForSelector( '#message' ); - - // Verify - await expect( page ).toMatchElement( '.updated.notice', { text: '1 product moved to the Trash.' } ); -}; +import { clickTab, uiUnblocked, verifyPublishAndTrash } from '../../utils'; describe( 'Add New Product Page', () => { beforeAll( async () => { @@ -50,7 +31,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 () => { @@ -135,6 +123,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 535d3371e00..233faead8fc 100644 --- a/tests/e2e-tests/utils/flows.js +++ b/tests/e2e-tests/utils/flows.js @@ -4,9 +4,23 @@ 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 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 7a5a3d64e29..f6490f920bb 100644 --- a/tests/e2e-tests/utils/index.js +++ b/tests/e2e-tests/utils/index.js @@ -6,7 +6,7 @@ const flows = require( './flows' ); /** * 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 } ); @@ -19,8 +19,46 @@ 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} moveToTrash + * @param {string} trashVerification + */ +const verifyPublishAndTrash = async ( button, publishNotice, publishVerification, moveToTrash, 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: moveToTrash } ); + await page.waitForSelector( '#message' ); + + // Verify + await expect( page ).toMatchElement( publishNotice, { text: trashVerification } ); +}; + module.exports = { ...flows, clickTab, uiUnblocked, + verifyPublishAndTrash, }; From 4ce07e9387deb0963d1af3f556a4b802b00c0ab1 Mon Sep 17 00:00:00 2001 From: Julia Amosova Date: Fri, 25 Oct 2019 11:40:54 +0200 Subject: [PATCH 2/2] Remove `moveToTrash` variable --- tests/e2e-tests/specs/wp-admin/wp-admin-coupon-new.test.js | 1 - tests/e2e-tests/specs/wp-admin/wp-admin-order-new.test.js | 1 - tests/e2e-tests/utils/index.js | 5 ++--- 3 files changed, 2 insertions(+), 5 deletions(-) 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 index 4f2a017ecd8..f5292ebb5ac 100644 --- 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 @@ -39,7 +39,6 @@ describe( 'Add New Coupon Page', () => { '#publish', '#message', 'Coupon updated.', - 'Move to Trash', '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 index 19c95de028d..57a1d0e72fe 100644 --- 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 @@ -36,7 +36,6 @@ describe( 'Add New Order Page', () => { '.order_actions li .save_order', '#message', 'Order updated.', - 'Move to trash', '1 order moved to the Trash.' ); } ); diff --git a/tests/e2e-tests/utils/index.js b/tests/e2e-tests/utils/index.js index f6490f920bb..821b0ac4e71 100644 --- a/tests/e2e-tests/utils/index.js +++ b/tests/e2e-tests/utils/index.js @@ -25,10 +25,9 @@ const uiUnblocked = async () => { * @param {string} button (Publish) * @param {string} publishNotice * @param {string} publishVerification - * @param {string} moveToTrash * @param {string} trashVerification */ -const verifyPublishAndTrash = async ( button, publishNotice, publishVerification, moveToTrash, trashVerification ) => { +const verifyPublishAndTrash = async ( button, publishNotice, publishVerification, trashVerification ) => { // Wait for auto save await page.waitFor( 2000 ); @@ -49,7 +48,7 @@ const verifyPublishAndTrash = async ( button, publishNotice, publishVerification } // Trash - await expect( page ).toClick( 'a', { text: moveToTrash } ); + await expect( page ).toClick( 'a', { text: "Move to Trash" } ); await page.waitForSelector( '#message' ); // Verify