2020-03-04 14:32:31 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
getAllBlocks,
|
2020-09-14 07:46:58 +00:00
|
|
|
openDocumentSettingsSidebar,
|
2020-03-04 14:32:31 +00:00
|
|
|
switchUserToAdmin,
|
|
|
|
} 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,
|
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,
|
2020-10-27 12:24:53 +00:00
|
|
|
insertBlockDontWaitForInsertClose,
|
2021-10-18 06:48:03 +00:00
|
|
|
openWidgetEditor,
|
|
|
|
closeModalIfExists,
|
|
|
|
openWidgetsEditorBlockInserter,
|
2020-10-27 12:24:53 +00:00
|
|
|
closeInserter,
|
|
|
|
} from '../../utils.js';
|
|
|
|
|
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',
|
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 () => {
|
|
|
|
await insertBlockDontWaitForInsertClose( block.name );
|
|
|
|
await closeInserter();
|
|
|
|
expect( await getAllBlocks() ).toHaveLength( 1 );
|
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();
|
|
|
|
await selectBlockByName( block.slug );
|
2021-10-18 06:48:03 +00:00
|
|
|
} );
|
2020-09-14 07:46:58 +00:00
|
|
|
|
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();
|
|
|
|
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();
|
|
|
|
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 openWidgetsEditorBlockInserter();
|
|
|
|
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
|
|
|
} );
|