Skip to content

Commit

Permalink
Merge pull request #444 from Progi1984/boShippingPreferencesPage
Browse files Browse the repository at this point in the history
Migrate `@pages/BO/shipping/preferences` from Core
  • Loading branch information
Progi1984 authored Feb 28, 2025
2 parents 85d2a8c + fcec1ca commit 3e139f9
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ export {default as boSearchPage} from '@pages/BO/shopParameters/search';
export {default as boSearchAliasPage} from '@pages/BO/shopParameters/search/alias';
export {default as boSearchAliasCreatePage} from '@pages/BO/shopParameters/search/alias/create';
export {default as boSecurityPage} from '@pages/BO/advancedParameters/security';
export {default as boShippingPreferencesPage} from '@pages/BO/shipping/preferences';
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';
Expand Down
11 changes: 11 additions & 0 deletions src/interfaces/BO/shipping/preferences.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type FakerCarrier from '@data/faker/carrier';
import {BOBasePagePageInterface} from '@interfaces/BO';
import {type Page} from '@playwright/test';

export interface BOShippingPreferencesInterface extends BOBasePagePageInterface {
readonly pageTitle: string;

setCarrierSortOrderBy(page: Page, sortBy: string, orderBy?: string): Promise<string>;
setDefaultCarrier(page: Page, carrier: FakerCarrier): Promise<string>;
setHandlingCharges(page: Page, value: string): Promise<string>;
}
9 changes: 9 additions & 0 deletions src/pages/BO/shipping/preferences.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type {BOShippingPreferencesInterface} from '@interfaces/BO/shipping/preferences';

/* eslint-disable global-require, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */
function requirePage(): BOShippingPreferencesInterface {
return require('@versions/develop/pages/BO/shipping/preferences');
}
/* eslint-enable global-require, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */

export default requirePage();
97 changes: 97 additions & 0 deletions src/versions/develop/pages/BO/shipping/preferences.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import type FakerCarrier from '@data/faker/carrier';
import {type BOShippingPreferencesInterface} from '@interfaces/BO/shipping/preferences';
import BOBasePage from '@pages/BO/BOBasePage';
import {type Page} from '@playwright/test';

class BOShippingPreferences extends BOBasePage implements BOShippingPreferencesInterface {
public readonly pageTitle: string;

private readonly handlingForm: string;

private readonly handlingChargesInput: string;

private readonly saveHandlingButton: string;

private readonly carrierOptionForm: string;

private readonly defaultCarrierSelect: string;

private readonly sortBySelect: string;

private readonly orderBySelect: string;

private readonly saveCarrierOptionsButton: string;

constructor() {
super();

this.pageTitle = 'Preferences •';
this.successfulUpdateMessage = 'Update successful';

// Handling form selectors
this.handlingForm = '#handling';
this.handlingChargesInput = '#handling_shipping_handling_charges';
this.saveHandlingButton = `${this.handlingForm} button`;

// Carrier options selectors
this.carrierOptionForm = '#carrier-options';
this.defaultCarrierSelect = '#carrier-options_default_carrier';
this.sortBySelect = '#carrier-options_carrier_default_order_by';
this.orderBySelect = '#carrier-options_carrier_default_order_way';
this.saveCarrierOptionsButton = `${this.carrierOptionForm} button`;
}

/* Handling methods */

/**
* Set handling charges button
* @param page {Page} Browser tab
* @param value {string} The handling charges value
* @returns {Promise<string>}
*/
async setHandlingCharges(page: Page, value: string): Promise<string> {
await this.setValue(page, this.handlingChargesInput, value);

// Save handling form and return successful message
await page.locator(this.saveHandlingButton).click();
return this.getAlertSuccessBlockParagraphContent(page);
}

/* Carrier options methods */

/**
* Set default carrier in carrier options form
* @param page {Page} Browser tab
* @param carrier {FakerCarrier} List of carriers
* @return {Promise<string>}
*/
async setDefaultCarrier(page: Page, carrier: FakerCarrier): Promise<string> {
await this.selectByVisibleText(
page,
this.defaultCarrierSelect,
`${carrier.id} - ${carrier.name} (${carrier.transitName})`,
);

// Save configuration and return successful message
await page.locator(this.saveCarrierOptionsButton).click();
return this.getAlertSuccessBlockParagraphContent(page);
}

/**
* Set carriers sort By 'Price' or 'Position' / order by 'Ascending' or 'descending' in carrier options form
* @param page {Page} Browser tab
* @param sortBy {String} Sort by 'Price' or 'Position'
* @param orderBy {String} Order by 'Ascending' or 'Descending'
* @returns {Promise<string>}
*/
async setCarrierSortOrderBy(page: Page, sortBy: string, orderBy: string = 'Ascending'): Promise<string> {
await this.selectByVisibleText(page, this.sortBySelect, sortBy);
await this.selectByVisibleText(page, this.orderBySelect, orderBy);

// Save configuration and return successful message
await page.locator(this.saveCarrierOptionsButton).click();
return this.getAlertSuccessBlockParagraphContent(page);
}
}

module.exports = new BOShippingPreferences();

0 comments on commit 3e139f9

Please sign in to comment.