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/catalog/brands/add from Core #409

Merged
merged 1 commit into from
Feb 17, 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 @@ -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';
Expand Down
10 changes: 10 additions & 0 deletions src/interfaces/BO/catalog/brands/create.ts
Original file line number Diff line number Diff line change
@@ -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<string>;
}
9 changes: 9 additions & 0 deletions src/pages/BO/catalog/brands/create.ts
Original file line number Diff line number Diff line change
@@ -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();
115 changes: 115 additions & 0 deletions src/versions/develop/pages/BO/catalog/brands/create.ts
Original file line number Diff line number Diff line change
@@ -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<string>}
*/
async createEditBrand(page: Page, brandData: FakerBrand): Promise<string> {
// 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<void>}
*/
async changeLanguage(page: Page, lang: string): Promise<void> {
await Promise.all([
page.locator(this.shortDescriptionLangLink(lang)).evaluate((el: HTMLElement) => el.click()),
this.waitForVisibleSelector(page, `${this.shortDescriptionLangLink(lang)}.active`),
]);
}
}

module.exports = new BOBrandsCreatePage();