Fix instantiation of grouped product variables
This commit is contained in:
parent
78ef1e4411
commit
f2305a2486
|
@ -21,6 +21,7 @@ const defaultVariableProduct = config.get( 'products.variable' );
|
||||||
let variableProductId;
|
let variableProductId;
|
||||||
|
|
||||||
// Variables for grouped product
|
// Variables for grouped product
|
||||||
|
const simpleProductPrice = config.has('products.simple.price') ? config.get('products.simple.price') : '9.99';
|
||||||
let groupedPostIdValue;
|
let groupedPostIdValue;
|
||||||
|
|
||||||
const runSingleProductPageTest = () => {
|
const runSingleProductPageTest = () => {
|
||||||
|
@ -86,7 +87,22 @@ const runSingleProductPageTest = () => {
|
||||||
|
|
||||||
describe('Grouped Product Page', () => {
|
describe('Grouped Product Page', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
groupedPostIdValue = await createGroupedProduct();
|
// Instantiate simple products to be grouped
|
||||||
|
const simple1 = {
|
||||||
|
name: simpleProductName + ' 1',
|
||||||
|
regularPrice: simpleProductPrice
|
||||||
|
};
|
||||||
|
const simple2 = {
|
||||||
|
name: simpleProductName + ' 2',
|
||||||
|
regularPrice: simpleProductPrice
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create grouped product
|
||||||
|
const groupedProduct = {
|
||||||
|
name: 'Grouped Product',
|
||||||
|
groupedProducts: [simple1, simple2]
|
||||||
|
};
|
||||||
|
groupedPostIdValue = await createGroupedProduct(groupedProduct);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to add grouped products to the cart', async () => {
|
it('should be able to add grouped products to the cart', async () => {
|
||||||
|
@ -94,37 +110,51 @@ const runSingleProductPageTest = () => {
|
||||||
await shopper.goToProduct(groupedPostIdValue);
|
await shopper.goToProduct(groupedPostIdValue);
|
||||||
await page.waitForSelector('form.grouped_form');
|
await page.waitForSelector('form.grouped_form');
|
||||||
await shopper.addToCart();
|
await shopper.addToCart();
|
||||||
await expect(page).toMatchElement('.woocommerce-error',
|
await expect(page).toMatchElement('.woocommerce-error', {
|
||||||
{text: 'Please choose the quantity of items you wish to add to your cart…'});
|
text:
|
||||||
|
'Please choose the quantity of items you wish to add to your cart…'
|
||||||
|
});
|
||||||
const quantityFields = await page.$$('div.quantity input.qty');
|
const quantityFields = await page.$$('div.quantity input.qty');
|
||||||
await quantityFields[0].click({clickCount: 3});
|
await quantityFields[0].click({ clickCount: 3 });
|
||||||
await quantityFields[0].type('5');
|
await quantityFields[0].type('5');
|
||||||
await quantityFields[1].click({clickCount: 3});
|
await quantityFields[1].click({ clickCount: 3 });
|
||||||
await quantityFields[1].type('5');
|
await quantityFields[1].type('5');
|
||||||
await shopper.addToCart();
|
await shopper.addToCart();
|
||||||
await expect(page).toMatchElement('.woocommerce-message',
|
await expect(page).toMatchElement('.woocommerce-message', {
|
||||||
{text: '“'+simpleProductName+' 1” and “'+simpleProductName+' 2” have been added to your cart.'});
|
text:
|
||||||
|
'“' +
|
||||||
|
simpleProductName +
|
||||||
|
' 1” and “' +
|
||||||
|
simpleProductName +
|
||||||
|
' 2” have been added to your cart.'
|
||||||
|
});
|
||||||
|
|
||||||
// Verify cart contents
|
// Verify cart contents
|
||||||
await shopper.goToCart();
|
await shopper.goToCart();
|
||||||
await shopper.productIsInCart(simpleProductName+' 1');
|
await shopper.productIsInCart(simpleProductName + ' 1');
|
||||||
await shopper.productIsInCart(simpleProductName+' 2');
|
await shopper.productIsInCart(simpleProductName + ' 2');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to remove grouped products from the cart', async () => {
|
it('should be able to remove grouped products from the cart', async () => {
|
||||||
// Remove items from cart
|
// Remove items from cart
|
||||||
await shopper.removeFromCart(simpleProductName+' 1');
|
await shopper.removeFromCart(simpleProductName + ' 1');
|
||||||
await uiUnblocked();
|
await uiUnblocked();
|
||||||
await expect(page).toMatchElement('.woocommerce-message', {text: '“'+simpleProductName+' 1” removed.'});
|
await expect(page).toMatchElement('.woocommerce-message', {
|
||||||
await Promise.all( [
|
text: '“' + simpleProductName + ' 1” removed.'
|
||||||
|
});
|
||||||
|
await Promise.all([
|
||||||
// Reload page and perform item removal, since removeFromCart won't remove it when placed in a row
|
// Reload page and perform item removal, since removeFromCart won't remove it when placed in a row
|
||||||
page.reload(),
|
page.reload(),
|
||||||
page.waitForNavigation( { waitUntil: 'networkidle0' } ),
|
page.waitForNavigation({ waitUntil: 'networkidle0' })
|
||||||
] );
|
]);
|
||||||
await shopper.removeFromCart(simpleProductName+' 2');
|
await shopper.removeFromCart(simpleProductName + ' 2');
|
||||||
await uiUnblocked();
|
await uiUnblocked();
|
||||||
await expect(page).toMatchElement('.woocommerce-message', {text: '“'+simpleProductName+' 2” removed.'});
|
await expect(page).toMatchElement('.woocommerce-message', {
|
||||||
await expect(page).toMatchElement('.cart-empty', {text: 'Your cart is currently empty.'});
|
text: '“' + simpleProductName + ' 2” removed.'
|
||||||
|
});
|
||||||
|
await expect(page).toMatchElement('.cart-empty', {
|
||||||
|
text: 'Your cart is currently empty.'
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,6 +23,7 @@ const config = require( 'config' );
|
||||||
const simpleProductName = config.get( 'products.simple.name' );
|
const simpleProductName = config.get( 'products.simple.name' );
|
||||||
const simpleProductPrice = config.has('products.simple.price') ? config.get('products.simple.price') : '9.99';
|
const simpleProductPrice = config.has('products.simple.price') ? config.get('products.simple.price') : '9.99';
|
||||||
const defaultVariableProduct = config.get('products.variable');
|
const defaultVariableProduct = config.get('products.variable');
|
||||||
|
const defaultGroupedProduct = config.get('products.grouped');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify and publish
|
* Verify and publish
|
||||||
|
@ -226,7 +227,7 @@ const createSimpleProductWithCategory = async ( productName, productPrice, categ
|
||||||
*/
|
*/
|
||||||
const createVariableProduct = async (varProduct = defaultVariableProduct) => {
|
const createVariableProduct = async (varProduct = defaultVariableProduct) => {
|
||||||
const { attributes } = varProduct;
|
const { attributes } = varProduct;
|
||||||
const { id } = await factories.products.variable.create(varProduct);
|
const { id } = await factories.products.variable.create(varProduct); // create the variable product
|
||||||
const variations = [];
|
const variations = [];
|
||||||
const buffer = []; // accumulated attributes while looping
|
const buffer = []; // accumulated attributes while looping
|
||||||
const aIdx = 0; // attributes[] index
|
const aIdx = 0; // attributes[] index
|
||||||
|
@ -292,25 +293,28 @@ const createVariableProduct = async (varProduct = defaultVariableProduct) => {
|
||||||
/**
|
/**
|
||||||
* Create grouped product.
|
* Create grouped product.
|
||||||
*
|
*
|
||||||
|
* @param groupedProduct Defaults to the grouped product object in `default.json`
|
||||||
* @returns ID of the grouped product
|
* @returns ID of the grouped product
|
||||||
*/
|
*/
|
||||||
const createGroupedProduct = async () => {
|
const createGroupedProduct = async (groupedProduct = defaultGroupedProduct) => {
|
||||||
// Create two products to be linked in a grouped product after
|
const { name, groupedProducts } = groupedProduct;
|
||||||
const simple1 = await factories.products.simple.create({
|
const simpleProductIds = [];
|
||||||
name: simpleProductName + ' 1',
|
let groupedProductRequest;
|
||||||
regularPrice: simpleProductPrice
|
|
||||||
});
|
|
||||||
const simple2 = await factories.products.simple.create({
|
|
||||||
name: simpleProductName + ' 2',
|
|
||||||
regularPrice: simpleProductPrice
|
|
||||||
});
|
|
||||||
const groupedProduct = {
|
|
||||||
name: 'Grouped Product',
|
|
||||||
type: 'grouped',
|
|
||||||
groupedProducts: [simple1.id, simple2.id]
|
|
||||||
};
|
|
||||||
|
|
||||||
const { id } = await factories.products.grouped.create(groupedProduct);
|
// Using the api, create simple products to be grouped
|
||||||
|
for (const simpleProduct of groupedProducts) {
|
||||||
|
const { id } = await factories.products.simple.create(simpleProduct);
|
||||||
|
simpleProductIds.push(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Using the api, create the grouped product
|
||||||
|
groupedProductRequest = {
|
||||||
|
name: name,
|
||||||
|
groupedProducts: simpleProductIds
|
||||||
|
};
|
||||||
|
const { id } = await factories.products.grouped.create(
|
||||||
|
groupedProductRequest
|
||||||
|
);
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue