2020-03-04 14:32:31 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import {
|
2020-09-14 07:46:58 +00:00
|
|
|
openDocumentSettingsSidebar,
|
2020-03-04 14:32:31 +00:00
|
|
|
switchUserToAdmin,
|
2023-01-25 15:41:22 +00:00
|
|
|
openGlobalBlockInserter,
|
2020-03-04 14:32:31 +00:00
|
|
|
} from '@wordpress/e2e-test-utils';
|
2020-09-14 07:46:58 +00:00
|
|
|
import {
|
|
|
|
findLabelWithText,
|
|
|
|
visitBlockPage,
|
2021-09-16 12:16:21 +00:00
|
|
|
selectBlockByName,
|
2023-01-25 15:41:22 +00:00
|
|
|
switchBlockInspectorTabWhenGutenbergIsInstalled,
|
2020-09-14 07:46:58 +00:00
|
|
|
} from '@woocommerce/blocks-test-utils';
|
2021-10-18 06:48:03 +00:00
|
|
|
import { merchant } from '@woocommerce/e2e-utils';
|
2020-03-04 14:32:31 +00:00
|
|
|
|
2022-05-23 12:05:30 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2020-10-27 12:24:53 +00:00
|
|
|
import {
|
2021-10-18 06:48:03 +00:00
|
|
|
searchForBlock,
|
|
|
|
openWidgetEditor,
|
|
|
|
closeModalIfExists,
|
2020-10-27 12:24:53 +00:00
|
|
|
} from '../../utils.js';
|
2023-03-13 11:49:28 +00:00
|
|
|
import { merchant as merchantUtils } from '../../../utils/merchant';
|
2020-10-27 12:24:53 +00:00
|
|
|
|
2020-06-15 14:59:18 +00:00
|
|
|
const block = {
|
|
|
|
name: 'Checkout',
|
|
|
|
slug: 'woocommerce/checkout',
|
2021-09-16 12:16:21 +00:00
|
|
|
class: '.wp-block-woocommerce-checkout',
|
2023-01-25 15:41:22 +00:00
|
|
|
selectors: {
|
|
|
|
insertButton: "//button//span[text()='Checkout']",
|
|
|
|
},
|
2020-06-15 14:59:18 +00:00
|
|
|
};
|
|
|
|
|
2021-05-05 11:52:27 +00:00
|
|
|
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE < 2 ) {
|
2022-05-23 12:05:30 +00:00
|
|
|
// eslint-disable-next-line jest/no-focused-tests, jest/expect-expect
|
2020-06-16 12:18:34 +00:00
|
|
|
test.only( `skipping ${ block.name } tests`, () => {} );
|
2021-05-05 11:52:27 +00:00
|
|
|
}
|
2020-06-16 12:18:34 +00:00
|
|
|
|
2020-06-15 14:59:18 +00:00
|
|
|
describe( `${ block.name } Block`, () => {
|
2021-10-18 06:48:03 +00:00
|
|
|
describe( 'in page editor', () => {
|
2022-08-12 14:23:08 +00:00
|
|
|
beforeAll( async () => {
|
|
|
|
await switchUserToAdmin();
|
|
|
|
await visitBlockPage( `${ block.name } Block` );
|
|
|
|
} );
|
2021-05-05 11:52:27 +00:00
|
|
|
|
2022-08-12 14:23:08 +00:00
|
|
|
it( 'can only be inserted once', async () => {
|
2023-01-25 15:41:22 +00:00
|
|
|
await openGlobalBlockInserter();
|
|
|
|
await page.keyboard.type( block.name );
|
|
|
|
const button = await page.$x( block.selectors.insertButton );
|
|
|
|
expect( button ).toHaveLength( 0 );
|
2021-05-18 13:09:30 +00:00
|
|
|
} );
|
2020-09-14 07:46:58 +00:00
|
|
|
|
2022-08-12 14:23:08 +00:00
|
|
|
it( 'renders without crashing', async () => {
|
|
|
|
await expect( page ).toRenderBlock( block );
|
|
|
|
} );
|
2020-09-14 07:46:58 +00:00
|
|
|
|
2022-08-12 14:23:08 +00:00
|
|
|
describe( 'attributes', () => {
|
|
|
|
beforeEach( async () => {
|
|
|
|
await openDocumentSettingsSidebar();
|
2023-01-25 15:41:22 +00:00
|
|
|
await switchBlockInspectorTabWhenGutenbergIsInstalled(
|
|
|
|
'Settings'
|
|
|
|
);
|
2022-08-12 14:23:08 +00:00
|
|
|
await selectBlockByName( block.slug );
|
2021-10-18 06:48:03 +00:00
|
|
|
} );
|
2020-09-14 07:46:58 +00:00
|
|
|
|
2023-03-13 11:49:28 +00:00
|
|
|
it( 'can toggle "hide shipping costs until an address is entered"', async () => {
|
|
|
|
await selectBlockByName(
|
|
|
|
'woocommerce/checkout-shipping-methods-block'
|
|
|
|
);
|
|
|
|
const toggleLabel = await findLabelWithText(
|
|
|
|
'Hide shipping costs until an address is entered'
|
|
|
|
);
|
|
|
|
await toggleLabel.click();
|
|
|
|
const shippingOptionsRequireAddressText = await page.$x(
|
|
|
|
'//p[contains(text(), "Shipping options will be displayed here after entering your full shipping address.")]'
|
|
|
|
);
|
|
|
|
await expect( shippingOptionsRequireAddressText ).toHaveLength(
|
|
|
|
1
|
|
|
|
);
|
|
|
|
|
|
|
|
await toggleLabel.click();
|
|
|
|
await expect( page ).toMatchElement(
|
|
|
|
'.wc-block-components-shipping-rates-control'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'toggles the same setting in shipping method and shipping methods blocks', async () => {
|
|
|
|
await merchantUtils.goToLocalPickupSettingsPage();
|
|
|
|
await merchantUtils.enableLocalPickup();
|
|
|
|
await merchantUtils.saveLocalPickupSettingsPageWithRefresh();
|
|
|
|
|
|
|
|
await visitBlockPage( `${ block.name } Block` );
|
|
|
|
await expect( page ).toClick(
|
|
|
|
'.wc-block-checkout__shipping-method button',
|
|
|
|
{ text: 'Shipping' }
|
|
|
|
);
|
|
|
|
await openDocumentSettingsSidebar();
|
|
|
|
const toggleLabel = await findLabelWithText(
|
|
|
|
'Hide shipping costs until an address is entered'
|
|
|
|
);
|
|
|
|
await toggleLabel.click();
|
|
|
|
const [ label ] = await page.$x(
|
|
|
|
'//label[contains(., "Hide shipping costs until an address is entered")]'
|
|
|
|
);
|
|
|
|
const shippingMethodForValue = await page.evaluate(
|
|
|
|
( passedLabel ) => passedLabel.getAttribute( 'for' ),
|
|
|
|
label
|
|
|
|
);
|
|
|
|
const shippingMethodSettingIsChecked = await page.evaluate(
|
|
|
|
( passedShippingMethodForValue ) =>
|
|
|
|
document.getElementById( passedShippingMethodForValue )
|
|
|
|
.checked,
|
|
|
|
shippingMethodForValue
|
|
|
|
);
|
|
|
|
await expect( shippingMethodSettingIsChecked ).toBe( true );
|
|
|
|
await selectBlockByName(
|
|
|
|
'woocommerce/checkout-shipping-methods-block'
|
|
|
|
);
|
|
|
|
const [ shippingMethodsLabel ] = await page.$x(
|
|
|
|
'//label[contains(., "Hide shipping costs until an address is entered")]'
|
|
|
|
);
|
|
|
|
const shippingMethodsLabelForValue = await page.evaluate(
|
|
|
|
( passedShippingMethodsLabel ) =>
|
|
|
|
passedShippingMethodsLabel.getAttribute( 'for' ),
|
|
|
|
shippingMethodsLabel
|
|
|
|
);
|
|
|
|
const shippingMethodLabelIsChecked = await page.evaluate(
|
|
|
|
( passedShippingMethodsLabelForValue ) =>
|
|
|
|
document.getElementById(
|
|
|
|
passedShippingMethodsLabelForValue
|
|
|
|
).checked,
|
|
|
|
shippingMethodsLabelForValue
|
|
|
|
);
|
|
|
|
expect( shippingMethodSettingIsChecked ).toBe(
|
|
|
|
shippingMethodLabelIsChecked
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2022-08-12 14:23:08 +00:00
|
|
|
it( 'can enable dark mode inputs', async () => {
|
|
|
|
const toggleLabel = await findLabelWithText(
|
|
|
|
'Dark mode inputs'
|
|
|
|
);
|
|
|
|
await toggleLabel.click();
|
|
|
|
|
|
|
|
await expect( page ).toMatchElement(
|
|
|
|
`.wc-block-checkout.has-dark-controls`
|
|
|
|
);
|
|
|
|
|
|
|
|
await toggleLabel.click();
|
|
|
|
|
|
|
|
await expect( page ).not.toMatchElement(
|
|
|
|
`.wc-block-checkout.has-dark-controls`
|
|
|
|
);
|
2021-09-16 12:16:21 +00:00
|
|
|
} );
|
2022-08-12 14:23:08 +00:00
|
|
|
} );
|
2021-09-16 12:16:21 +00:00
|
|
|
|
2022-08-12 14:23:08 +00:00
|
|
|
describe( 'shipping address block attributes', () => {
|
|
|
|
beforeEach( async () => {
|
|
|
|
await openDocumentSettingsSidebar();
|
2023-01-25 15:41:22 +00:00
|
|
|
await switchBlockInspectorTabWhenGutenbergIsInstalled(
|
|
|
|
'Settings'
|
|
|
|
);
|
2022-08-12 14:23:08 +00:00
|
|
|
await selectBlockByName(
|
|
|
|
'woocommerce/checkout-shipping-address-block'
|
|
|
|
);
|
|
|
|
} );
|
2021-09-16 12:16:21 +00:00
|
|
|
|
2022-08-12 14:23:08 +00:00
|
|
|
describe( 'Company input', () => {
|
|
|
|
const selector = `${ block.class } #shipping-company`;
|
2021-09-16 12:16:21 +00:00
|
|
|
|
2022-08-12 14:23:08 +00:00
|
|
|
it( 'visibility can be toggled', async () => {
|
|
|
|
await expect( 'Company' ).toToggleElement( selector );
|
|
|
|
} );
|
2021-09-16 12:16:21 +00:00
|
|
|
|
2022-08-12 14:23:08 +00:00
|
|
|
it( 'required attribute can be toggled', async () => {
|
|
|
|
// Company is disabled by default, so first we need to enable it.
|
|
|
|
const toggleLabel = await findLabelWithText( 'Company' );
|
2021-10-18 06:48:03 +00:00
|
|
|
await toggleLabel.click();
|
2022-08-12 14:23:08 +00:00
|
|
|
await expect(
|
|
|
|
'Require company name?'
|
|
|
|
).toToggleRequiredAttrOf( selector );
|
2021-10-18 06:48:03 +00:00
|
|
|
} );
|
2020-09-14 07:46:58 +00:00
|
|
|
} );
|
|
|
|
|
2022-08-12 14:23:08 +00:00
|
|
|
describe( 'Apartment input', () => {
|
|
|
|
it( 'visibility can be toggled', async () => {
|
|
|
|
const selector = `${ block.class } #shipping-address_2`;
|
|
|
|
await expect( 'Apartment, suite, etc.' ).toToggleElement(
|
|
|
|
selector
|
2021-10-18 06:48:03 +00:00
|
|
|
);
|
|
|
|
} );
|
2022-08-12 14:23:08 +00:00
|
|
|
} );
|
2021-03-19 10:05:42 +00:00
|
|
|
|
2022-08-12 14:23:08 +00:00
|
|
|
describe( 'Phone input', () => {
|
|
|
|
const selector = `${ block.class } #shipping-phone`;
|
2021-03-19 10:05:42 +00:00
|
|
|
|
2022-08-12 14:23:08 +00:00
|
|
|
it( 'visibility can be toggled', async () => {
|
|
|
|
await expect( 'Phone' ).toToggleElement( selector );
|
2021-03-19 10:05:42 +00:00
|
|
|
} );
|
2020-09-14 07:46:58 +00:00
|
|
|
|
2022-08-12 14:23:08 +00:00
|
|
|
it( 'required attribute can be toggled', async () => {
|
|
|
|
await expect(
|
|
|
|
'Require phone number?'
|
|
|
|
).toToggleRequiredAttrOf( selector );
|
2021-03-19 10:05:42 +00:00
|
|
|
} );
|
2020-09-14 07:46:58 +00:00
|
|
|
} );
|
2022-08-12 14:23:08 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
describe( 'action block attributes', () => {
|
|
|
|
beforeEach( async () => {
|
|
|
|
await openDocumentSettingsSidebar();
|
2023-01-25 15:41:22 +00:00
|
|
|
await switchBlockInspectorTabWhenGutenbergIsInstalled(
|
|
|
|
'Settings'
|
|
|
|
);
|
2022-08-12 14:23:08 +00:00
|
|
|
await selectBlockByName( 'woocommerce/checkout-actions-block' );
|
|
|
|
} );
|
2020-09-14 07:46:58 +00:00
|
|
|
|
2022-08-12 14:23:08 +00:00
|
|
|
describe( 'Return to cart link', () => {
|
|
|
|
it( 'visibility can be toggled', async () => {
|
|
|
|
const selector = `${ block.class } .wc-block-components-checkout-return-to-cart-button`;
|
|
|
|
const toggleLabel = await findLabelWithText(
|
|
|
|
'Show a "Return to Cart" link'
|
2021-10-18 06:48:03 +00:00
|
|
|
);
|
2022-08-12 14:23:08 +00:00
|
|
|
await expect( toggleLabel ).toToggleElement( selector );
|
2021-03-19 10:05:42 +00:00
|
|
|
} );
|
2020-09-14 07:46:58 +00:00
|
|
|
} );
|
2021-09-16 12:16:21 +00:00
|
|
|
} );
|
2021-10-18 06:48:03 +00:00
|
|
|
} );
|
2020-09-14 07:46:58 +00:00
|
|
|
|
2021-10-18 06:48:03 +00:00
|
|
|
describe( 'in widget editor', () => {
|
|
|
|
it( "can't be inserted in a widget area", async () => {
|
|
|
|
await merchant.login();
|
|
|
|
await openWidgetEditor();
|
|
|
|
await closeModalIfExists();
|
|
|
|
await searchForBlock( block.name );
|
|
|
|
const checkoutButton = await page.$x(
|
|
|
|
`//button//span[text()='${ block.name }']`
|
|
|
|
);
|
2020-09-14 07:46:58 +00:00
|
|
|
|
2021-10-18 06:48:03 +00:00
|
|
|
expect( checkoutButton ).toHaveLength( 0 );
|
2020-09-14 07:46:58 +00:00
|
|
|
} );
|
|
|
|
} );
|
2020-03-04 14:32:31 +00:00
|
|
|
} );
|