2022-10-14 03:25:02 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
getAllBlocks,
|
|
|
|
switchUserToAdmin,
|
|
|
|
canvas,
|
|
|
|
openListView,
|
|
|
|
} from '@wordpress/e2e-test-utils';
|
2023-04-03 13:02:36 +00:00
|
|
|
import { visitBlockPage } from '@woocommerce/blocks-test-utils';
|
2022-10-14 03:25:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
insertBlockDontWaitForInsertClose,
|
|
|
|
GUTENBERG_EDITOR_CONTEXT,
|
|
|
|
describeOrSkip,
|
2023-04-03 13:02:36 +00:00
|
|
|
openSettingsSidebar,
|
2022-10-14 03:25:02 +00:00
|
|
|
} from '../../utils';
|
|
|
|
|
|
|
|
const block = {
|
2022-12-05 12:46:50 +00:00
|
|
|
name: 'Products (Beta)',
|
2022-10-14 03:25:02 +00:00
|
|
|
slug: 'woocommerce/product-query',
|
|
|
|
class: '.wp-block-query',
|
|
|
|
};
|
|
|
|
|
|
|
|
describeOrSkip( GUTENBERG_EDITOR_CONTEXT === 'gutenberg' )(
|
|
|
|
`${ block.name } Block`,
|
|
|
|
() => {
|
|
|
|
beforeAll( async () => {
|
|
|
|
await switchUserToAdmin();
|
|
|
|
await visitBlockPage( `${ block.name } Block` );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'can be inserted more than once', async () => {
|
|
|
|
await insertBlockDontWaitForInsertClose( block.name );
|
|
|
|
expect( await getAllBlocks() ).toHaveLength( 2 );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'renders without crashing', async () => {
|
|
|
|
await expect( page ).toRenderBlock( block );
|
|
|
|
} );
|
|
|
|
|
2022-11-16 01:52:51 +00:00
|
|
|
/**
|
|
|
|
* We changed the “Show only products on sale” from a top-level toggle
|
|
|
|
* setting to a product filter, but tests for them haven't been updated
|
|
|
|
* yet. We will fix these tests in a follow-up PR.
|
|
|
|
*/
|
|
|
|
it.skip( 'Editor preview shows only on sale products after enabling `Show only products on sale`', async () => {
|
2022-10-14 03:25:02 +00:00
|
|
|
await visitBlockPage( `${ block.name } Block` );
|
|
|
|
const canvasEl = canvas();
|
2023-04-03 13:02:36 +00:00
|
|
|
await openSettingsSidebar();
|
2022-10-14 03:25:02 +00:00
|
|
|
await openListView();
|
|
|
|
await page.click(
|
|
|
|
'.block-editor-list-view-block__contents-container a.components-button'
|
|
|
|
);
|
|
|
|
const [ onSaleToggle ] = await page.$x(
|
|
|
|
'//label[text()="Show only products on sale"]'
|
|
|
|
);
|
|
|
|
await onSaleToggle.click();
|
|
|
|
await canvasEl.waitForSelector( `${ block.class } > p` );
|
|
|
|
await canvasEl.waitForSelector(
|
|
|
|
`${ block.class } > ul.wp-block-post-template`
|
|
|
|
);
|
|
|
|
const products = await canvasEl.$$(
|
|
|
|
`${ block.class } ul.wp-block-post-template > li.block-editor-block-preview__live-content`
|
|
|
|
);
|
|
|
|
expect( products ).toHaveLength( 1 );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
);
|