Add new Puppeteer e2e test: tax settings

This commit is contained in:
Julia Amosova 2019-08-30 12:53:45 +01:00
parent fc24adce30
commit b7201e1363
3 changed files with 180 additions and 0 deletions

View File

@ -0,0 +1,137 @@
/**
* @format
*/
/**
* External dependencies
*/
import { activatePlugin } from '@wordpress/e2e-test-utils';
/**
* Internal dependencies
*/
import { StoreOwnerFlow } from '../../utils/flows';
import { clearAndFillInput, settingsPageSaveChanges, uiUnblocked } from "../../utils";
describe( 'WooCommerce Tax Settings', () => {
beforeAll( async () => {
await activatePlugin( 'woocommerce' );
} );
it( 'can enable tax calculation', async() => {
// Go to general settings page
await StoreOwnerFlow.openSettings( 'general' );
// Make sure the general tab is active
await expect( page ).toMatchElement( 'a.nav-tab-active', { text: 'General' } );
// Enable tax calculation
await expect( page ).toClick( '#woocommerce_calc_taxes' );
await settingsPageSaveChanges();
await expect( page ).toMatchElement( '#message', { text: 'Your settings have been saved.' } );
// Verify that tax settings are now present
await expect( page ).toMatchElement( 'a.nav-tab', { text: 'Tax' } );
} );
it( 'can set tax options', async () => {
// Go to tax settings page
await StoreOwnerFlow.openSettings( 'tax' );
// Make sure the tax tab is active
await expect( page ).toMatchElement( 'a.nav-tab-active', { text: 'Tax' } );
// Prices exclusive of tax
await expect( page ).toClick( 'input[name="woocommerce_prices_include_tax"][value="no"]' );
// Tax based on customer shipping address
await expect( page ).toSelect( '#woocommerce_tax_based_on', 'Customer shipping address' );
// Standard tax class for shipping
await expect( page ).toSelect( '#woocommerce_shipping_tax_class', 'Standard' );
// Leave rounding unchecked (no-op)
// Display prices excluding tax
await expect( page ).toSelect( '#woocommerce_tax_display_shop', 'Excluding tax' );
// Display prices including tax in cart and at checkout
await expect( page ).toSelect( '#woocommerce_tax_display_cart', 'Including tax' );
// Display a single tax total
await expect( page ).toSelect( '#woocommerce_tax_total_display', 'As a single total' );
await settingsPageSaveChanges();
await expect( page ).toMatchElement( '#message', { text: 'Your settings have been saved.' } );
} );
it( 'can add tax classes', async () => {
// Go to tax settings page
await StoreOwnerFlow.openSettings( 'tax' );
// Make sure the tax tab is active
await expect( page ).toMatchElement( 'a.nav-tab-active', { text: 'Tax' } );
// Remove additional tax classes
await clearAndFillInput( '#woocommerce_tax_classes', '' );
await settingsPageSaveChanges();
// Add a "fancy" tax class
await clearAndFillInput( '#woocommerce_tax_classes', 'Fancy' );
await settingsPageSaveChanges();
await expect( page ).toMatchElement( 'ul.subsubsub > li > a', { text: 'Fancy rates' } );
} );
it( 'can set rate settings', async () => {
// Go to "fancy" rates tax settings page
await StoreOwnerFlow.openSettings( 'tax', 'fancy' );
// Make sure the tax tab is active, with the "fancy" subsection
await expect( page ).toMatchElement( 'a.nav-tab-active', { text: 'Tax' } );
await expect( page ).toMatchElement( 'ul.subsubsub > li > a.current', { text: 'Fancy rates' } );
// Create a state tax
await expect( page ).toClick( '.wc_tax_rates a.insert' );
await expect( page ).toFill( 'input[name^="tax_rate_country[new-0"]', 'US' );
await expect( page ).toFill( 'input[name^="tax_rate_state[new-0"]', 'CA' );
await expect( page ).toFill( 'input[name^="tax_rate[new-0"]', '7.5' );
await expect( page ).toFill( 'input[name^="tax_rate_name[new-0"]', 'CA State Tax' );
// Create a federal tax
await expect( page ).toClick( '.wc_tax_rates a.insert' );
await expect( page ).toFill( 'input[name^="tax_rate_country[new-1"]', 'US' );
await expect( page ).toFill( 'input[name^="tax_rate[new-1"]', '1.5' );
await expect( page ).toFill( 'input[name^="tax_rate_priority[new-1"]', '2' );
await expect( page ).toFill( 'input[name^="tax_rate_name[new-1"]', 'Federal Tax' );
await expect( page ).toClick( 'input[name^="tax_rate_shipping[new-1"]' );
// Save changes (AJAX here)
await expect( page ).toClick( 'button.woocommerce-save-button' );
await uiUnblocked();
// Verify 2 tax rates
expect( await page.$$( '#rates tr' ) ).toHaveLength( 2 );
// Delete federal rate
await expect( page ).toClick( '#rates tr:nth-child(2) input' );
await expect( page ).toClick( '.wc_tax_rates a.remove_tax_rates' );
// Save changes (AJAX here)
await expect( page ).toClick( 'button.woocommerce-save-button' );
await uiUnblocked();
// Verify 1 rate
expect( await page.$$( '#rates tr' ) ).toHaveLength( 1 );
await expect( page ).toMatchElement(
'#rates tr:first-of-type input[name^="tax_rate_state"][value="CA"]'
);
} );
it( 'can remove tax classes', async () => {
// Go to tax settings page
await StoreOwnerFlow.openSettings( 'tax' );
// Make sure the tax tab is active
await expect( page ).toMatchElement( 'a.nav-tab-active', { text: 'Tax' } );
// Remove "fancy" tax class
await clearAndFillInput( '#woocommerce_tax_classes', ' ' );
await settingsPageSaveChanges();
await expect( page ).not.toMatchElement( 'ul.subsubsub > li > a', { text: 'Fancy rates' } );
await page.waitFor( 10000 );
} );
} );

