2020-03-04 14:32:31 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import {
|
2021-10-25 14:46:34 +00:00
|
|
|
clickBlockToolbarButton,
|
2020-07-29 13:39:15 +00:00
|
|
|
openDocumentSettingsSidebar,
|
2020-03-04 14:32:31 +00:00
|
|
|
switchUserToAdmin,
|
2021-05-05 11:52:27 +00:00
|
|
|
getAllBlocks,
|
2020-03-04 14:32:31 +00:00
|
|
|
} from '@wordpress/e2e-test-utils';
|
2020-07-29 13:39:15 +00:00
|
|
|
import {
|
2020-09-14 07:46:58 +00:00
|
|
|
findLabelWithText,
|
2020-07-29 13:39:15 +00:00
|
|
|
visitBlockPage,
|
2021-10-25 14:46:34 +00:00
|
|
|
selectBlockByName,
|
2020-07-29 13:39:15 +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
|
|
|
} from '../../utils.js';
|
|
|
|
|
2020-06-15 14:59:18 +00:00
|
|
|
const block = {
|
|
|
|
name: 'Cart',
|
|
|
|
slug: 'woocommerce/cart',
|
2021-11-09 13:18:55 +00:00
|
|
|
class: '.wp-block-woocommerce-cart',
|
|
|
|
};
|
|
|
|
|
|
|
|
const filledCartBlock = {
|
|
|
|
name: 'Filled Cart',
|
|
|
|
slug: 'woocommerce/filled-cart-block',
|
|
|
|
class: '.wp-block-woocommerce-filled-cart-block',
|
|
|
|
};
|
|
|
|
|
|
|
|
const emptyCartBlock = {
|
|
|
|
name: 'Empty Cart',
|
|
|
|
slug: 'woocommerce/empty-cart-block',
|
|
|
|
class: '.wp-block-woocommerce-empty-cart-block',
|
2020-06-15 14:59:18 +00:00
|
|
|
};
|
|
|
|
|
2022-09-21 06:29:16 +00:00
|
|
|
const crossSellsBlock = {
|
|
|
|
name: 'Cart Cross-Sells block',
|
|
|
|
slug: 'woocommerce/cart-cross-sells-products-block',
|
|
|
|
class: '.wp-block-woocommerce-cart-cross-sells-products-block',
|
|
|
|
};
|
|
|
|
|
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` );
|
2020-09-14 07:46:58 +00:00
|
|
|
} );
|
2020-07-29 13:39:15 +00:00
|
|
|
|
2022-08-12 14:23:08 +00:00
|
|
|
it( 'can only be inserted once', async () => {
|
|
|
|
await insertBlockDontWaitForInsertClose( block.name );
|
|
|
|
expect( await getAllBlocks() ).toHaveLength( 1 );
|
|
|
|
} );
|
2020-07-29 13:39:15 +00:00
|
|
|
|
2022-08-12 14:23:08 +00:00
|
|
|
it( 'renders without crashing', async () => {
|
|
|
|
await expect( page ).toRenderBlock( block );
|
|
|
|
await expect( page ).toRenderBlock( filledCartBlock );
|
2022-09-21 06:29:16 +00:00
|
|
|
await expect( page ).toRenderBlock( crossSellsBlock );
|
2022-08-12 14:23:08 +00:00
|
|
|
await expect( page ).toRenderBlock( emptyCartBlock );
|
|
|
|
} );
|
2021-10-18 06:48:03 +00:00
|
|
|
|
2022-08-12 14:23:08 +00:00
|
|
|
it( 'shows empty cart when changing the view', async () => {
|
|
|
|
await page.waitForSelector( block.class ).catch( () => {
|
|
|
|
throw new Error(
|
|
|
|
`Could not find an element with class ${ block.class } - the block probably did not load correctly.`
|
|
|
|
);
|
2021-03-19 10:05:42 +00:00
|
|
|
} );
|
2022-08-12 14:23:08 +00:00
|
|
|
await selectBlockByName( block.slug );
|
|
|
|
await clickBlockToolbarButton( 'Switch view', 'ariaLabel' );
|
|
|
|
const emptyCartButton = await page.waitForXPath(
|
|
|
|
`//button[contains(@class,'components-dropdown-menu__menu-item')]//span[contains(text(), 'Empty Cart')]`
|
|
|
|
);
|
|
|
|
// Clicks the element by running the JavaScript HTMLElement.click() method on the given element in the
|
|
|
|
// browser context, which fires a click event. It doesn't scroll the page or move the mouse and works
|
|
|
|
// even if the element is off-screen.
|
|
|
|
await emptyCartButton.evaluate( ( b ) => b.click() );
|
2021-05-05 11:52:27 +00:00
|
|
|
|
2022-08-12 14:23:08 +00:00
|
|
|
await expect( page ).not.toMatchElement(
|
|
|
|
`${ emptyCartBlock.class }[hidden]`
|
|
|
|
);
|
|
|
|
await expect( page ).toMatchElement(
|
|
|
|
`${ filledCartBlock.class }[hidden]`
|
|
|
|
);
|
2021-10-25 14:46:34 +00:00
|
|
|
|
2022-08-12 14:23:08 +00:00
|
|
|
await selectBlockByName( block.slug );
|
|
|
|
await clickBlockToolbarButton( 'Switch view', 'ariaLabel' );
|
|
|
|
const filledCartButton = await page.waitForXPath(
|
|
|
|
`//button[contains(@class,'components-dropdown-menu__menu-item')]//span[contains(text(), 'Filled Cart')]`
|
|
|
|
);
|
|
|
|
await filledCartButton.evaluate( ( b ) => b.click() );
|
2021-10-25 14:46:34 +00:00
|
|
|
|
2022-08-12 14:23:08 +00:00
|
|
|
await expect( page ).toMatchElement(
|
|
|
|
`${ emptyCartBlock.class }[hidden]`
|
|
|
|
);
|
|
|
|
await expect( page ).not.toMatchElement(
|
|
|
|
`${ filledCartBlock.class }[hidden]`
|
|
|
|
);
|
|
|
|
} );
|
2021-10-25 14:46:34 +00:00
|
|
|
|
2022-08-12 14:23:08 +00:00
|
|
|
describe( 'attributes', () => {
|
|
|
|
beforeEach( async () => {
|
|
|
|
await openDocumentSettingsSidebar();
|
|
|
|
await selectBlockByName(
|
|
|
|
'woocommerce/cart-order-summary-shipping-block'
|
2021-10-18 06:48:03 +00:00
|
|
|
);
|
2021-05-05 11:52:27 +00:00
|
|
|
} );
|
|
|
|
|
2022-08-12 14:23:08 +00:00
|
|
|
it( 'can toggle Shipping calculator', async () => {
|
|
|
|
const selector = ` .wc-block-components-totals-shipping__change-address-button`;
|
|
|
|
const toggleLabel = await findLabelWithText(
|
|
|
|
'Shipping calculator'
|
|
|
|
);
|
|
|
|
await expect( toggleLabel ).toToggleElement( selector );
|
2021-05-05 11:52:27 +00:00
|
|
|
} );
|
|
|
|
} );
|
2020-07-29 13:39:15 +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 cartButton = await page.$x(
|
|
|
|
`//button//span[text()='${ block.name }']`
|
|
|
|
);
|
|
|
|
|
|
|
|
// This one match is the Cart widget.
|
|
|
|
expect( cartButton ).toHaveLength( 1 );
|
|
|
|
} );
|
|
|
|
} );
|
2020-03-04 14:32:31 +00:00
|
|
|
} );
|