2022-04-01 09:23:48 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
insertBlock,
|
|
|
|
canvas,
|
|
|
|
searchForBlock as searchForFSEBlock,
|
|
|
|
} from '@wordpress/e2e-test-utils';
|
|
|
|
|
2021-09-08 08:14:53 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2022-02-07 10:29:22 +00:00
|
|
|
import {
|
|
|
|
openWidgetsEditorBlockInserter,
|
|
|
|
closeModalIfExists,
|
|
|
|
openWidgetEditor,
|
|
|
|
searchForBlock,
|
|
|
|
isBlockInsertedInWidgetsArea,
|
2022-04-01 09:23:48 +00:00
|
|
|
goToSiteEditor,
|
|
|
|
useTheme,
|
|
|
|
waitForCanvas,
|
2022-02-07 10:29:22 +00:00
|
|
|
} from '../../utils.js';
|
2021-09-08 08:14:53 +00:00
|
|
|
|
|
|
|
const block = {
|
|
|
|
name: 'Mini Cart',
|
|
|
|
slug: 'woocommerce/mini-cart',
|
|
|
|
class: '.wc-block-mini-cart',
|
2022-04-01 09:23:48 +00:00
|
|
|
selectors: {
|
|
|
|
insertButton: "//button//span[text()='Mini Cart']",
|
|
|
|
insertButtonDisabled:
|
|
|
|
"//button[@aria-disabled]//span[text()='Mini Cart']",
|
|
|
|
},
|
2021-09-08 08:14:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if ( process.env.WOOCOMMERCE_BLOCKS_PHASE < 3 ) {
|
2022-05-23 12:05:30 +00:00
|
|
|
// eslint-disable-next-line jest/no-focused-tests, jest/expect-expect
|
2021-09-08 08:14:53 +00:00
|
|
|
test.only( `skipping ${ block.name } tests`, () => {} );
|
|
|
|
}
|
|
|
|
|
2022-02-07 10:29:22 +00:00
|
|
|
const addBlockToWidgetsArea = async () => {
|
|
|
|
await closeModalIfExists();
|
|
|
|
await openWidgetsEditorBlockInserter();
|
|
|
|
await searchForBlock( block.name );
|
2022-12-30 11:47:33 +00:00
|
|
|
await page.waitForXPath( block.selectors.insertButton );
|
2022-04-01 09:23:48 +00:00
|
|
|
const miniCartButton = await page.$x( block.selectors.insertButton );
|
2022-02-07 10:29:22 +00:00
|
|
|
await miniCartButton[ 0 ].click();
|
|
|
|
};
|
|
|
|
|
2021-09-08 08:14:53 +00:00
|
|
|
describe( `${ block.name } Block`, () => {
|
2022-02-07 10:29:22 +00:00
|
|
|
describe( 'in widget editor', () => {
|
|
|
|
beforeEach( async () => {
|
|
|
|
await openWidgetEditor();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'can be inserted in widget area', async () => {
|
|
|
|
await addBlockToWidgetsArea();
|
|
|
|
expect( await isBlockInsertedInWidgetsArea( block.slug ) ).toBe(
|
|
|
|
true
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2021-10-21 09:07:20 +00:00
|
|
|
it( 'can only be inserted once', async () => {
|
2022-02-07 10:29:22 +00:00
|
|
|
await addBlockToWidgetsArea();
|
|
|
|
const miniCartButton = await page.$x(
|
2022-04-01 09:23:48 +00:00
|
|
|
block.selectors.insertButtonDisabled
|
2022-02-07 10:29:22 +00:00
|
|
|
);
|
2021-10-21 09:07:20 +00:00
|
|
|
|
2022-02-07 10:29:22 +00:00
|
|
|
expect( miniCartButton ).toHaveLength( 1 );
|
2021-10-21 09:07:20 +00:00
|
|
|
} );
|
2021-09-08 08:14:53 +00:00
|
|
|
} );
|
2022-02-07 10:29:22 +00:00
|
|
|
|
2022-04-01 09:23:48 +00:00
|
|
|
describe( 'in FSE editor', () => {
|
|
|
|
useTheme( 'emptytheme' );
|
|
|
|
|
|
|
|
beforeEach( async () => {
|
2022-08-03 20:22:37 +00:00
|
|
|
await goToSiteEditor();
|
2022-04-01 09:23:48 +00:00
|
|
|
await waitForCanvas();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'can be inserted in FSE area', async () => {
|
|
|
|
await insertBlock( block.name );
|
|
|
|
await expect( canvas() ).toMatchElement( block.class );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'can only be inserted once', async () => {
|
|
|
|
await insertBlock( block.name );
|
|
|
|
await searchForFSEBlock( block.name );
|
|
|
|
const miniCartButton = await page.$x(
|
|
|
|
block.selectors.insertButtonDisabled
|
|
|
|
);
|
|
|
|
expect( miniCartButton ).toHaveLength( 1 );
|
|
|
|
} );
|
|
|
|
} );
|
2021-09-08 08:14:53 +00:00
|
|
|
} );
|