Skip to content
Draft
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
9 changes: 8 additions & 1 deletion src/pages/BO/international/taxes/taxRules/create.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import {type BOTaxRulesCreatePageInterface} from '@interfaces/BO/international/taxes/taxRules/create';
import testContext from '@utils/test';
import semver from 'semver';

const psVersion = testContext.getPSVersion();

/* 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');
if (semver.lt(psVersion, '9.2.0')) {
return require('@versions/9.1/pages/BO/international/taxes/taxRules/create').boTaxRulesCreatePage;
}
return require('@versions/develop/pages/BO/international/taxes/taxRules/create').boTaxRulesCreatePage;
}
/* eslint-enable global-require, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */

Expand Down
9 changes: 8 additions & 1 deletion src/pages/BO/international/taxes/taxRules/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import {type BOTaxRulesPageInterface} from '@interfaces/BO/international/taxes/taxRules';
import testContext from '@utils/test';
import semver from 'semver';

const psVersion = testContext.getPSVersion();

/* eslint-disable global-require, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */
function requirePage(): BOTaxRulesPageInterface {
return require('@versions/develop/pages/BO/international/taxes/taxRules');
if (semver.lt(psVersion, '9.2.0')) {
return require('@versions/9.1/pages/BO/international/taxes/taxRules').boTaxRulesPage;
}
return require('@versions/develop/pages/BO/international/taxes/taxRules').boTaxRulesPage;
}
/* eslint-enable global-require, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */

Expand Down
69 changes: 69 additions & 0 deletions src/versions/9.1/pages/BO/international/taxes/taxRules/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import type FakerTaxRule from '@data/faker/taxRule';
import type FakerTaxRulesGroup from '@data/faker/taxRulesGroup';
import {type BOTaxRulesCreatePageInterface} from '@interfaces/BO/international/taxes/taxRules/create';
import {type Page} from '@playwright/test';
import {
BOTaxRulesCreatePage as BOTaxRulesCreatePageVersion,
} from '@versions/develop/pages/BO/international/taxes/taxRules/create';

