Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functional Tests : BO - Catalog - Products : Pack Tab #33963

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ describe('BO - Catalog - Products : CRUD pack of products', async () => {
it(`should check the product '${test.args.product.name}' in the pack`, async function () {
await testContext.addContextItem(this, 'testIdentifier', `checkProductInPack${index}`, baseContext);

const result = await foProductPage.getProductInPackList(page, index + 2);
const result = await foProductPage.getProductInPackList(page, index + 1);
await Promise.all([
await expect(result.image).to.contains(test.args.product.coverImage),
await expect(result.name).to.equal(test.args.product.name),
Expand Down Expand Up @@ -470,7 +470,7 @@ describe('BO - Catalog - Products : CRUD pack of products', async () => {
it(`should check the product '${test.args.product.name}' in the pack`, async function () {
await testContext.addContextItem(this, 'testIdentifier', `checkEditProductInPack${index}`, baseContext);

const result = await foProductPage.getProductInPackList(page, index + 2);
const result = await foProductPage.getProductInPackList(page, index + 1);
await Promise.all([
await expect(result.image).to.contains(test.args.product.coverImage),
await expect(result.name).to.equal(test.args.product.name),
Expand Down
580 changes: 580 additions & 0 deletions tests/UI/campaigns/productV2/functional/12_packTab.ts

Large diffs are not rendered by default.

39 changes: 27 additions & 12 deletions tests/UI/data/demo/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,20 @@ export default {
quantity: 1200,
status: true,
}),
demo_12: new ProductData({
id: 7,
name: 'Mug The adventure begins',
thumbImage: 'mug-the-adventure-begins.jpg',
coverImage: 'mug-the-adventure-begins.jpg',
reference: 'demo_12',
category: 'Home Accessories',
summary: 'White Ceramic Mug. 325ml',
priceTaxExcluded: 11.9,
price: 14.28,
tax: 20,
quantity: 300,
demo_9: new ProductData({
id: 17,
name: 'Brown bear notebook',
reference: 'demo_9',
category: 'Stationery',
price: 15.48,
quantity: 1200,
status: true,
attributes: [
{
name: 'Paper Type',
values: ['Ruled', 'Plain', 'Squarred', 'Doted'],
},
],
}),
demo_11: new ProductData({
id: 6,
Expand All @@ -127,6 +128,20 @@ export default {
quantity: 300,
status: true,
}),
demo_12: new ProductData({
id: 7,
name: 'Mug The adventure begins',
thumbImage: 'mug-the-adventure-begins.jpg',
coverImage: 'mug-the-adventure-begins.jpg',
reference: 'demo_12',
category: 'Home Accessories',
summary: 'White Ceramic Mug. 325ml',
priceTaxExcluded: 11.9,
price: 14.28,
tax: 20,
quantity: 300,
status: true,
}),
demo_13: new ProductData({
id: 8,
name: 'Mug Today is a good day',
Expand Down
4 changes: 3 additions & 1 deletion tests/UI/pages/BO/catalog/productsV2/add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ class CreateProduct extends BOBasePage {
priceTaxExc: await this.getTextContent(page, this.productHeaderTaxExcluded),
priceTaxIncl: await this.getTextContent(page, this.productHeaderTaxIncluded),
quantity: await this.getTextContent(page, this.productHeaderQuantity, false),
reference: await this.getTextContent(page, this.productHeaderReference('reference'), false),
reference: (await page.locator(this.productHeaderReference('reference')).count())
? await this.getTextContent(page, this.productHeaderReference('reference'), false)
: '',
Comment on lines +214 to +216
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe create specific functions for this one and others, so we could use individually ?

mpn: (await page.locator(this.productHeaderReference('mpn')).count())
? await this.getTextContent(page, this.productHeaderReference('mpn'), false)
: '',
Expand Down
37 changes: 33 additions & 4 deletions tests/UI/pages/BO/catalog/productsV2/add/packTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class PackTab extends BOBasePage {

private readonly alertDangerProductInPack: (productInList: number) => string;

private readonly editQuantityBase: string;

private readonly editQuantityInput: string;

private readonly minimalQuantityInput: string;
Expand Down Expand Up @@ -108,6 +110,7 @@ class PackTab extends BOBasePage {
+ 'delta_quantity + span';

// Edit quantity selectors
this.editQuantityBase = 'input#product_stock_quantities_delta_quantity_quantity';
this.editQuantityInput = '#product_stock_quantities_delta_quantity_delta';
this.minimalQuantityInput = '#product_stock_quantities_minimal_quantity';
this.packStockTypeRadioButton = (buttonRow: number) => `#product_stock_pack_stock_type_${buttonRow} +i`;
Expand Down Expand Up @@ -245,7 +248,7 @@ class PackTab extends BOBasePage {
async getStockMovement(page: Page, movementRow: number): Promise<ProductStockMovement> {
return {
dateTime: await this.getTextContent(page, this.dateTimeRowInTable(movementRow - 1)),
employee: await this.getTextContent(page, this.employeeRowInTable(movementRow - 1)),
employee: await this.getTextContent(page, this.employeeRowInTable(movementRow - 1), false),
quantity: await this.getNumberFromText(page, this.quantityRowInTable(movementRow - 1)),
};
}
Expand Down Expand Up @@ -301,10 +304,27 @@ class PackTab extends BOBasePage {
* @param packData {ProductPackOptions} Data to edit pack of products
*/
async editPackOfProducts(page: Page, packData: ProductPackOptions): Promise<void> {
await this.setValue(page, this.editQuantityInput, packData.quantity);
await this.editQuantity(page, packData.quantity);
await this.setValue(page, this.minimalQuantityInput, packData.minimalQuantity);
await this.editPackStockType(page, packData.packQuantitiesOption);
}

/**
* Edit quantity
* @param page {Page} Browser tab
* @param quantity {number} Quantity
*/
async editQuantity(page: Page, quantity: number): Promise<void> {
await this.setValue(page, this.editQuantityInput, quantity);
}

switch (packData.packQuantitiesOption) {
/**
* Edit quantity
* @param page {Page} Browser tab
* @param packStockType {string} Quantity
*/
async editPackStockType(page: Page, packStockType: string): Promise<void> {
switch (packStockType) {
case 'Decrement pack only':
await page.click(this.packStockTypeRadioButton(0));
break;
Expand All @@ -322,9 +342,18 @@ class PackTab extends BOBasePage {
break;

default:
throw new Error(`Radio button for ${packData.packQuantitiesOption} was not found`);
throw new Error(`Radio button for ${packStockType} was not found`);
}
}

/**
* Get the value of the stock
* @param page {Page} Browser tab
* @return <Promise<number>>
*/
async getStockValue(page: Page): Promise<number> {
return parseInt(await page.locator(this.editQuantityBase).getAttribute('value') ?? '', 10);
}
}

export default new PackTab();
12 changes: 6 additions & 6 deletions tests/UI/pages/BO/catalog/productsV2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ class Products extends BOBasePage {
await this.waitForVisibleSelector(page, `${this.modalCreateProduct} iframe`);
await this.waitForHiddenSelector(page, this.modalCreateProductLoader);

const createProductFrame: Frame | null = await page.frame({url: /sell\/catalog\/products-v2\/create/gmi});
await expect(createProductFrame).to.be.not.null;
const createProductFrame: Frame | null = page.frame({url: /sell\/catalog\/products-v2\/create/gmi});
expect(createProductFrame).to.be.not.eq(null);
Comment on lines +307 to +308
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect should be removed from pages (I think it's a WIP on delete productV1)


return this.getTextContent(createProductFrame!, this.productTypeDescription);
}
Expand All @@ -329,8 +329,8 @@ class Products extends BOBasePage {
await this.waitForVisibleSelector(page, `${this.modalCreateProduct} iframe`);
await this.waitForHiddenSelector(page, this.modalCreateProductLoader);

const createProductFrame: Frame | null = await page.frame({url: /sell\/catalog\/products-v2\/create/gmi});
await expect(createProductFrame).to.be.not.null;
const createProductFrame: Frame | null = page.frame({url: /sell\/catalog\/products-v2\/create/gmi});
expect(createProductFrame).to.be.not.eq(null);

await this.waitForSelectorAndClick(createProductFrame!, this.productType(productType));
}
Expand All @@ -341,8 +341,8 @@ class Products extends BOBasePage {
* @returns {Promise<void>}
*/
async clickOnAddNewProduct(page: Page): Promise<void> {
const createProductFrame: Frame | null = await page.frame({url: /sell\/catalog\/products-v2\/create/gmi});
await expect(createProductFrame).to.be.not.null;
const createProductFrame: Frame | null = page.frame({url: /sell\/catalog\/products-v2\/create/gmi});
expect(createProductFrame).to.be.not.eq(null);

await this.waitForSelectorAndClick(createProductFrame!, this.addNewProductButton);
}
Expand Down
41 changes: 29 additions & 12 deletions tests/UI/pages/FO/product/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class Product extends FOBasePage {

private readonly regularPrice: string;

private readonly packProductsPrice: string;

private readonly productPrice: string;

private readonly taxShippingDeliveryBlock: string;
Expand Down Expand Up @@ -181,6 +183,7 @@ class Product extends FOBasePage {
this.discountAmountSpan = `${this.productPricesBlock} .discount.discount-amount`;
this.discountPercentageSpan = `${this.productPricesBlock} .discount.discount-percentage`;
this.regularPrice = `${this.productPricesBlock} .regular-price`;
this.packProductsPrice = `${this.productPricesBlock} .product-pack-price span`;
this.productPrice = `${this.productPricesBlock} .current-price span`;
this.taxShippingDeliveryBlock = `${this.productPricesBlock} div.tax-shipping-delivery-label`;
this.deliveryInformationSpan = `${this.taxShippingDeliveryBlock} span.delivery-information`;
Expand Down Expand Up @@ -246,7 +249,7 @@ class Product extends FOBasePage {
* @param page {Page} Browser tab
* @return {Promise<boolean>}
*/
isProductTagVisible(page: Page): Promise<boolean> {
async isProductTagVisible(page: Page): Promise<boolean> {
return this.elementVisible(page, this.productFlag);
}

Expand All @@ -260,7 +263,9 @@ class Product extends FOBasePage {
name: await this.getTextContent(page, this.productName),
price: await this.getPriceFromText(page, this.productPrice),
summary: await this.getTextContent(page, this.shortDescription, false),
description: await this.getTextContent(page, this.productDescription),
description: (await page.locator(`${this.productDescription}:visible`).count())
? await this.getTextContent(page, this.productDescription)
: '',
};
}

Expand All @@ -274,11 +279,14 @@ class Product extends FOBasePage {
image: string | null, quantity: number,
price: string, name: string
}> {
// Add +1 due to span before the article
const productIdentifier: number = productInList + 1;

return {
image: await this.getAttributeContent(page, this.productInPackImage(productInList), 'src'),
name: await this.getTextContent(page, this.productInPackName(productInList)),
price: await this.getTextContent(page, this.productInPackPrice(productInList)),
quantity: await this.getNumberFromText(page, this.productInPackQuantity(productInList)),
image: await this.getAttributeContent(page, this.productInPackImage(productIdentifier), 'src'),
name: await this.getTextContent(page, this.productInPackName(productIdentifier)),
price: await this.getTextContent(page, this.productInPackPrice(productIdentifier)),
quantity: await this.getNumberFromText(page, this.productInPackQuantity(productIdentifier)),
};
}

Expand All @@ -287,17 +295,26 @@ class Product extends FOBasePage {
* @param page {Page} Browser tab
* @returns {Promise<number>}
*/
getRegularPrice(page: Page): Promise<number> {
async getRegularPrice(page: Page): Promise<number> {
return this.getPriceFromText(page, this.regularPrice);
}

/**
* Get the price of products in pack
* @param page {Page} Browser tab
* @returns {Promise<number>}
*/
async getPackProductsPrice(page: Page): Promise<number> {
return this.getPriceFromText(page, this.packProductsPrice);
}

/**
* Get product attributes from a Ul selector
* @param page {Page} Browser tab
* @param ulSelector {string} Selector to locate the element
* @returns {Promise<Array<string>>}
*/
getProductsAttributesFromUl(page: Page, ulSelector: string): Promise<Array<string | null>> {
async getProductsAttributesFromUl(page: Page, ulSelector: string): Promise<Array<string | null>> {
return page.$$eval(`${ulSelector} li .attribute-name`, (all) => all.map((el) => el.textContent));
}

Expand Down Expand Up @@ -381,7 +398,7 @@ class Product extends FOBasePage {
* @param page {Page} Browser tab
* @returns {Promise<string>}
*/
getDiscountAmount(page: Page): Promise<string> {
async getDiscountAmount(page: Page): Promise<string> {
return this.getTextContent(page, this.discountAmountSpan);
}

Expand All @@ -390,7 +407,7 @@ class Product extends FOBasePage {
* @param page {Page} Browser tab
* @returns {Promise<string>}
*/
getDiscountPercentage(page: Page): Promise<string> {
async getDiscountPercentage(page: Page): Promise<string> {
return this.getTextContent(page, this.discountPercentageSpan);
}

Expand All @@ -399,7 +416,7 @@ class Product extends FOBasePage {
* @param page {Page} Browser tab
* @return {promise<string>}
*/
getProductAvailabilityLabel(page: Page): Promise<string> {
async getProductAvailabilityLabel(page: Page): Promise<string> {
return this.getTextContent(page, this.productAvailability, false);
}

Expand All @@ -408,7 +425,7 @@ class Product extends FOBasePage {
* @param page {Page} Browser tab
* @return {Promise<string>}
*/
getDeliveryInformationText(page: Page): Promise<string> {
async getDeliveryInformationText(page: Page): Promise<string> {
return this.getTextContent(page, this.deliveryInformationSpan);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/UI/pages/commonPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export default class CommonPage {
async getNumberFromText(page: Page | Frame, selector: string, timeout: number = 0): Promise<number> {
await page.waitForTimeout(timeout);
const text = await this.getTextContent(page, selector, false);
const number = (/\d+/g.exec(text) ?? '').toString();
const number = (/-?\d+/g.exec(text) ?? '').toString();

return parseInt(number, 10);
}
Expand Down
9 changes: 9 additions & 0 deletions tests/UI/utils/basicHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,13 @@ export default {

return age;
},

/**
* Make a string's first character uppercase
* @param value {string}
* @returns {string}
*/
capitalize(value: string): string {
return value.charAt(0).toUpperCase() + value.slice(1);
},
};