diff --git a/src/index.ts b/src/index.ts index 7deaaa9a..054608ef 100644 --- a/src/index.ts +++ b/src/index.ts @@ -198,6 +198,7 @@ export {default as boAttributesPage} from '@pages/BO/catalog/attributes'; export {default as boAttributesCreatePage} from '@pages/BO/catalog/attributes/createAttribute'; export {default as boAttributesValueCreatePage} from '@pages/BO/catalog/attributes/createValue'; export {default as boAttributesViewPage} from '@pages/BO/catalog/attributes/view'; +export {default as boBrandsCreatePage} from '@pages/BO/catalog/brands/create'; export {default as boBrandAdressesCreatePage} from '@pages/BO/catalog/brands/addresses/create'; export {default as boBrandsPage} from '@pages/BO/catalog/brands'; export {default as boCarriersPage} from '@pages/BO/shipping/carriers'; diff --git a/src/interfaces/BO/catalog/brands/create.ts b/src/interfaces/BO/catalog/brands/create.ts new file mode 100644 index 00000000..8db0b95b --- /dev/null +++ b/src/interfaces/BO/catalog/brands/create.ts @@ -0,0 +1,10 @@ +import type FakerBrand from '@data/faker/brand'; +import {BOBasePagePageInterface} from '@interfaces/BO'; +import {type Page} from '@playwright/test'; + +export interface BOBrandsCreatePageInterface extends BOBasePagePageInterface { + readonly pageTitle: string; + readonly pageTitleEdit: string; + + createEditBrand(page: Page, brandData: FakerBrand): Promise; +} diff --git a/src/pages/BO/catalog/brands/create.ts b/src/pages/BO/catalog/brands/create.ts new file mode 100644 index 00000000..6e5113aa --- /dev/null +++ b/src/pages/BO/catalog/brands/create.ts @@ -0,0 +1,9 @@ +import type {BOBrandsCreatePageInterface} from '@interfaces/BO/catalog/brands/create'; + +/* eslint-disable global-require, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */ +function requirePage(): BOBrandsCreatePageInterface { + return require('@versions/develop/pages/BO/catalog/brands/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/catalog/brands/create.ts b/src/versions/develop/pages/BO/catalog/brands/create.ts new file mode 100644 index 00000000..9d549018 --- /dev/null +++ b/src/versions/develop/pages/BO/catalog/brands/create.ts @@ -0,0 +1,115 @@ +import type FakerBrand from '@data/faker/brand'; +import {type BOBrandsCreatePageInterface} from '@interfaces/BO/catalog/brands/create'; +import BOBasePage from '@pages/BO/BOBasePage'; +import {type Page} from '@playwright/test'; + +/** + * Add brand page, contains selectors and functions for the page + * @class + * @extends BOBasePage + */ +class BOBrandsCreatePage extends BOBasePage implements BOBrandsCreatePageInterface { + public readonly pageTitle: string; + + public readonly pageTitleEdit: string; + + private readonly nameInput: string; + + private readonly shortDescriptionDiv: string; + + private readonly shortDescriptionLangLink: (lang: string) => string; + + private readonly shortDescriptionIFrame: (id: number) => string; + + private readonly descriptionDiv: string; + + private readonly descriptionIFrame: (id: number) => string; + + private readonly logoFileInput: string; + + private readonly metaTitleInput: (id: number) => string; + + private readonly metaDescriptionInput: (id: number) => string; + + private readonly statusToggleInput: (toggle: number) => string; + + private readonly saveButton: string; + + /** + * @constructs + * Setting up titles and selectors to use on add brand page + */ + constructor() { + super(); + + this.pageTitle = `New brand • ${global.INSTALL.SHOP_NAME}`; + this.pageTitleEdit = 'Editing brand'; + + // Selectors + this.nameInput = '#manufacturer_name'; + this.shortDescriptionDiv = '#manufacturer_short_description'; + this.shortDescriptionLangLink = (lang: string) => `${this.shortDescriptionDiv} li.nav-item a[data-locale='${lang}']`; + this.shortDescriptionIFrame = (id: number) => `${this.shortDescriptionDiv} #manufacturer_short_description_${id}_ifr`; + this.descriptionDiv = '#manufacturer_description'; + this.descriptionIFrame = (id: number) => `${this.descriptionDiv} #manufacturer_description_${id}_ifr`; + this.logoFileInput = '#manufacturer_logo'; + this.metaTitleInput = (id: number) => `#manufacturer_meta_title_${id}`; + this.metaDescriptionInput = (id: number) => `#manufacturer_meta_description_${id}`; + this.statusToggleInput = (toggle: number) => `#manufacturer_is_enabled_${toggle}`; + + this.saveButton = '.card-footer button'; + } + + /* + Methods + */ + + /** + * Create or edit Brand + * @param page {Page} Browser tab + * @param brandData {FakerBrand} Data to set in brand form + * @returns {Promise} + */ + async createEditBrand(page: Page, brandData: FakerBrand): Promise { + // Fill Name + await this.setValue(page, this.nameInput, brandData.name); + // Fill information in english + await this.changeLanguage(page, 'en'); + await this.setValueOnTinymceInput(page, this.shortDescriptionIFrame(1), brandData.shortDescription); + await this.setValueOnTinymceInput(page, this.descriptionIFrame(1), brandData.description); + await this.setValue(page, this.metaTitleInput(1), brandData.metaTitle); + await this.setValue(page, this.metaDescriptionInput(1), brandData.metaDescription); + + // Fill Information in french + await this.changeLanguage(page, 'fr'); + await this.setValueOnTinymceInput(page, this.shortDescriptionIFrame(2), brandData.shortDescriptionFr); + await this.setValueOnTinymceInput(page, this.descriptionIFrame(2), brandData.descriptionFr); + await this.setValue(page, this.metaTitleInput(2), brandData.metaTitleFr); + await this.setValue(page, this.metaDescriptionInput(2), brandData.metaDescriptionFr); + + // Add logo + await this.uploadFile(page, this.logoFileInput, brandData.logo); + + // Set Enabled value + await this.setChecked(page, this.statusToggleInput(brandData.enabled ? 1 : 0)); + + // Save Created brand + await this.clickAndWaitForURL(page, this.saveButton); + return this.getAlertSuccessBlockParagraphContent(page); + } + + /** + * Change language for selector + * @param page {Page} Browser tab + * @param lang {string} Language to choose + * @return {Promise} + */ + async changeLanguage(page: Page, lang: string): Promise { + await Promise.all([ + page.locator(this.shortDescriptionLangLink(lang)).evaluate((el: HTMLElement) => el.click()), + this.waitForVisibleSelector(page, `${this.shortDescriptionLangLink(lang)}.active`), + ]); + } +} + +module.exports = new BOBrandsCreatePage();