Skip to content

Commit

Permalink
Merge pull request #363 from Progi1984/boTaxRulesCreatePage
Browse files Browse the repository at this point in the history
Migrate `@pages/BO/international/taxes/taxRules/add` from Core
  • Loading branch information
Progi1984 authored Jan 27, 2025
2 parents 450152b + af9c9a7 commit 15c4922
Show file tree
Hide file tree
Showing 4 changed files with 137 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 @@ -292,6 +292,7 @@ export {default as boStatisticsPage} from '@pages/BO/statistics';
export {default as boStockPage} from '@pages/BO/catalog/stock';
export {default as boSuppliersCreate} from '@pages/BO/catalog/suppliers/create';
export {default as boTaxesPage} from '@pages/BO/international/taxes';
export {default as boTaxRulesCreatePage} from '@pages/BO/international/taxes/taxRules/create';
export {default as boThemeAdvancedConfigurationPage} from '@pages/BO/design/themeAndLogo/advancedConfiguration';
export {default as boThemeAndLogoPage} from '@pages/BO/design/themeAndLogo';
export {default as boThemeAndLogoChooseLayoutsPage} from '@pages/BO/design/themeAndLogo/themeAndLogo/chooseLayouts';
Expand Down
13 changes: 13 additions & 0 deletions src/interfaces/BO/international/taxes/taxRules/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type FakerTaxRule from '@data/faker/taxRule';
import type FakerTaxRulesGroup from '@data/faker/taxRulesGroup';
import {BOBasePagePageInterface} from '@interfaces/BO';
import {type Page} from '@playwright/test';

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

clickOnAddNewTaxRule(page: Page): Promise<void>;
createEditTaxRules(page: Page, taxRuleData: FakerTaxRule): Promise<string>;
createEditTaxRulesGroup(page: Page, taxRuleGroupData: FakerTaxRulesGroup): Promise<string>;
}
9 changes: 9 additions & 0 deletions src/pages/BO/international/taxes/taxRules/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {type BOTaxRulesCreatePageInterface} from '@interfaces/BO/international/taxes/taxRules/create';

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

export default requirePage();
114 changes: 114 additions & 0 deletions src/versions/develop/pages/BO/international/taxes/taxRules/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import type FakerTaxRule from '@data/faker/taxRule';
import type FakerTaxRulesGroup from '@data/faker/taxRulesGroup';
import {BOTaxRulesCreatePageInterface} from '@interfaces/BO/international/taxes/taxRules/create';
import BOBasePage from '@pages/BO/BOBasePage';
import {type Page} from '@playwright/test';

/**
* Add tax rules page, contains functions that can be used on the page
* @class
* @extends BOBasePage
*/
class BOTaxRulesCreatePage extends BOBasePage implements BOTaxRulesCreatePageInterface {
public readonly pageTitleCreate: string;

public readonly pageTitleEdit: string;

private readonly addNewTaxRuleButton: string;

private readonly taxRuleGroupForm: string;

private readonly nameInput: string;

private readonly statusInput: (id: string) => string;

private readonly saveTaxButton: string;

private readonly taxRuleForm: string;

private readonly countrySelect: string;

private readonly behaviourSelect: string;

private readonly taxSelect: string;

private readonly descriptionInput: string;

private readonly saveAndStayButton: string;

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

this.pageTitleCreate = 'Tax Rules > Add new';
this.pageTitleEdit = 'Tax Rules > Edit';

// Selectors
// Header buttons
this.addNewTaxRuleButton = 'a[data-role=page-header-desc-tax_rule-link]';

// New tax rule group form
this.taxRuleGroupForm = '#tax_rules_group_form';
this.nameInput = `${this.taxRuleGroupForm} #name`;
this.statusInput = (id: string) => `${this.taxRuleGroupForm} input#active_${id}`;
this.saveTaxButton = `${this.taxRuleGroupForm} #tax_rules_group_form_submit_btn`;

// New tax rule form
this.taxRuleForm = '#tax_rule_form';
this.countrySelect = `${this.taxRuleForm} #country`;
this.behaviourSelect = `${this.taxRuleForm} #behavior`;
this.taxSelect = `${this.taxRuleForm} #id_tax`;
this.descriptionInput = `${this.taxRuleForm} #description`;
this.saveAndStayButton = `${this.taxRuleForm} #tax_rule_form_submit_btn_1`;
}

/*
Methods
*/

/**
* Fill form for add/edit tax rules group
* @param page {Page} Browser tab
* @param taxRuleGroupData {FakerTaxRulesGroup} Data to set on tax rule group data
* @returns {Promise<string>}
*/
async createEditTaxRulesGroup(page: Page, taxRuleGroupData: FakerTaxRulesGroup): Promise<string> {
await this.setValue(page, this.nameInput, taxRuleGroupData.name);
await this.setChecked(page, this.statusInput(taxRuleGroupData.enabled ? 'on' : 'off'));
// Save Tax rules group
await this.clickAndWaitForURL(page, this.saveTaxButton);

return this.getAlertSuccessBlockContent(page);
}

/**
* Fill form for add/edit tax rules group
* @param page {Page} Browser tab
* @param taxRuleData {FakerTaxRule} Data to set on new/edit tax rule data
* @returns {Promise<string>}
*/
async createEditTaxRules(page: Page, taxRuleData: FakerTaxRule): Promise<string> {
await this.selectByVisibleText(page, this.countrySelect, taxRuleData.country);
await this.selectByVisibleText(page, this.behaviourSelect, taxRuleData.behaviour);
await this.selectByVisibleText(page, this.taxSelect, taxRuleData.name);
await this.setValue(page, this.descriptionInput, taxRuleData.description);
// Save Tax rules
await page.locator(this.saveAndStayButton).click();

return this.getAlertSuccessBlockContent(page);
}

/**
* Click on add new tax rule
* @param page {Page} Browser tab
* @return {Promise<void>}
*/
async clickOnAddNewTaxRule(page: Page): Promise<void> {
await page.locator(this.addNewTaxRuleButton).click();
}
}

module.exports = new BOTaxRulesCreatePage();

0 comments on commit 15c4922

Please sign in to comment.