POC: Array of objects

This commit is contained in:
Rodel Calasagsag 2021-06-17 13:35:00 +08:00
parent f3c9be0492
commit 1a6380c9c5
1 changed files with 44 additions and 71 deletions

View File

@ -5,16 +5,16 @@
*/ */
const { const {
merchant, merchant,
clearAndFillInput,
searchForOrder, searchForOrder,
createSimpleProduct, createSimpleProduct,
addProductToOrder, addProductToOrder,
clickUpdateOrder, clickUpdateOrder,
factories, factories,
selectOptionInSelect2,
} = require( '@woocommerce/e2e-utils' ); } = require( '@woocommerce/e2e-utils' );
const searchString = 'John Doe'; const searchString = 'John Doe';
const itemName = 'Wanted Product';
const customerBilling = { const customerBilling = {
first_name: 'John', first_name: 'John',
last_name: 'Doe', last_name: 'Doe',
@ -67,11 +67,48 @@ const updateCustomerBilling = async () => {
await client.put( customerEndpoint + customerId, customerData ); await client.put( customerEndpoint + customerId, customerData );
}; };
/**
* Function for creating individual search terms.
*
* @param f field to be printed in the test results
* @param v the search term to be typed into the search box
* @returns object containing the field and search term
*/
const createData = (f, v) => {
return {
field: f,
value: v
};
};
/**
* Data table to be fed into `it.each()`.
*/
const queries = [
createData('billing first name', customerBilling.first_name),
createData('billing last name', customerBilling.last_name),
createData('billing company name', customerBilling.company),
createData('billing first address', customerBilling.address_1),
createData('billing second address', customerBilling.address_2),
createData('billing city name', customerBilling.city),
createData('billing post code', customerBilling.postcode),
createData('billing email', customerBilling.email),
createData('billing phone', customerBilling.phone),
createData('billing state', customerBilling.state),
createData('shipping first name', customerShipping.first_name),
createData('shipping last name', customerShipping.last_name),
createData('shipping first address', customerShipping.address_1),
createData('shipping second address', customerShipping.address_2),
createData('shipping city name', customerShipping.city),
createData('shipping post code', customerShipping.postcode),
createData('shipping item name', itemName)
];
const runOrderSearchingTest = () => { const runOrderSearchingTest = () => {
describe('WooCommerce Orders > Search orders', () => { describe('WooCommerce Orders > Search orders', () => {
let orderId; let orderId;
beforeAll( async () => { beforeAll( async () => {
await createSimpleProduct('Wanted Product'); await createSimpleProduct(itemName);
await updateCustomerBilling(); await updateCustomerBilling();
// Create new order for testing // Create new order for testing
@ -90,7 +127,7 @@ const runOrderSearchingTest = () => {
// Save new order and add desired product to order // Save new order and add desired product to order
await clickUpdateOrder('Order updated.', true); await clickUpdateOrder('Order updated.', true);
await addProductToOrder(orderId, 'Wanted Product'); await addProductToOrder(orderId, itemName);
// Open All Orders view // Open All Orders view
await merchant.openAllOrdersView(); await merchant.openAllOrdersView();
@ -100,69 +137,9 @@ const runOrderSearchingTest = () => {
await searchForOrder(orderId, orderId, searchString); await searchForOrder(orderId, orderId, searchString);
}); });
it('can search for order by billing first name', async () => { it.each(queries)('can search for order by $field using search term "$value"', async ({ value }) => {
await searchForOrder(customerBilling.first_name, orderId, searchString); await searchForOrder(value, orderId, searchString);
}) });
it('can search for order by billing last name', async () => {
await searchForOrder(customerBilling.last_name, orderId, searchString);
})
it('can search for order by billing company name', async () => {
await searchForOrder(customerBilling.company, orderId, searchString);
})
it('can search for order by billing first address', async () => {
await searchForOrder(customerBilling.address_1, orderId, searchString);
})
it('can search for order by billing second address', async () => {
await searchForOrder(customerBilling.address_2, orderId, searchString);
})
it('can search for order by billing city name', async () => {
await searchForOrder(customerBilling.city, orderId, searchString);
})
it('can search for order by billing post code', async () => {
await searchForOrder(customerBilling.postcode, orderId, searchString);
})
it('can search for order by billing email', async () => {
await searchForOrder(customerBilling.email, orderId, searchString);
})
it('can search for order by billing phone', async () => {
await searchForOrder(customerBilling.phone, orderId, searchString);
})
it('can search for order by billing state', async () => {
await searchForOrder(customerBilling.state, orderId, searchString);
})
it('can search for order by shipping first name', async () => {
await searchForOrder(customerShipping.first_name, orderId, searchString);
})
it('can search for order by shipping last name', async () => {
await searchForOrder(customerShipping.last_name, orderId, searchString);
})
it('can search for order by shipping first address', async () => {
await searchForOrder(customerShipping.address_1, orderId, searchString);
})
it('can search for order by shipping second address', async () => {
await searchForOrder(customerShipping.address_2, orderId, searchString);
})
it('can search for order by shipping city name', async () => {
await searchForOrder(customerShipping.city, orderId, searchString);
})
it('can search for order by shipping postcode name', async () => {
await searchForOrder(customerShipping.postcode, orderId, searchString);
})
/** /**
* shipping state is abbreviated. This test passes if billing and shipping state are the same * shipping state is abbreviated. This test passes if billing and shipping state are the same
@ -170,10 +147,6 @@ const runOrderSearchingTest = () => {
it.skip('can search for order by shipping state name', async () => { it.skip('can search for order by shipping state name', async () => {
await searchForOrder('New York', orderId, searchString); await searchForOrder('New York', orderId, searchString);
}) })
it('can search for order by item name', async () => {
await searchForOrder('Wanted Product', orderId, searchString);
})
}); });
}; };