From a2179f8f7119b67405c22c161907b933052ec1f8 Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Fri, 24 Jan 2025 09:09:25 +0100 Subject: [PATCH] Migrate `@pages/BO/orders/shoppingCarts/view` from Core --- src/index.ts | 1 + .../BO/orders/shoppingCarts/view.ts | 15 ++ src/pages/BO/orders/shoppingCarts/view.ts | 9 + .../pages/BO/orders/shoppingCarts/view.ts | 198 ++++++++++++++++++ 4 files changed, 223 insertions(+) create mode 100644 src/interfaces/BO/orders/shoppingCarts/view.ts create mode 100644 src/pages/BO/orders/shoppingCarts/view.ts create mode 100644 src/versions/develop/pages/BO/orders/shoppingCarts/view.ts diff --git a/src/index.ts b/src/index.ts index 6509bd02..6f0af24e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -276,6 +276,7 @@ export {default as boSearchAliasPage} from '@pages/BO/shopParameters/search/alia export {default as boSearchAliasCreatePage} from '@pages/BO/shopParameters/search/alias/create'; export {default as boShopParametersPage} from '@pages/BO/shopParameters/general'; export {default as boShoppingCartsPage} from '@pages/BO/orders/shoppingCarts'; +export {default as boShoppingCartsViewPage} from '@pages/BO/orders/shoppingCarts/view'; export {default as boSqlManagerPage} from '@pages/BO/advancedParameters/database/sqlManager'; export {default as boSqlManagerCreatePage} from '@pages/BO/advancedParameters/database/sqlManager/create'; export {default as boSqlManagerViewPage} from '@pages/BO/advancedParameters/database/sqlManager/view'; diff --git a/src/interfaces/BO/orders/shoppingCarts/view.ts b/src/interfaces/BO/orders/shoppingCarts/view.ts new file mode 100644 index 00000000..0625a3ac --- /dev/null +++ b/src/interfaces/BO/orders/shoppingCarts/view.ts @@ -0,0 +1,15 @@ +import {BOBasePagePageInterface} from '@interfaces/BO'; +import {type Frame, type Page} from '@playwright/test'; + +export interface BOShoppingCartsViewPageInterface extends BOBasePagePageInterface { + readonly pageTitle: (cardID: string) => string; + + createOrderFromThisCart(page: Page): Promise; + getCartId(page: Frame|Page): Promise; + getCartTotal(page: Frame|Page): Promise; + getCustomerInformation(page: Frame|Page): Promise; + getOrderInformation(page: Frame|Page): Promise; + getTextColumn(page: Frame|Page, columnName: string, row?: number): Promise; + goToOrderPage(page: Page): Promise; + hasButtonCreateOrderFromCart(page: Frame|Page): Promise; +} diff --git a/src/pages/BO/orders/shoppingCarts/view.ts b/src/pages/BO/orders/shoppingCarts/view.ts new file mode 100644 index 00000000..6336d2a7 --- /dev/null +++ b/src/pages/BO/orders/shoppingCarts/view.ts @@ -0,0 +1,9 @@ +import {type BOShoppingCartsViewPageInterface} from '@interfaces/BO/orders/shoppingCarts/view'; + +/* eslint-disable global-require, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */ +function requirePage(): BOShoppingCartsViewPageInterface { + return require('@versions/develop/pages/BO/orders/shoppingCarts/view'); +} +/* eslint-enable global-require, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */ + +export default requirePage(); diff --git a/src/versions/develop/pages/BO/orders/shoppingCarts/view.ts b/src/versions/develop/pages/BO/orders/shoppingCarts/view.ts new file mode 100644 index 00000000..9ff0db3c --- /dev/null +++ b/src/versions/develop/pages/BO/orders/shoppingCarts/view.ts @@ -0,0 +1,198 @@ +import {type BOShoppingCartsViewPageInterface} from '@interfaces/BO/orders/shoppingCarts/view'; +import BOBasePage from '@pages/BO/BOBasePage'; +import {type Frame, type Page} from '@playwright/test'; + +/** + * View shopping page, contains functions that can be used on view shopping cart page + * @class + * @extends BOBasePage + */ +class BOShoppingCartsViewPage extends BOBasePage implements BOShoppingCartsViewPageInterface { + public readonly pageTitle: (cardID: string) => string; + + private readonly cartSubtitle: string; + + private readonly cartTotal: string; + + private readonly customerInformationBlock: string; + + private readonly customerInformationCartBody: string; + + private readonly orderInformationBlock: string; + + private readonly orderInformationBlockBody: string; + + private readonly orderInformationButtonCreateOrder: string; + + private readonly orderInformationLinkOrder: string; + + private readonly cartSummaryBlock: string; + + private readonly cartSummaryBlockBody: string; + + private readonly cartSummaryTable: string; + + private readonly cartSummaryTableBody: string; + + private readonly cartSummaryTableRow: (row: number) => string; + + private readonly cartSummaryTableColumn: (row: number, column: number) => string; + + /** + * @constructs + * Setting up texts and selectors to use on view shopping cart page + */ + constructor() { + super(); + + this.pageTitle = (cartID: string) => `Cart #${cartID} • ${global.INSTALL.SHOP_NAME}`; + + // Selectors + this.cartSubtitle = '#box-kpi-cart div.subtitle'; + this.cartTotal = '#box-kpi-cart div.value'; + + // Customer Block + this.customerInformationBlock = '#main-div div[data-role="customer-information"]'; + this.customerInformationCartBody = `${this.customerInformationBlock} .card-body`; + + // Order Information Block + this.orderInformationBlock = '#main-div div[data-role="order-information"]'; + this.orderInformationBlockBody = `${this.orderInformationBlock} .card-body`; + this.orderInformationButtonCreateOrder = `${this.orderInformationBlockBody} #create-order-from-cart`; + this.orderInformationLinkOrder = `${this.orderInformationBlockBody} a.btn`; + + // Cart Summary Block + this.cartSummaryBlock = '#main-div div[data-role="cart-summary"]'; + this.cartSummaryBlockBody = `${this.cartSummaryBlock} .card-body`; + this.cartSummaryTable = `${this.cartSummaryBlockBody} .table`; + this.cartSummaryTableBody = `${this.cartSummaryTable} tbody`; + this.cartSummaryTableRow = (row: number) => `${this.cartSummaryTableBody} tr:nth-child(${row})`; + this.cartSummaryTableColumn = (row: number, column: number) => `${this.cartSummaryTableRow(row)} td:nth-child(${column})`; + } + + /* + Methods + */ + /** + * Get cart ID + * @param page {Page|Frame} Browser tab + * @returns {Promise} + */ + async getCartId(page: Frame|Page): Promise { + return this.getTextContent(page, this.cartSubtitle); + } + + /** + * Get cart Total + * @param page {Frame|Page} Browser tab + * @returns {Promise} + */ + async getCartTotal(page: Frame|Page): Promise { + return this.getPriceFromText(page, this.cartTotal); + } + + /** + * Get Customer Information + * @param page {Frame|Page} Browser tab + * @returns {Promise} + */ + async getCustomerInformation(page: Frame|Page): Promise { + return this.getTextContent(page, this.customerInformationCartBody); + } + + /** + * Get Order information + * @param page {Frame|Page} Browser tab + * @returns {Promise} + */ + async getOrderInformation(page: Frame|Page): Promise { + return this.getTextContent(page, this.orderInformationBlockBody); + } + + /** + * Get text from column in table + * @param page {Frame|Page} Browser tab + * @param columnName {string} Column on table + * @param row {number} Row on table + * @returns {Promise} + */ + async getTextColumn(page: Frame|Page, columnName: string, row: number = 1): Promise { + let columnSelector; + + switch (columnName) { + case 'image': + columnSelector = `${this.cartSummaryTableColumn(row, 1)} img`; + break; + + case 'title': + columnSelector = this.cartSummaryTableColumn(row, 2); + break; + + case 'unit_price': + columnSelector = this.cartSummaryTableColumn(row, 3); + break; + + case 'quantity': + columnSelector = this.cartSummaryTableColumn(row, 4); + break; + + case 'stock_available': + columnSelector = this.cartSummaryTableColumn(row, 5); + break; + + case 'total': + columnSelector = this.cartSummaryTableColumn(row, 6); + break; + + case 'total_cost_products': + columnSelector = this.cartSummaryTableColumn(row + 1, 2); + break; + + case 'total_cost_shipping': + columnSelector = this.cartSummaryTableColumn(row + 2, 2); + break; + + case 'total_cart': + columnSelector = this.cartSummaryTableColumn(row + 3, 2); + break; + + default: + throw new Error(`Column ${columnName} was not found`); + } + + if (columnName === 'image') { + return this.getAttributeContent(page, columnSelector, 'src'); + } + + return this.getTextContent(page, columnSelector); + } + + /** + * Check if the button "Create an order from this cart." exists + * @param page {Frame|Page} Browser tab + * @returns {Promise} + */ + async hasButtonCreateOrderFromCart(page: Frame|Page): Promise { + return this.elementVisible(page, this.orderInformationButtonCreateOrder, 1000); + } + + /** + * Click on the "Create an order from this cart." button + * @param page {Page} Browser tab + * @returns {Promise} + */ + async createOrderFromThisCart(page: Page): Promise { + await this.clickAndWaitForURL(page, this.orderInformationButtonCreateOrder); + } + + /** + * Click on the Order link + * @param page {Page} Browser tab + * @returns {Promise} + */ + async goToOrderPage(page: Page): Promise { + await this.clickAndWaitForURL(page, this.orderInformationLinkOrder); + } +} + +module.exports = new BOShoppingCartsViewPage();