diff --git a/src/index.ts b/src/index.ts index d0526805..156db207 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'; diff --git a/src/interfaces/BO/customers/create.ts b/src/interfaces/BO/customers/create.ts new file mode 100644 index 00000000..6518fa55 --- /dev/null +++ b/src/interfaces/BO/customers/create.ts @@ -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; + createEditCustomer(page: Frame|Page, customerData: FakerCustomer, waitForNavigation?: boolean): Promise +} diff --git a/src/interfaces/BO/index.ts b/src/interfaces/BO/index.ts index 6b2b8673..b035dd94 100644 --- a/src/interfaces/BO/index.ts +++ b/src/interfaces/BO/index.ts @@ -100,6 +100,7 @@ export interface BOBasePagePageInterface extends CommonPageInterface { getShopName(page: Page): Promise; getShopVersion(page:Page):Promise; goToDashboardPage(page: Page): Promise; + goToManageQuickAccessPage(page: Page): Promise; goToMyProfile(page: Page): Promise; goToSubMenu(page: Page, parentSelector: string, linkSelector: string): Promise; hasAlertBlock(page: Page): Promise; diff --git a/src/pages/BO/customers/create.ts b/src/pages/BO/customers/create.ts new file mode 100644 index 00000000..75cac582 --- /dev/null +++ b/src/pages/BO/customers/create.ts @@ -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(); diff --git a/src/versions/develop/pages/BO/customers/create.ts b/src/versions/develop/pages/BO/customers/create.ts new file mode 100644 index 00000000..1fc6c56a --- /dev/null +++ b/src/versions/develop/pages/BO/customers/create.ts @@ -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} + */ + async fillCustomerForm(page: Frame|Page, customerData: FakerCustomer): Promise { + // 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} + */ + async fillB2BCustomerForm(page: Page, customerData: FakerCustomer): Promise { + // 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} + */ + async createEditCustomer(page: Frame|Page, customerData: FakerCustomer, waitForNavigation: boolean = true): Promise { + // 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} + */ + async createEditB2BCustomer(page: Page, customerData: FakerCustomer): Promise { + // 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} + */ + async setCustomerGroupAccess(page: Frame|Page, customerGroup: string): Promise { + 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();