class BOTaxRulesCreatePage extends BOTaxRulesCreatePageVersion implements BOTaxRulesCreatePageInterface {
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`;
}

/**
* 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);
}
}

const boTaxRulesCreatePage = new BOTaxRulesCreatePage();
export {boTaxRulesCreatePage, BOTaxRulesCreatePage};
115 changes: 115 additions & 0 deletions src/versions/9.1/pages/BO/international/taxes/taxRules/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import {type BOTaxRulesPageInterface} from '@interfaces/BO/international/taxes/taxRules';
import {Page} from '@playwright/test';
import {BOTaxRulesPage as BOTaxRulesPageVersion} from '@versions/develop/pages/BO/international/taxes/taxRules';

class BOTaxRulesPage extends BOTaxRulesPageVersion implements BOTaxRulesPageInterface {
constructor() {
super();

// Selectors
// HEADER buttons
this.addNewTaxRulesGroupLink = 'a[data-role=page-header-desc-tax_rules_group-link]';

// Form selectors
this.gridTableHeaderTitle = `${this.gridForm} .panel-heading`;
this.gridTableNumberOfTitlesSpan = `${this.gridTableHeaderTitle} span.badge`;
this.gridTable = '#table-tax_rules_group';

// Filter selectors
this.filterRow = `${this.gridTable} tr.filter`;
this.filterColumn = (filterBy: string) => `${this.filterRow} [name='tax_rules_groupFilter_${filterBy}']`;
this.filterSearchButton = '#submitFilterButtontax_rules_group';
this.filterResetButton = `${this.filterRow} button[name='submitResettax_rules_group']`;

// Table rows and columns
this.tableBody = `${this.gridTable} tbody`;
this.tableRow = (row: number) => `${this.tableBody} tr:nth-child(${row})`;
this.editRowLink = (row: number) => `${this.tableRow(row)} a.edit`;
this.tableBodyColumn = (row: number) => `${this.tableRow(row)} td`;

// Columns selectors
this.tableColumnId = (row: number) => `${this.tableBodyColumn(row)}:nth-child(2)`;
this.tableColumnName = (row: number) => `${this.tableBodyColumn(row)}:nth-child(3)`;
this.tableColumnActive = (row: number) => `${this.tableBodyColumn(row)}:nth-child(4) a`;
this.tableColumnCheckIcon = (row: number) => `${this.tableColumnActive(row)} i.icon-check`;

// Bulk actions selectors
this.bulkActionBlock = 'div.bulk-actions';
this.bulkActionMenuButton = '#bulk_action_menu_tax_rules_group';
this.bulkActionDropdownMenu = `${this.bulkActionBlock} ul.dropdown-menu`;
this.selectAllLink = `${this.bulkActionDropdownMenu} li:nth-child(1)`;
this.bulkDeleteLink = `${this.bulkActionDropdownMenu} li:nth-child(7)`;
this.bulkEnableLink = `${this.bulkActionDropdownMenu} li:nth-child(4)`;
this.bulkDisableLink = `${this.bulkActionDropdownMenu} li:nth-child(5)`;
}

/**
* Get text column from table
* @param page {Page} Browser tab
* @param row {number} Row on table
* @param columnName {string} Column name to get text column from table
* @returns {Promise<string>}
*/
async getTextColumnFromTable(page: Page, row: number, columnName: string): Promise<string> {
let columnSelector;

switch (columnName) {
case 'id_tax_rules_group':
columnSelector = this.tableColumnId(row);
break;

case 'name':
columnSelector = this.tableColumnName(row);
break;

case 'active':
columnSelector = this.tableColumnActive(row);
break;

default:
throw new Error(`Column ${columnName} was not found`);
}

if (columnName === 'active') {
return this.getAttributeContent(page, columnSelector, 'title');
}

return this.getTextContent(page, columnSelector);
}

/**
* Select all rows
* @param page {Page} Browser tab
* @return {Promise<void>}
*/
async bulkSelectRows(page: Page): Promise<void> {
await page.locator(this.bulkActionMenuButton).click();

await Promise.all([
page.locator(this.selectAllLink).click(),
this.waitForHiddenSelector(page, this.selectAllLink),
]);
}

/**
* Delete tax rules by bulk action
* @param page {Page} Browser tab
* @returns {Promise<string>}
*/
async bulkDeleteTaxRules(page: Page): Promise<string> {
await this.dialogListener(page, true);
// Select all rows
await this.bulkSelectRows(page);

// Click on Button Bulk actions
await page.locator(this.bulkActionMenuButton).click();

// Click on delete
await this.clickAndWaitForURL(page, this.bulkDeleteLink);

return this.getAlertSuccessBlockContent(page);
}
}

const boTaxRulesPage = new BOTaxRulesPage();
export {boTaxRulesPage, BOTaxRulesPage};
2 changes: 1 addition & 1 deletion src/versions/develop/pages/BO/international/taxes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ class BOTaxesPage extends BOBasePage implements BOTaxesPageInterface {
* @param page {Page} Browser tab
* @return {Promise<string>}
*/
getPaginationLabel(page: Page): Promise<string> {
async getPaginationLabel(page: Page): Promise<string> {
return this.getTextContent(page, this.paginationLabel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@ import {type Page} from '@playwright/test';
* @extends BOBasePage
*/
class BOTaxRulesCreatePage extends BOBasePage implements BOTaxRulesCreatePageInterface {
public readonly pageTitleCreate: string;
public pageTitleCreate: string;

public readonly pageTitleEdit: string;
public pageTitleEdit: string;

private readonly addNewTaxRuleButton: string;
protected addNewTaxRuleButton: string;

private readonly taxRuleGroupForm: string;
protected taxRuleGroupForm: string;

private readonly nameInput: string;
protected nameInput: string;

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

private readonly saveTaxButton: string;
protected saveTaxButton: string;

private readonly taxRuleForm: string;
protected taxRuleForm: string;

private readonly countrySelect: string;
protected countrySelect: string;

private readonly behaviourSelect: string;
protected behaviourSelect: string;

private readonly taxSelect: string;
protected taxSelect: string;

private readonly descriptionInput: string;
protected descriptionInput: string;

private readonly saveAndStayButton: string;
protected saveAndStayButton: string;

/**
* @constructs
Expand All @@ -43,26 +43,26 @@ class BOTaxRulesCreatePage extends BOBasePage implements BOTaxRulesCreatePageInt
constructor() {
super();

this.pageTitleCreate = 'Tax Rules > Add new';
this.pageTitleEdit = 'Tax Rules > Edit';
this.pageTitleCreate = `New tax rule • ${global.INSTALL.SHOP_NAME}`;
this.pageTitleEdit = 'Editing tax rule ';

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

// 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`;
this.taxRuleGroupForm = 'form[name="tax_rules_group"]';
this.nameInput = `${this.taxRuleGroupForm} #tax_rules_group_name`;
this.statusInput = (id: string) => `${this.taxRuleGroupForm} input#tax_rules_group_is_enabled_${id}`;
this.saveTaxButton = `${this.taxRuleGroupForm} #save-and-stay-button`;

// 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`;
this.taxRuleForm = 'iframe[name="tax-rule-form-modal-iframe"]';
this.countrySelect = '#tax_rule_country';
this.behaviourSelect = '#tax_rule_behavior';
this.taxSelect = '#tax_rule_tax';
this.descriptionInput = '#tax_rule_description';
this.saveAndStayButton = '#tax-rule-form-modal .btn-confirm-submit';
}

/*
Expand All @@ -77,11 +77,11 @@ class BOTaxRulesCreatePage extends BOBasePage implements BOTaxRulesCreatePageInt
*/
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'));
await this.setChecked(page, this.statusInput(taxRuleGroupData.enabled ? '1' : '0'));
// Save Tax rules group
await this.clickAndWaitForURL(page, this.saveTaxButton);

return this.getAlertSuccessBlockContent(page);
return this.getAlertSuccessBlockParagraphContent(page);
}

/**
Expand All @@ -91,14 +91,17 @@ class BOTaxRulesCreatePage extends BOBasePage implements BOTaxRulesCreatePageInt
* @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.addNewTaxRuleButton).click();
await page.locator(this.taxRuleForm).waitFor({state: 'visible'});

const iframeLocator = await page.frameLocator(this.taxRuleForm);
await iframeLocator.locator(this.countrySelect).selectOption({label: taxRuleData.country});
await iframeLocator.locator(this.behaviourSelect).selectOption({label: taxRuleData.behaviour});
await iframeLocator.locator(this.taxSelect).selectOption({label: taxRuleData.name});
await iframeLocator.locator(this.descriptionInput).fill(taxRuleData.description);
await page.locator(this.saveAndStayButton).click();

return this.getAlertSuccessBlockContent(page);
return this.getAlertSuccessBlockParagraphContent(page);
}

/**
Expand All @@ -111,4 +114,5 @@ class BOTaxRulesCreatePage extends BOBasePage implements BOTaxRulesCreatePageInt
}
}

module.exports = new BOTaxRulesCreatePage();
const boTaxRulesCreatePage = new BOTaxRulesCreatePage();
export {boTaxRulesCreatePage, BOTaxRulesCreatePage};
Loading
Loading