2019-08-30 11:53:45 +00:00
|
|
|
/**
|
|
|
|
* @format
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { StoreOwnerFlow } from '../../utils/flows';
|
2019-09-04 16:29:13 +00:00
|
|
|
import {
|
|
|
|
clearAndFillInput,
|
|
|
|
setCheckbox,
|
|
|
|
settingsPageSaveChanges,
|
|
|
|
uiUnblocked,
|
|
|
|
verifyCheckboxIsSet,
|
|
|
|
verifyValueOfInputField
|
2019-11-24 13:08:48 +00:00
|
|
|
} from '../../utils';
|
2019-08-30 11:53:45 +00:00
|
|
|
|
|
|
|
describe( 'WooCommerce Tax Settings', () => {
|
|
|
|
beforeAll( async () => {
|
2019-11-24 13:08:48 +00:00
|
|
|
await StoreOwnerFlow.login();
|
2019-08-30 11:53:45 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
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
|
2019-09-03 11:55:25 +00:00
|
|
|
await setCheckbox( 'input[name="woocommerce_calc_taxes"]' );
|
2019-08-30 11:53:45 +00:00
|
|
|
await settingsPageSaveChanges();
|
2019-09-04 16:29:13 +00:00
|
|
|
|
|
|
|
// Verify that settings have been saved
|
|
|
|
await Promise.all( [
|
|
|
|
expect( page ).toMatchElement( '#message', { text: 'Your settings have been saved.' } ),
|
|
|
|
verifyCheckboxIsSet( '#woocommerce_calc_taxes' ),
|
|
|
|
] );
|
2019-08-30 11:53:45 +00:00
|
|
|
|
|
|
|
// 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();
|
2019-09-04 16:29:13 +00:00
|
|
|
|
|
|
|
// Verify that settings have been saved
|
|
|
|
await Promise.all( [
|
|
|
|
expect( page ).toMatchElement( '#message', { text: 'Your settings have been saved.' } ),
|
|
|
|
verifyValueOfInputField( 'input[name="woocommerce_prices_include_tax"][value="no"]', 'no' ),
|
|
|
|
expect( page ).toMatchElement( '#woocommerce_tax_based_on', { text: 'Customer shipping address' } ),
|
|
|
|
expect( page ).toMatchElement( '#woocommerce_shipping_tax_class', { text: 'Standard' } ),
|
|
|
|
expect( page ).toMatchElement( '#woocommerce_tax_display_shop', { text: 'Excluding tax' } ),
|
|
|
|
expect( page ).toMatchElement( '#woocommerce_tax_display_cart', { text: 'Including tax' } ),
|
|
|
|
expect( page ).toMatchElement( '#woocommerce_tax_total_display', { text: 'As a single total' } ),
|
|
|
|
] );
|
2019-08-30 11:53:45 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2019-09-04 16:29:13 +00:00
|
|
|
// Verify that settings have been saved
|
|
|
|
await Promise.all( [
|
|
|
|
expect( page ).toMatchElement( '#message', { text: 'Your settings have been saved.' } ),
|
2019-10-20 20:52:53 +00:00
|
|
|
expect( page ).toMatchElement( '#woocommerce_tax_classes', { text: '' } ),
|
2019-09-04 16:29:13 +00:00
|
|
|
] );
|
|
|
|
|
2019-08-30 11:53:45 +00:00
|
|
|
// Add a "fancy" tax class
|
|
|
|
await clearAndFillInput( '#woocommerce_tax_classes', 'Fancy' );
|
|
|
|
await settingsPageSaveChanges();
|
2019-09-04 16:29:13 +00:00
|
|
|
|
|
|
|
// Verify that settings have been saved
|
|
|
|
await Promise.all( [
|
|
|
|
expect( page ).toMatchElement( '#message', { text: 'Your settings have been saved.' } ),
|
|
|
|
expect( page ).toMatchElement( 'ul.subsubsub > li > a', { text: 'Fancy rates' } ),
|
|
|
|
] );
|
2019-08-30 11:53:45 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
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();
|
2019-09-04 16:29:13 +00:00
|
|
|
|
|
|
|
// Verify that settings have been saved
|
|
|
|
await Promise.all( [
|
|
|
|
expect( page ).toMatchElement( '#message', { text: 'Your settings have been saved.' } ),
|
|
|
|
expect( page ).not.toMatchElement( 'ul.subsubsub > li > a', { text: 'Fancy rates' } ),
|
|
|
|
] );
|
2019-08-30 11:53:45 +00:00
|
|
|
await page.waitFor( 10000 );
|
|
|
|
} );
|
|
|
|
} );
|