Skip to content

Commit

Permalink
Migrate @pages/BO/customers/add from Core
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Jan 15, 2025
1 parent 9c1bb91 commit 7c81cf7
Show file tree
Hide file tree
Showing 5 changed files with 236 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 @@ -205,6 +205,7 @@ export {default as boCustomerSettingsPage} from '@pages/BO/shopParameters/custom
export {default as boCurrenciesCreatePage} from '@pages/BO/international/localization/currencies/create';
export {default as boCurrenciesPage} from '@pages/BO/international/localization/currencies';
export {default as boCustomersPage} from '@pages/BO/customers';
export {default as boCustomersCreatePage} from '@pages/BO/customers/create';
export {default as boDashboardPage} from '@pages/BO/dashboard';
export {default as boDbBackupPage} from '@pages/BO/advancedParameters/database/dbBackup';
export {default as boDesignEmailThemesPage} from '@pages/BO/design/emailThemes';
Expand Down
11 changes: 11 additions & 0 deletions src/interfaces/BO/customers/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type FakerCustomer from '@data/faker/customer';
import {BOBasePagePageInterface} from '@interfaces/BO';
import {type Frame, type Page} from '@playwright/test';

export interface BOCustomersCreatePageInterface extends BOBasePagePageInterface {
readonly pageTitleCreate: string;
readonly pageTitleEdit: string;

createEditB2BCustomer(page: Page, customerData: FakerCustomer): Promise<string>;
createEditCustomer(page: Frame|Page, customerData: FakerCustomer, waitForNavigation?: boolean): Promise<string>
}
1 change: 1 addition & 0 deletions src/interfaces/BO/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export interface BOBasePagePageInterface extends CommonPageInterface {
getShopName(page: Page): Promise<string>;
getShopVersion(page:Page):Promise<string>;
goToDashboardPage(page: Page): Promise<void>;
goToManageQuickAccessPage(page: Page): Promise<void>;
goToMyProfile(page: Page): Promise<void>;
goToSubMenu(page: Page, parentSelector: string, linkSelector: string): Promise<void>;
hasAlertBlock(page: Page): Promise<boolean>;
Expand Down
9 changes: 9 additions & 0 deletions src/pages/BO/customers/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {type BOCustomersCreatePageInterface} from '@interfaces/BO/customers/create';

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

export default requirePage();
214 changes: 214 additions & 0 deletions src/versions/develop/pages/BO/customers/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
import type FakerCustomer from '@data/faker/customer';
import {type BOCustomersCreatePageInterface} from '@interfaces/BO/customers/create';
import BOBasePage from '@pages/BO/BOBasePage';
import {type Frame, type Page} from '@playwright/test';

/**
* Add customer page, contains functions that can be used on the page
* @class
* @extends BOBasePage
*/
class BOCustomersCreatePage extends BOBasePage implements BOCustomersCreatePageInterface {
public readonly pageTitleCreate: string;

public readonly pageTitleEdit: string;

public readonly updateSuccessfullMessage: string;

private readonly socialTitleInput: (id: number) => string;

private readonly firstNameInput: string;

private readonly lastNameInput: string;

private readonly emailInput: string;

private readonly passwordInput: string;

private readonly yearOfBirthSelect: string;

private readonly monthOfBirthSelect: string;

private readonly dayOfBirthSelect: string;

private readonly statusToggleInput: (toggle: number) => string;

private readonly partnerOffersToggleInput: (toggle: number) => string;

private readonly companyInput: string;

private readonly allowedOutstandingAmountInput: string;

private readonly riskRatingSelect: string;

private readonly groupAccessCheckbox: (id: number) => string;

private readonly visitorCheckbox: string;

private readonly guestCheckbox: string;

private readonly customerCheckbox: string;

private readonly selectAllGroupAccessCheckbox: string;

private readonly defaultCustomerGroupSelect: string;

private readonly saveCustomerButton: string;

/**
* @constructs
* Setting up texts and selectors to use on add customer page
*/
constructor() {
super();

this.pageTitleCreate = `New customer • ${global.INSTALL.SHOP_NAME}`;
this.pageTitleEdit = 'Editing customer';
this.updateSuccessfullMessage = 'Update successful';

// Selectors
this.socialTitleInput = (id: number) => `#customer_gender_id_${id}`;
this.firstNameInput = '#customer_first_name';
this.lastNameInput = '#customer_last_name';
this.emailInput = '#customer_email';
this.passwordInput = '#customer_password';
this.yearOfBirthSelect = 'select#customer_birthday_year';
this.monthOfBirthSelect = 'select#customer_birthday_month';
this.dayOfBirthSelect = 'select#customer_birthday_day';
this.statusToggleInput = (toggle: number) => `#customer_is_enabled_${toggle}`;
this.partnerOffersToggleInput = (toggle: number) => `#customer_is_partner_offers_subscribed_${toggle}`;
this.companyInput = '#customer_company_name';
this.allowedOutstandingAmountInput = '#customer_allowed_outstanding_amount';
this.riskRatingSelect = '#customer_risk_id';

// Group access selector
this.groupAccessCheckbox = (id: number) => `#customer_group_ids_${id}`;
this.visitorCheckbox = this.groupAccessCheckbox(0);
this.guestCheckbox = this.groupAccessCheckbox(1);
this.customerCheckbox = this.groupAccessCheckbox(2);

this.selectAllGroupAccessCheckbox = 'input.js-choice-table-select-all';
this.defaultCustomerGroupSelect = 'select#customer_default_group_id';
this.saveCustomerButton = '#save-button';
}

/*
Methods
*/

/**
* Fill form for add/edit customer
* @param page {Frame|Page} Browser tab
* @param customerData {FakerCustomer} Data to set on new customer form
* @return {Promise<void>}
*/
async fillCustomerForm(page: Frame|Page, customerData: FakerCustomer): Promise<void> {
// Click on label for social input
await this.setHiddenCheckboxValue(page, this.socialTitleInput(customerData.socialTitle === 'Mr.' ? 0 : 1));

// Fill form
await this.setValue(page, this.firstNameInput, customerData.firstName);
await this.setValue(page, this.lastNameInput, customerData.lastName);
await this.setValue(page, this.emailInput, customerData.email);
await this.setValue(page, this.passwordInput, customerData.password);
await this.selectByVisibleText(page, this.yearOfBirthSelect, customerData.yearOfBirth);
await this.selectByVisibleText(page, this.monthOfBirthSelect, customerData.monthOfBirth);
await this.selectByVisibleText(page, this.dayOfBirthSelect, customerData.dayOfBirth);
await this.setChecked(page, this.statusToggleInput(customerData.enabled ? 1 : 0));
await this.setChecked(page, this.partnerOffersToggleInput(customerData.partnerOffers ? 1 : 0));
await this.setCustomerGroupAccess(page, customerData.defaultCustomerGroup);
await this.selectByVisibleText(page, this.defaultCustomerGroupSelect, customerData.defaultCustomerGroup);
}

/**
* Fill form for add/edit B2B customer
* @param page {Page} Browser tab
* @param customerData {FakerCustomer} Data to set on new customer form
* @return {Promise<void>}
*/
async fillB2BCustomerForm(page: Page, customerData: FakerCustomer): Promise<void> {
// Click on label for social input
await this.setHiddenCheckboxValue(page, this.socialTitleInput(customerData.socialTitle === 'Mr.' ? 0 : 1));

// Fill form
await this.setValue(page, this.firstNameInput, customerData.firstName);
await this.setValue(page, this.lastNameInput, customerData.lastName);
await this.setValue(page, this.emailInput, customerData.email);
await this.setValue(page, this.passwordInput, customerData.password);
await this.selectByVisibleText(page, this.yearOfBirthSelect, customerData.yearOfBirth);
await this.selectByVisibleText(page, this.monthOfBirthSelect, customerData.monthOfBirth);
await this.selectByVisibleText(page, this.dayOfBirthSelect, customerData.dayOfBirth);
await this.setChecked(page, this.statusToggleInput(customerData.enabled ? 1 : 0));
await this.setChecked(page, this.partnerOffersToggleInput(customerData.partnerOffers ? 1 : 0));
await this.setCustomerGroupAccess(page, customerData.defaultCustomerGroup);
await this.selectByVisibleText(page, this.defaultCustomerGroupSelect, customerData.defaultCustomerGroup);
await this.setValue(page, this.companyInput, customerData.company);
await this.setValue(page, this.allowedOutstandingAmountInput, customerData.allowedOutstandingAmount);
await this.selectByVisibleText(page, this.riskRatingSelect, customerData.riskRating);
}

/**
* Fill form for add/edit customer and get successful message after saving
* @param page {Frame|Page} Browser tab
* @param customerData {FakerCustomer} Data to set on new customer form
* @param waitForNavigation {boolean} True if we need save and waitForNavigation, false if not
* @return {Promise<string>}
*/
async createEditCustomer(page: Frame|Page, customerData: FakerCustomer, waitForNavigation: boolean = true): Promise<string> {
// Fill form
await this.fillCustomerForm(page, customerData);

// Save Customer
if (waitForNavigation) {
await this.clickAndWaitForURL(page, this.saveCustomerButton);
return this.getAlertSuccessBlockParagraphContent(page);
}
await this.waitForSelectorAndClick(page, this.saveCustomerButton);
return '';
}

/**
* Fill form for add/edit B2B customer and get successful message after saving
* @param page {Page} Browser tab
* @param customerData {FakerCustomer} Data to set on new customer form
* @return {Promise<string>}
*/
async createEditB2BCustomer(page: Page, customerData: FakerCustomer): Promise<string> {
// Fill form
await this.fillB2BCustomerForm(page, customerData);

// Save Customer
await this.clickAndWaitForURL(page, this.saveCustomerButton);
return this.getAlertSuccessBlockParagraphContent(page);
}

/**
* Set customer group access in form
* @param page {Frame|Page} Browser tab
* @param customerGroup {string} Value to set on customer group input
* @return {Promise<void>}
*/
async setCustomerGroupAccess(page: Frame|Page, customerGroup: string): Promise<void> {
switch (customerGroup) {
case 'Customer':
await this.setCheckedWithIcon(page, this.visitorCheckbox, false);
await this.setCheckedWithIcon(page, this.customerCheckbox);
await this.setCheckedWithIcon(page, this.guestCheckbox, false);
break;
case 'Guest':
await this.setCheckedWithIcon(page, this.visitorCheckbox, false);
await this.setCheckedWithIcon(page, this.customerCheckbox, false);
await this.setCheckedWithIcon(page, this.guestCheckbox);
break;
case 'Visitor':
await this.setCheckedWithIcon(page, this.guestCheckbox, false);
await this.setCheckedWithIcon(page, this.customerCheckbox, false);
await this.setCheckedWithIcon(page, this.visitorCheckbox);
break;
default:
throw new Error(`${customerGroup} was not found as a group access`);
}
}
}

module.exports = new BOCustomersCreatePage();

0 comments on commit 7c81cf7

Please sign in to comment.