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

Migrate @pages/BO/orders/shoppingCarts/view from Core #350

Merged
merged 1 commit into from
Jan 24, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
15 changes: 15 additions & 0 deletions src/interfaces/BO/orders/shoppingCarts/view.ts
Original file line number Diff line number Diff line change
@@ -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<void>;
getCartId(page: Frame|Page): Promise<string>;
getCartTotal(page: Frame|Page): Promise<number>;
getCustomerInformation(page: Frame|Page): Promise<string>;
getOrderInformation(page: Frame|Page): Promise<string>;
getTextColumn(page: Frame|Page, columnName: string, row?: number): Promise<string | null>;
goToOrderPage(page: Page): Promise<void>;
hasButtonCreateOrderFromCart(page: Frame|Page): Promise<boolean>;
}
9 changes: 9 additions & 0 deletions src/pages/BO/orders/shoppingCarts/view.ts
Original file line number Diff line number Diff line change
@@ -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();
198 changes: 198 additions & 0 deletions src/versions/develop/pages/BO/orders/shoppingCarts/view.ts
Original file line number Diff line number Diff line change
@@ -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<string>}
*/
async getCartId(page: Frame|Page): Promise<string> {
return this.getTextContent(page, this.cartSubtitle);
}

/**
* Get cart Total
* @param page {Frame|Page} Browser tab
* @returns {Promise<number>}
*/
async getCartTotal(page: Frame|Page): Promise<number> {
return this.getPriceFromText(page, this.cartTotal);
}

/**
* Get Customer Information
* @param page {Frame|Page} Browser tab
* @returns {Promise<string>}
*/
async getCustomerInformation(page: Frame|Page): Promise<string> {
return this.getTextContent(page, this.customerInformationCartBody);
}

/**
* Get Order information
* @param page {Frame|Page} Browser tab
* @returns {Promise<string>}
*/
async getOrderInformation(page: Frame|Page): Promise<string> {
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<string>}
*/
async getTextColumn(page: Frame|Page, columnName: string, row: number = 1): Promise<string | null> {
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<boolean>}
*/
async hasButtonCreateOrderFromCart(page: Frame|Page): Promise<boolean> {
return this.elementVisible(page, this.orderInformationButtonCreateOrder, 1000);
}

/**
* Click on the "Create an order from this cart." button
* @param page {Page} Browser tab
* @returns {Promise<void>}
*/
async createOrderFromThisCart(page: Page): Promise<void> {
await this.clickAndWaitForURL(page, this.orderInformationButtonCreateOrder);
}

/**
* Click on the Order link
* @param page {Page} Browser tab
* @returns {Promise<void>}
*/
async goToOrderPage(page: Page): Promise<void> {
await this.clickAndWaitForURL(page, this.orderInformationLinkOrder);
}
}

module.exports = new BOShoppingCartsViewPage();
Loading