2020-03-04 14:32:31 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import {
|
2020-07-29 13:39:15 +00:00
|
|
|
clickButton,
|
2020-03-04 14:32:31 +00:00
|
|
|
getAllBlocks,
|
2020-07-29 13:39:15 +00:00
|
|
|
openDocumentSettingsSidebar,
|
2020-03-04 14:32:31 +00:00
|
|
|
switchUserToAdmin,
|
|
|
|
} 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,
|
|
|
|
} from '@woocommerce/blocks-test-utils';
|
2020-03-04 14:32:31 +00:00
|
|
|
|
2020-10-27 12:24:53 +00:00
|
|
|
import {
|
|
|
|
insertBlockDontWaitForInsertClose,
|
|
|
|
closeInserter,
|
|
|
|
} from '../../utils.js';
|
|
|
|
|
2020-06-15 14:59:18 +00:00
|
|
|
const block = {
|
|
|
|
name: 'Cart',
|
|
|
|
slug: 'woocommerce/cart',
|
|
|
|
class: '.wc-block-cart',
|
|
|
|
};
|
|
|
|
|
2020-06-16 12:18:34 +00:00
|
|
|
if ( process.env.WP_VERSION < 5.3 || process.env.WOOCOMMERCE_BLOCKS_PHASE < 2 )
|
|
|
|
// eslint-disable-next-line jest/no-focused-tests
|
|
|
|
test.only( `skipping ${ block.name } tests`, () => {} );
|
|
|
|
|
2020-06-15 14:59:18 +00:00
|
|
|
describe( `${ block.name } Block`, () => {
|
|
|
|
beforeAll( async () => {
|
|
|
|
await switchUserToAdmin();
|
|
|
|
await visitBlockPage( `${ block.name } Block` );
|
2020-03-04 14:32:31 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'can only be inserted once', async () => {
|
2020-10-27 12:24:53 +00:00
|
|
|
await insertBlockDontWaitForInsertClose( block.name );
|
2020-07-29 13:39:15 +00:00
|
|
|
await closeInserter();
|
2020-03-04 14:32:31 +00:00
|
|
|
expect( await getAllBlocks() ).toHaveLength( 1 );
|
2020-06-15 14:59:18 +00:00
|
|
|
} );
|
2020-03-04 14:32:31 +00:00
|
|
|
|
2020-06-15 14:59:18 +00:00
|
|
|
it( 'renders without crashing', async () => {
|
2020-06-25 13:00:27 +00:00
|
|
|
await expect( page ).toRenderBlock( block );
|
2020-03-04 14:32:31 +00:00
|
|
|
} );
|
2020-07-29 13:39:15 +00:00
|
|
|
|
2020-09-14 07:46:58 +00:00
|
|
|
describe( 'attributes', () => {
|
|
|
|
beforeEach( async () => {
|
|
|
|
await openDocumentSettingsSidebar();
|
|
|
|
await page.click( block.class );
|
|
|
|
} );
|
2020-07-29 13:39:15 +00:00
|
|
|
|
2020-09-14 07:46:58 +00:00
|
|
|
it( 'can toggle Shipping calculator', async () => {
|
|
|
|
const selector = `${ block.class } .wc-block-components-totals-shipping__change-address-button`;
|
|
|
|
const toggleLabel = await findLabelWithText(
|
|
|
|
'Shipping calculator'
|
|
|
|
);
|
|
|
|
await expect( toggleLabel ).toToggleElement( selector );
|
|
|
|
} );
|
2020-07-29 13:39:15 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'shows empty cart when changing the view', async () => {
|
|
|
|
await openDocumentSettingsSidebar();
|
|
|
|
await page.click( block.class );
|
|
|
|
await expect( page ).toMatchElement(
|
|
|
|
'[hidden] .wc-block-cart__empty-cart__title'
|
|
|
|
);
|
|
|
|
await clickButton( 'Empty Cart' );
|
|
|
|
await expect( page ).not.toMatchElement(
|
|
|
|
'[hidden] .wc-block-cart__empty-cart__title'
|
|
|
|
);
|
|
|
|
await clickButton( 'Full Cart' );
|
|
|
|
await expect( page ).toMatchElement(
|
|
|
|
'[hidden] .wc-block-cart__empty-cart__title'
|
|
|
|
);
|
|
|
|
} );
|
2020-03-04 14:32:31 +00:00
|
|
|
} );
|