diff --git a/src/data/faker/cartRule.ts b/src/data/faker/cartRule.ts index aa681336b..efd3edb06 100644 --- a/src/data/faker/cartRule.ts +++ b/src/data/faker/cartRule.ts @@ -71,7 +71,7 @@ export default class FakerCartRule { public readonly discountType: string; - public readonly discountPercent: number | null; + public discountPercent: number | string | null; public readonly discountAmount: CartRuleDiscountAmount | null; @@ -205,4 +205,14 @@ export default class FakerCartRule { this.freeGiftProduct = cartRuleToCreate.freeGiftProduct || null; } } + + getDiscountPercent(): number { + return parseInt(this.discountPercent!.toString(), 10); + } + + setDiscountPercent(discountPercent: number|string|null): this { + this.discountPercent = discountPercent; + + return this; + } } diff --git a/src/interfaces/BO/catalog/discounts/create.ts b/src/interfaces/BO/catalog/discounts/create.ts index 36c2d0b73..ce449ce7a 100644 --- a/src/interfaces/BO/catalog/discounts/create.ts +++ b/src/interfaces/BO/catalog/discounts/create.ts @@ -4,6 +4,8 @@ import {type Frame, type Page} from '@playwright/test'; export interface BOCartRulesCreatePageInterface extends BOBasePagePageInterface { readonly editPageTitle: string; + readonly errorMessageFieldInvalid: (field: string) => string; + readonly errorMessageReductionPercentageBetween: string; readonly pageTitle: string; clickOnCancelButton(page: Page): Promise; diff --git a/src/interfaces/FO/cart/index.ts b/src/interfaces/FO/cart/index.ts index d5d1b2b5e..cc3b14077 100644 --- a/src/interfaces/FO/cart/index.ts +++ b/src/interfaces/FO/cart/index.ts @@ -29,7 +29,7 @@ export interface FoCartPageInterface extends FOBasePagePageInterface { getAlertWarningForPromoCode(page: Page): Promise; getCartRuleErrorMessage(page: Page): Promise; getCartRuleName(page: Page, line?: number): Promise; - getDiscountValue(page: Page, line?: number): Promise; + getCartRuleValue(page: Page, line?: number): Promise; getHighlightPromoCode(page: Page): Promise; getNoItemsInYourCartMessage(page: Page): Promise; getNotificationMessage(page: Page): Promise; diff --git a/src/utils/core.ts b/src/utils/core.ts index c18c0a3fe..807afaea7 100644 --- a/src/utils/core.ts +++ b/src/utils/core.ts @@ -33,12 +33,12 @@ export default { }, /** - * Calculate percentage - * @param num {number|float} Number to do the percentage - * @param percentage {number} Percentage value - * @returns {Promise} - */ - async percentage(num: number, percentage: number): Promise { + * Calculate percentage + * @param num {number|float} Number to do the percentage + * @param percentage {number} Percentage value + * @returns {number|float} + */ + percentage(num: number, percentage: number): number { return (num / 100) * percentage; }, diff --git a/src/versions/develop/pages/BO/catalog/discounts/create.ts b/src/versions/develop/pages/BO/catalog/discounts/create.ts index 679a57104..e3dc908bd 100644 --- a/src/versions/develop/pages/BO/catalog/discounts/create.ts +++ b/src/versions/develop/pages/BO/catalog/discounts/create.ts @@ -13,6 +13,10 @@ class BOCartRulesCreatePage extends BOBasePage implements BOCartRulesCreatePageI public readonly editPageTitle: string; + public readonly errorMessageReductionPercentageBetween: string; + + public readonly errorMessageFieldInvalid: (field: string) => string; + private readonly cartRuleForm: string; private readonly infomationsTabLink: string; @@ -167,6 +171,10 @@ class BOCartRulesCreatePage extends BOBasePage implements BOCartRulesCreatePageI this.pageTitle = 'Cart Rules > Add new •'; this.editPageTitle = 'Cart Rules > Edit'; + // Messages + this.errorMessageReductionPercentageBetween = 'Reduction percentage must be between 0% and 100%'; + this.errorMessageFieldInvalid = (field: string) => `The ${field} field is invalid.`; + // Selectors this.cartRuleForm = '#cart_rule_form'; @@ -541,10 +549,10 @@ class BOCartRulesCreatePage extends BOBasePage implements BOCartRulesCreatePageI async saveCartRule(page: Frame | Page): Promise { await this.clickAndWaitForURL(page, this.saveButton); - if (await this.elementVisible(page, `${this.alertSuccessBlock}[role='alert']`, 2000)) { - return this.getTextContent(page, `${this.alertSuccessBlock}[role='alert']`); + if (await this.elementVisible(page, `${this.alertBlock}[role='alert']`, 2000)) { + return this.getTextContent(page, `${this.alertBlock}[role='alert']`); } - return this.getTextContent(page, this.alertSuccessBlock); + return this.getTextContent(page, this.alertBlock); } /** diff --git a/src/versions/develop/pages/FO/classic/cart/index.ts b/src/versions/develop/pages/FO/classic/cart/index.ts index f0c0e6fdc..a4ac149cd 100644 --- a/src/versions/develop/pages/FO/classic/cart/index.ts +++ b/src/versions/develop/pages/FO/classic/cart/index.ts @@ -519,22 +519,22 @@ class CartPage extends FOBasePage implements FoCartPageInterface { } /** - * Get cart rule error text + * Get cart rule value * @param page {Page} Browser tab - * @returns {Promise} + * @param line {number} Cart rule line + * @return {string} */ - async getCartRuleErrorMessage(page: Page): Promise { - return this.getTextContent(page, this.cartRuleAlertMessage); + async getCartRuleValue(page: Page, line: number = 1): Promise { + return this.getTextContent(page, this.discountValue(line)); } /** - * Get discount value + * Get cart rule error text * @param page {Page} Browser tab - * @param line {number} Cart summary line - * @returns {Promise} + * @returns {Promise} */ - async getDiscountValue(page: Page, line: number = 1): Promise { - return this.getPriceFromText(page, this.discountValue(line), 2000); + async getCartRuleErrorMessage(page: Page): Promise { + return this.getTextContent(page, this.cartRuleAlertMessage); } /**