Reviews by product/category e2e tests (https://github.com/woocommerce/woocommerce-blocks/pull/2808)
* Tests for reviews by product * reviews by category
This commit is contained in:
parent
e3dc2e9c86
commit
8cd96950e8
|
@ -141,6 +141,7 @@ const ReviewsByCategoryEditor = ( {
|
|||
'Reviews by Category',
|
||||
'woo-gutenberg-products-block'
|
||||
) }
|
||||
className="wc-block-reviews-by-category"
|
||||
>
|
||||
{ __(
|
||||
'Show product reviews from specific categories.',
|
||||
|
|
|
@ -125,6 +125,7 @@ const ReviewsByProductEditor = ( {
|
|||
'Reviews by Product',
|
||||
'woo-gutenberg-products-block'
|
||||
) }
|
||||
className="wc-block-reviews-by-product"
|
||||
>
|
||||
{ __(
|
||||
'Show reviews of your product to build trust',
|
||||
|
@ -161,7 +162,7 @@ const ReviewsByProductEditor = ( {
|
|||
{ getInspectorControls() }
|
||||
<EditorContainerBlock
|
||||
attributes={ attributes }
|
||||
className="wc-block-all-reviews"
|
||||
className="wc-block-reviews-by-product"
|
||||
icon={
|
||||
<Icon
|
||||
icon={ comment }
|
||||
|
|
|
@ -12,6 +12,7 @@ import {
|
|||
createCoupons,
|
||||
createProducts,
|
||||
createReviews,
|
||||
createCategories,
|
||||
createShippingZones,
|
||||
createBlockPages,
|
||||
enablePaymentGateways,
|
||||
|
@ -31,17 +32,22 @@ module.exports = async ( globalConfig ) => {
|
|||
setupSettings(),
|
||||
createTaxes(),
|
||||
createCoupons(),
|
||||
createProducts(),
|
||||
createCategories(),
|
||||
createShippingZones(),
|
||||
createBlockPages(),
|
||||
enablePaymentGateways(),
|
||||
] );
|
||||
const [ , taxes, coupons, products, shippingZones, pages ] = results;
|
||||
const [ , taxes, coupons, categories, shippingZones, pages ] = results;
|
||||
|
||||
// Create products after categories.
|
||||
const products = await createProducts( categories );
|
||||
|
||||
/**
|
||||
* Create fixture reviews data on first product.
|
||||
* Create fixture reviews data for each product.
|
||||
*/
|
||||
await createReviews( products[ 0 ] );
|
||||
products.forEach( async ( productId ) => {
|
||||
await createReviews( productId );
|
||||
} );
|
||||
|
||||
global.fixtureData = {
|
||||
taxes,
|
||||
|
|
|
@ -78,6 +78,17 @@ const ReviewsInProduct = ( id ) => [
|
|||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* Product category fixture data, using the create batch endpoint
|
||||
*
|
||||
* @see {@link https://woocommerce.github.io/woocommerce-rest-api-docs/#batch-update-product-categories|Batch update product categories}
|
||||
*/
|
||||
const Categories = () => [
|
||||
{
|
||||
name: 'Music',
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* Product fixture data, using the create batch endpoint
|
||||
*
|
||||
|
@ -103,6 +114,28 @@ const Products = () => [
|
|||
'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg',
|
||||
},
|
||||
],
|
||||
categories: [ 'Music' ],
|
||||
},
|
||||
{
|
||||
name: 'Woo Single #2',
|
||||
type: 'simple',
|
||||
regular_price: '25.99',
|
||||
virtual: true,
|
||||
downloadable: true,
|
||||
downloads: [
|
||||
{
|
||||
name: 'Woo Single 2',
|
||||
file:
|
||||
'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg',
|
||||
},
|
||||
],
|
||||
images: [
|
||||
{
|
||||
src:
|
||||
'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg',
|
||||
},
|
||||
],
|
||||
categories: [ 'Music' ],
|
||||
},
|
||||
];
|
||||
|
||||
|
@ -225,6 +258,7 @@ const Taxes = () => [
|
|||
module.exports = {
|
||||
Coupons,
|
||||
ReviewsInProduct,
|
||||
Categories,
|
||||
Products,
|
||||
Settings,
|
||||
Shipping,
|
||||
|
|
|
@ -102,6 +102,36 @@ const deleteCoupons = ( ids ) =>
|
|||
WooCommerce.post( 'coupons/batch', {
|
||||
delete: ids,
|
||||
} );
|
||||
|
||||
/**
|
||||
* Create Product Categories.
|
||||
*
|
||||
* @param {Object[]} fixture An array of objects describing our data, defaults
|
||||
* to our fixture.
|
||||
* @return {Promise} a promise that resolves to an array of newly created categories,
|
||||
* or rejects if the request failed.
|
||||
*/
|
||||
const createCategories = ( fixture = fixtures.Categories() ) =>
|
||||
WooCommerce.post( 'products/categories/batch', {
|
||||
create: fixture,
|
||||
} ).then( ( response ) => response.data.create );
|
||||
|
||||
/**
|
||||
* Delete Product Categories.
|
||||
*
|
||||
* @param {Object[]} categories an array of categories to delete.
|
||||
*
|
||||
* @return {Promise} return a promise that resolves to the deleted data or
|
||||
* reject if the request failed.
|
||||
*/
|
||||
const deleteCategories = ( categories ) => {
|
||||
const ids = categories.map( ( category ) => category.id );
|
||||
|
||||
return WooCommerce.post( 'products/categories/batch', {
|
||||
delete: ids,
|
||||
} );
|
||||
};
|
||||
|
||||
/**
|
||||
* Create Products.
|
||||
*
|
||||
|
@ -109,17 +139,29 @@ const deleteCoupons = ( ids ) =>
|
|||
*
|
||||
* @todo add more products to e2e fixtures data.
|
||||
*
|
||||
* @param {Array} categories Array of category objects so we can replace names with ids in the request.
|
||||
* @param {Object[]} fixture An array of objects describing our data, defaults
|
||||
* to our fixture.
|
||||
* @return {Promise} a promise that resolves to an array of newly created products,
|
||||
* or rejects if the request failed.
|
||||
*/
|
||||
const createProducts = ( fixture = fixtures.Products() ) =>
|
||||
WooCommerce.post( 'products/batch', {
|
||||
create: fixture,
|
||||
const createProducts = ( categories, fixture = fixtures.Products() ) => {
|
||||
const hydratedFixture = fixture.map( ( product ) => {
|
||||
if ( categories && product.categories ) {
|
||||
product.categories = product.categories.map( ( categoryName ) =>
|
||||
categories.find(
|
||||
( category ) => category.name === categoryName
|
||||
)
|
||||
);
|
||||
}
|
||||
return product;
|
||||
} );
|
||||
return WooCommerce.post( 'products/batch', {
|
||||
create: hydratedFixture,
|
||||
} ).then( ( products ) => {
|
||||
return products.data.create.map( ( product ) => product.id );
|
||||
} );
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete products.
|
||||
|
@ -139,8 +181,6 @@ const deleteProducts = ( ids ) =>
|
|||
/**
|
||||
* Create Reviews.
|
||||
*
|
||||
* This is not called directly but is called within createProducts.
|
||||
*
|
||||
* @param {number} id product id to assign reviews to.
|
||||
* @param {Object[]} fixture An array of objects describing our reviews, defaults
|
||||
* to our fixture.
|
||||
|
@ -305,6 +345,8 @@ module.exports = {
|
|||
deleteTaxes,
|
||||
createCoupons,
|
||||
deleteCoupons,
|
||||
createCategories,
|
||||
deleteCategories,
|
||||
createProducts,
|
||||
deleteProducts,
|
||||
createReviews,
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{"title":"Reviews by Category Block","pageContent":"<!-- wp:woocommerce/reviews-by-category -->\n<div class=\"wp-block-woocommerce-reviews-by-category wc-block-reviews-by-category 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\" data-category-ids=\"\"></div>\n<!-- /wp:woocommerce/reviews-by-category -->"}
|
|
@ -0,0 +1 @@
|
|||
{"title":"Reviews by Product Block","pageContent":"<!-- wp:woocommerce/reviews-by-product -->\n<div class=\"wp-block-woocommerce-reviews-by-product wc-block-all-reviews has-image has-name has-date has-rating has-content\" 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/reviews-by-product -->"}
|
|
@ -30,6 +30,6 @@ describe( `${ block.name } Block`, () => {
|
|||
'.wc-block-review-list .wc-block-review-list-item__item',
|
||||
( reviews ) => reviews.length
|
||||
)
|
||||
).toBeGreaterThanOrEqual( 3 ); // Fixture data has three reviews.
|
||||
).toBeGreaterThanOrEqual( 6 ); // Fixture data has three reviews per product.
|
||||
} );
|
||||
} );
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { switchUserToAdmin, clickButton } from '@wordpress/e2e-test-utils';
|
||||
import { visitBlockPage } from '@woocommerce/blocks-test-utils';
|
||||
|
||||
const block = {
|
||||
name: 'Reviews by Category',
|
||||
slug: 'woocommerce/reviews-by-category',
|
||||
class: '.wc-block-reviews-by-category',
|
||||
};
|
||||
|
||||
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 category selector', async () => {
|
||||
await expect( page ).toMatchElement(
|
||||
`${ block.class } .woocommerce-search-list`
|
||||
);
|
||||
} );
|
||||
|
||||
it( 'can select a category and show reviews', async () => {
|
||||
// we focus on the block
|
||||
await page.click( block.class );
|
||||
await page.waitForSelector(
|
||||
`${ block.class } .woocommerce-search-list__item`
|
||||
);
|
||||
await page.click( `${ block.class } .woocommerce-search-list__item` );
|
||||
await clickButton( 'Done' );
|
||||
// Selected.
|
||||
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( 6 ); // Fixture data has three reviews per product, and there are multiple products.
|
||||
} );
|
||||
} );
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { switchUserToAdmin, clickButton } from '@wordpress/e2e-test-utils';
|
||||
import { visitBlockPage } from '@woocommerce/blocks-test-utils';
|
||||
|
||||
const block = {
|
||||
name: 'Reviews by Product',
|
||||
slug: 'woocommerce/reviews-by-product',
|
||||
class: '.wc-block-reviews-by-product',
|
||||
};
|
||||
|
||||
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 product selector', async () => {
|
||||
await expect( page ).toMatchElement(
|
||||
`${ block.class } .woocommerce-search-list`
|
||||
);
|
||||
} );
|
||||
|
||||
it( 'can select a product and show reviews', async () => {
|
||||
// we focus on the block
|
||||
await page.click( block.class );
|
||||
await page.waitForSelector(
|
||||
`${ block.class } .woocommerce-search-list__item`
|
||||
);
|
||||
await page.click( `${ block.class } .woocommerce-search-list__item` );
|
||||
await clickButton( 'Done' );
|
||||
// Selected.
|
||||
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 per product.
|
||||
} );
|
||||
} );
|
Loading…
Reference in New Issue