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,
|
2021-03-19 10:05:42 +00:00
|
|
|
conditionalDescribe,
|
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',
|
|
|
|
class: '.wc-block-cart',
|
|
|
|
};
|
|
|
|
|
2020-12-09 16:09:45 +00:00
|
|
|
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE < 2 )
|
2020-06-16 12:18:34 +00:00
|
|
|
// 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();
|
2020-03-04 14:32:31 +00:00
|
|
|
} );
|
|
|
|
|
2021-03-19 10:05:42 +00:00
|
|
|
afterEach( async () => {
|
|
|
|
await page.evaluate( () => {
|
|
|
|
localStorage.removeItem(
|
|
|
|
'wc-blocks_dismissed_compatibility_notices'
|
|
|
|
);
|
|
|
|
} );
|
2020-06-15 14:59:18 +00:00
|
|
|
} );
|
2020-03-04 14:32:31 +00:00
|
|
|
|
2021-03-19 10:05:42 +00:00
|
|
|
conditionalDescribe( process.env.WP_VERSION > 5.4 )(
|
|
|
|
'before compatibility notice is dismissed',
|
|
|
|
() => {
|
|
|
|
beforeEach( async () => {
|
|
|
|
await page.evaluate( () => {
|
|
|
|
localStorage.setItem(
|
|
|
|
'wc-blocks_dismissed_compatibility_notices',
|
|
|
|
'[]'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
await visitBlockPage( `${ block.name } Block` );
|
|
|
|
} );
|
2020-07-29 13:39:15 +00:00
|
|
|
|
2021-03-19 10:05:42 +00:00
|
|
|
it( 'shows compatibility notice', async () => {
|
|
|
|
const compatibilityNoticeTitle = await page.$x(
|
|
|
|
`//h1[contains(text(), 'Compatibility notice')]`
|
|
|
|
);
|
|
|
|
expect( compatibilityNoticeTitle.length ).toBe( 1 );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
describe( 'once compatibility notice is dismissed', () => {
|
2020-09-14 07:46:58 +00:00
|
|
|
beforeEach( async () => {
|
2021-03-19 10:05:42 +00:00
|
|
|
await page.evaluate( () => {
|
|
|
|
localStorage.setItem(
|
|
|
|
'wc-blocks_dismissed_compatibility_notices',
|
|
|
|
'["cart"]'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
await visitBlockPage( `${ block.name } Block` );
|
2020-09-14 07:46:58 +00:00
|
|
|
} );
|
2020-07-29 13:39:15 +00:00
|
|
|
|
2021-03-19 10:05:42 +00:00
|
|
|
it( 'can only be inserted once', async () => {
|
|
|
|
await insertBlockDontWaitForInsertClose( block.name );
|
|
|
|
await closeInserter();
|
|
|
|
expect( await getAllBlocks() ).toHaveLength( 1 );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'renders without crashing', async () => {
|
|
|
|
await expect( page ).toRenderBlock( block );
|
2020-09-14 07:46:58 +00:00
|
|
|
} );
|
2020-07-29 13:39:15 +00:00
|
|
|
|
2021-03-19 10:05:42 +00:00
|
|
|
describe( 'attributes', () => {
|
|
|
|
beforeEach( async () => {
|
|
|
|
await openDocumentSettingsSidebar();
|
|
|
|
await page.click( block.class );
|
|
|
|
} );
|
|
|
|
|
|
|
|
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 );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'shows empty cart when changing the view', async () => {
|
|
|
|
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'
|
|
|
|
);
|
|
|
|
// Simulate user scrolling up so the block toolbar doesn't cover
|
|
|
|
// the `Full Cart` button.
|
|
|
|
page.evaluate( () => {
|
|
|
|
document
|
|
|
|
.querySelector( '.wc-block-view-switch-control' )
|
|
|
|
.scrollIntoView( { block: 'center', inline: 'center' } );
|
|
|
|
} );
|
|
|
|
await clickButton( 'Full Cart' );
|
|
|
|
await expect( page ).toMatchElement(
|
|
|
|
'[hidden] .wc-block-cart__empty-cart__title'
|
|
|
|
);
|
|
|
|
} );
|
2020-07-29 13:39:15 +00:00
|
|
|
} );
|
2020-03-04 14:32:31 +00:00
|
|
|
} );
|