Skip to content

Commit

Permalink
Merge pull request #327 from Progi1984/boAttributesCreatePage
Browse files Browse the repository at this point in the history
Migrate `@pages/BO/catalog/attributes/addAttribute` from Core
  • Loading branch information
Progi1984 authored Jan 16, 2025
2 parents f231d80 + f33fc5d commit 41f3acb
Show file tree
Hide file tree
Showing 4 changed files with 101 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 @@ -193,6 +193,7 @@ export {default as boAdministrationPage} from '@pages/BO/advancedParameters/admi
export {default as boApiClientsPage} from '@pages/BO/advancedParameters/apiclients';
export {default as boApiClientsCreatePage} from '@pages/BO/advancedParameters/apiclients/create';
export {default as boAttributesPage} from '@pages/BO/catalog/attributes';
export {default as boAttributesCreatePage} from '@pages/BO/catalog/attributes/createAttribute';
export {default as boBrandsPage} from '@pages/BO/catalog/brands';
export {default as boCarriersPage} from '@pages/BO/shipping/carriers';
export {default as boCarriersCreatePage} from '@pages/BO/shipping/carriers/create';
Expand Down
10 changes: 10 additions & 0 deletions src/interfaces/BO/catalog/attributes/createAttribute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type FakerAttribute from '@data/faker/attribute';
import {BOBasePagePageInterface} from '@interfaces/BO';
import {type Page} from '@playwright/test';

export interface BOAttributesCreatePageInterface extends BOBasePagePageInterface {
readonly createPageTitle: string;
readonly editPageTitle: (name: string) => string;

addEditAttribute(page: Page, attributeData: FakerAttribute): Promise<string>;
}
9 changes: 9 additions & 0 deletions src/pages/BO/catalog/attributes/createAttribute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type {BOAttributesCreatePageInterface} from '@interfaces/BO/catalog/attributes/createAttribute';

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

export default requirePage();
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import type FakerAttribute from '@data/faker/attribute';
import BOBasePage from '@pages/BO/BOBasePage';
import {type Page} from '@playwright/test';

/**
* Add attribute page, contains functions that can be used on the page
* @class
* @extends BOBasePage
*/
class BOAttributesCreatePage extends BOBasePage {
public readonly createPageTitle: string;

public readonly editPageTitle: (name: string) => string;

private readonly nameInput: string;

private readonly publicNameInput: string;

private readonly urlInput: string;

private readonly metaTitleInput: string;

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

private readonly attributeTypeSelect: string;

private readonly saveButton: string;

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

this.createPageTitle = `New attribute • ${global.INSTALL.SHOP_NAME}`;
this.editPageTitle = (name: string) => `Editing attribute ${name}${global.INSTALL.SHOP_NAME}`;

// Form selectors
this.nameInput = '#attribute_group_name_1';
this.publicNameInput = '#attribute_group_public_name_1';
this.urlInput = '#attribute_group_url_name_1';
this.metaTitleInput = '#attribute_group_meta_title_1';
this.indexableToggle = (toggle: number) => `#attribute_group_is_indexable_${toggle}`;
this.attributeTypeSelect = '#attribute_group_group_type';
this.saveButton = 'form[name="attribute_group"] div.card-footer button';
}
/*
Methods
*/

/**
* Fill attribute form and save it
* @param page {Page} Browser tab
* @param attributeData {FakerAttribute} Data to set on new/edit attribute form
* @return {Promise<string>}
*/
async addEditAttribute(page: Page, attributeData: FakerAttribute): Promise<string> {
// Set names
await this.setValue(page, this.nameInput, attributeData.name);
await this.setValue(page, this.publicNameInput, attributeData.publicName);

// Set Url and meta title
await this.setValue(page, this.urlInput, attributeData.url);
await this.setValue(page, this.metaTitleInput, attributeData.metaTitle);

// Set indexable toggle
await this.setChecked(page, this.indexableToggle(attributeData.indexable ? 1 : 0));

// Set attribute type
await this.selectByVisibleText(page, this.attributeTypeSelect, attributeData.attributeType);

// Save attribute
await this.clickAndWaitForURL(page, this.saveButton);

// Return successful message
return this.getAlertSuccessBlockParagraphContent(page);
}
}

module.exports = new BOAttributesCreatePage();

0 comments on commit 41f3acb

Please sign in to comment.