basic e2e test for instantiating All Reviews block (https://github.com/woocommerce/woocommerce-blocks/pull/2799)
* add e2e test for instantiating All Reviews block: - adapted code from @senadir in-progress PR https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/2756 * remove pptr-testing-library - not needed for this test * Don't skip tests for the review block on < 5.3 Co-authored-by: Mike Jolley <mike.jolley@me.com>
This commit is contained in:
parent
661ebc196a
commit
29e7aa9bdf
|
@ -11,6 +11,7 @@ import {
|
|||
createTaxes,
|
||||
createCoupons,
|
||||
createProducts,
|
||||
createReviews,
|
||||
createShippingZones,
|
||||
createBlockPages,
|
||||
enablePaymentGateways,
|
||||
|
@ -36,6 +37,12 @@ module.exports = async ( globalConfig ) => {
|
|||
enablePaymentGateways(),
|
||||
] );
|
||||
const [ , taxes, coupons, products, shippingZones, pages ] = results;
|
||||
|
||||
/**
|
||||
* Create fixture reviews data on first product.
|
||||
*/
|
||||
await createReviews( products[ 0 ] );
|
||||
|
||||
global.fixtureData = {
|
||||
taxes,
|
||||
coupons,
|
||||
|
|
|
@ -103,7 +103,7 @@ const deleteCoupons = ( ids ) =>
|
|||
delete: ids,
|
||||
} );
|
||||
/**
|
||||
* Create Products and call createReviews.
|
||||
* Create Products.
|
||||
*
|
||||
* currently this only creates a single product for the sake of reviews.
|
||||
*
|
||||
|
@ -118,7 +118,6 @@ const createProducts = ( fixture = fixtures.Products() ) =>
|
|||
WooCommerce.post( 'products/batch', {
|
||||
create: fixture,
|
||||
} ).then( ( products ) => {
|
||||
createReviews( products.data.create[ 0 ].id );
|
||||
return products.data.create.map( ( product ) => product.id );
|
||||
} );
|
||||
|
||||
|
@ -308,6 +307,7 @@ module.exports = {
|
|||
deleteCoupons,
|
||||
createProducts,
|
||||
deleteProducts,
|
||||
createReviews,
|
||||
enablePaymentGateways,
|
||||
createShippingZones,
|
||||
deleteShippingZones,
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{"title":"All Reviews Block","pageContent":"<!-- wp:woocommerce/all-reviews -->\n<div class=\"wp-block-woocommerce-all-reviews wc-block-all-reviews has-image has-name has-date has-rating has-content has-product-name\" data-image-type=\"reviewer\" data-orderby=\"most-recent\" data-reviews-on-page-load=\"10\" data-reviews-on-load-more=\"10\" data-show-load-more=\"true\" data-show-orderby=\"true\"></div>\n<!-- /wp:woocommerce/all-reviews -->"}
|
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { switchUserToAdmin } from '@wordpress/e2e-test-utils';
|
||||
|
||||
import { visitBlockPage } from '@woocommerce/blocks-test-utils';
|
||||
|
||||
const block = {
|
||||
name: 'All Reviews',
|
||||
slug: 'woocommerce/all-reviews',
|
||||
class: '.wc-block-all-reviews',
|
||||
};
|
||||
|
||||
describe( `${ block.name } Block`, () => {
|
||||
beforeAll( async () => {
|
||||
await switchUserToAdmin();
|
||||
await visitBlockPage( `${ block.name } Block` );
|
||||
} );
|
||||
|
||||
it( 'renders without crashing', async () => {
|
||||
await expect( page ).toRenderBlock( block );
|
||||
} );
|
||||
|
||||
it( 'shows reviews', async () => {
|
||||
await page.waitForSelector(
|
||||
'.wc-block-review-list .wc-block-review-list-item__item:not(.is-loading)'
|
||||
);
|
||||
expect(
|
||||
await page.$$eval(
|
||||
'.wc-block-review-list .wc-block-review-list-item__item',
|
||||
( reviews ) => reviews.length
|
||||
)
|
||||
).toBeGreaterThanOrEqual( 3 ); // Fixture data has three reviews.
|
||||
} );
|
||||
} );
|
Loading…
Reference in New Issue