View File

@ -5,6 +5,7 @@
const baseUrl = process.env.WP_BASE_URL;
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 = {
openNewProduct: async () => {
@ -12,6 +13,18 @@ const StoreOwnerFlow = {
waitUntil: 'networkidle0',
} );
},
openSettings: async ( tab, section = null ) => {
let settingsUrl = WP_ADMIN_WC_SETTINGS + tab;
if ( section ) {
settingsUrl += `&section=${ section }`;
}
await page.goto( settingsUrl, {
waitUntil: 'networkidle0',
} );
},
};
export { StoreOwnerFlow };

View File

@ -1,8 +1,25 @@
/**
* External dependencies
*/
import { pressKeyWithModifier } from '@wordpress/e2e-test-utils';
/**
* Internal dependencies
*/
const flows = require( './flows' );
/**
* Perform a "select all" and then fill a input.
*
* @param {string} selector
* @param {string} value
*/
const clearAndFillInput = async ( selector, value ) => {
await page.focus( selector );
await pressKeyWithModifier( 'primary', 'a' );
await page.type( selector, value );
};
/**
* Click a tab (on post type edit screen).
*
@ -12,6 +29,17 @@ const clickTab = async ( tabName ) => {
await expect( page ).toClick( '.wc-tabs > li > a', { text: tabName } );
};
/**
* Save changes on a WooCommerce settings page.
*/
const settingsPageSaveChanges = async () => {
await page.focus( 'button.woocommerce-save-button' );
await Promise.all( [
page.waitForNavigation( { waitUntil: 'networkidle0' } ),
page.click( 'button.woocommerce-save-button' ),
] );
};
/**
* Wait for UI blocking to end.
*/
@ -21,6 +49,8 @@ const uiUnblocked = async () => {
module.exports = {
...flows,
clearAndFillInput,
clickTab,
settingsPageSaveChanges,
uiUnblocked,
};