Skip to content

Commit 931f20e

Browse files
committed
Functional Tests : Enable feature flag "Tax rule groups"
1 parent ab9f1e8 commit 931f20e

7 files changed

Lines changed: 308 additions & 92 deletions

File tree

src/pages/BO/international/taxes/taxRules/create.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import {type BOTaxRulesCreatePageInterface} from '@interfaces/BO/international/taxes/taxRules/create';
2+
import testContext from '@utils/test';
3+
import semver from 'semver';
4+
5+
const psVersion = testContext.getPSVersion();
26

37
/* eslint-disable global-require, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */
48
function requirePage(): BOTaxRulesCreatePageInterface {
5-
return require('@versions/develop/pages/BO/international/taxes/taxRules/create');
9+
if (semver.lt(psVersion, '9.2.0')) {
10+
return require('@versions/9.1/pages/BO/international/taxes/taxRules/create').boTaxRulesCreatePage;
11+
}
12+
return require('@versions/develop/pages/BO/international/taxes/taxRules/create').boTaxRulesCreatePage;
613
}
714
/* eslint-enable global-require, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */
815

src/pages/BO/international/taxes/taxRules/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import {type BOTaxRulesPageInterface} from '@interfaces/BO/international/taxes/taxRules';
2+
import testContext from '@utils/test';
3+
import semver from 'semver';
4+
5+
const psVersion = testContext.getPSVersion();
26

37
/* eslint-disable global-require, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */
48
function requirePage(): BOTaxRulesPageInterface {
5-
return require('@versions/develop/pages/BO/international/taxes/taxRules');
9+
if (semver.lt(psVersion, '9.2.0')) {
10+
return require('@versions/9.1/pages/BO/international/taxes/taxRules').boTaxRulesPage;
11+
}
12+
return require('@versions/develop/pages/BO/international/taxes/taxRules').boTaxRulesPage;
613
}
714
/* eslint-enable global-require, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */
815

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import type FakerTaxRule from '@data/faker/taxRule';
2+
import type FakerTaxRulesGroup from '@data/faker/taxRulesGroup';
3+
import {type BOTaxRulesCreatePageInterface} from '@interfaces/BO/international/taxes/taxRules/create';
4+
import {type Page} from '@playwright/test';
5+
import {
6+
BOTaxRulesCreatePage as BOTaxRulesCreatePageVersion,
7+
} from '@versions/develop/pages/BO/international/taxes/taxRules/create';
8+
9+
class BOTaxRulesCreatePage extends BOTaxRulesCreatePageVersion implements BOTaxRulesCreatePageInterface {
10+
constructor() {
11+
super();
12+
13+
this.pageTitleCreate = 'Tax Rules > Add new';
14+
this.pageTitleEdit = 'Tax Rules > Edit';
15+
16+
// Selectors
17+
// Header buttons
18+
this.addNewTaxRuleButton = 'a[data-role=page-header-desc-tax_rule-link]';
19+
20+
// New tax rule group form
21+
this.taxRuleGroupForm = '#tax_rules_group_form';
22+
this.nameInput = `${this.taxRuleGroupForm} #name`;
23+
this.statusInput = (id: string) => `${this.taxRuleGroupForm} input#active_${id}`;
24+
this.saveTaxButton = `${this.taxRuleGroupForm} #tax_rules_group_form_submit_btn`;
25+
26+
// New tax rule form
27+
this.taxRuleForm = '#tax_rule_form';
28+
this.countrySelect = `${this.taxRuleForm} #country`;
29+
this.behaviourSelect = `${this.taxRuleForm} #behavior`;
30+
this.taxSelect = `${this.taxRuleForm} #id_tax`;
31+
this.descriptionInput = `${this.taxRuleForm} #description`;
32+
this.saveAndStayButton = `${this.taxRuleForm} #tax_rule_form_submit_btn_1`;
33+
}
34+
35+
/**
36+
* Fill form for add/edit tax rules group
37+
* @param page {Page} Browser tab
38+
* @param taxRuleGroupData {FakerTaxRulesGroup} Data to set on tax rule group data
39+
* @returns {Promise<string>}
40+
*/
41+
async createEditTaxRulesGroup(page: Page, taxRuleGroupData: FakerTaxRulesGroup): Promise<string> {
42+
await this.setValue(page, this.nameInput, taxRuleGroupData.name);
43+
await this.setChecked(page, this.statusInput(taxRuleGroupData.enabled ? 'on' : 'off'));
44+
// Save Tax rules group
45+
await this.clickAndWaitForURL(page, this.saveTaxButton);
46+
47+
return this.getAlertSuccessBlockContent(page);
48+
}
49+
50+
/**
51+
* Fill form for add/edit tax rules group
52+
* @param page {Page} Browser tab
53+
* @param taxRuleData {FakerTaxRule} Data to set on new/edit tax rule data
54+
* @returns {Promise<string>}
55+
*/
56+
async createEditTaxRules(page: Page, taxRuleData: FakerTaxRule): Promise<string> {
57+
await this.selectByVisibleText(page, this.countrySelect, taxRuleData.country);
58+
await this.selectByVisibleText(page, this.behaviourSelect, taxRuleData.behaviour);
59+
await this.selectByVisibleText(page, this.taxSelect, taxRuleData.name);
60+
await this.setValue(page, this.descriptionInput, taxRuleData.description);
61+
// Save Tax rules
62+
await page.locator(this.saveAndStayButton).click();
63+
64+
return this.getAlertSuccessBlockContent(page);
65+
}
66+
}
67+
68+
const boTaxRulesCreatePage = new BOTaxRulesCreatePage();
69+
export {boTaxRulesCreatePage, BOTaxRulesCreatePage};
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import {type BOTaxRulesPageInterface} from '@interfaces/BO/international/taxes/taxRules';
2+
import {Page} from '@playwright/test';
3+
import {BOTaxRulesPage as BOTaxRulesPageVersion} from '@versions/develop/pages/BO/international/taxes/taxRules';
4+
5+
class BOTaxRulesPage extends BOTaxRulesPageVersion implements BOTaxRulesPageInterface {
6+
constructor() {
7+
super();
8+
9+
// Selectors
10+
// HEADER buttons
11+
this.addNewTaxRulesGroupLink = 'a[data-role=page-header-desc-tax_rules_group-link]';
12+
13+
// Form selectors
14+
this.gridTableHeaderTitle = `${this.gridForm} .panel-heading`;
15+
this.gridTableNumberOfTitlesSpan = `${this.gridTableHeaderTitle} span.badge`;
16+
this.gridTable = '#table-tax_rules_group';
17+
18+
// Filter selectors
19+
this.filterRow = `${this.gridTable} tr.filter`;
20+
this.filterColumn = (filterBy: string) => `${this.filterRow} [name='tax_rules_groupFilter_${filterBy}']`;
21+
this.filterSearchButton = '#submitFilterButtontax_rules_group';
22+
this.filterResetButton = `${this.filterRow} button[name='submitResettax_rules_group']`;
23+
24+
// Table rows and columns
25+
this.tableBody = `${this.gridTable} tbody`;
26+
this.tableRow = (row: number) => `${this.tableBody} tr:nth-child(${row})`;
27+
this.editRowLink = (row: number) => `${this.tableRow(row)} a.edit`;
28+
this.tableBodyColumn = (row: number) => `${this.tableRow(row)} td`;
29+
30+
// Columns selectors
31+
this.tableColumnId = (row: number) => `${this.tableBodyColumn(row)}:nth-child(2)`;
32+
this.tableColumnName = (row: number) => `${this.tableBodyColumn(row)}:nth-child(3)`;
33+
this.tableColumnActive = (row: number) => `${this.tableBodyColumn(row)}:nth-child(4) a`;
34+
this.tableColumnCheckIcon = (row: number) => `${this.tableColumnActive(row)} i.icon-check`;
35+
36+
// Bulk actions selectors
37+
this.bulkActionBlock = 'div.bulk-actions';
38+
this.bulkActionMenuButton = '#bulk_action_menu_tax_rules_group';
39+
this.bulkActionDropdownMenu = `${this.bulkActionBlock} ul.dropdown-menu`;
40+
this.selectAllLink = `${this.bulkActionDropdownMenu} li:nth-child(1)`;
41+
this.bulkDeleteLink = `${this.bulkActionDropdownMenu} li:nth-child(7)`;
42+
this.bulkEnableLink = `${this.bulkActionDropdownMenu} li:nth-child(4)`;
43+
this.bulkDisableLink = `${this.bulkActionDropdownMenu} li:nth-child(5)`;
44+
}
45+
46+
/**
47+
* Get text column from table
48+
* @param page {Page} Browser tab
49+
* @param row {number} Row on table
50+
* @param columnName {string} Column name to get text column from table
51+
* @returns {Promise<string>}
52+
*/
53+
async getTextColumnFromTable(page: Page, row: number, columnName: string): Promise<string> {
54+
let columnSelector;
55+
56+
switch (columnName) {
57+
case 'id_tax_rules_group':
58+
columnSelector = this.tableColumnId(row);
59+
break;
60+
61+
case 'name':
62+
columnSelector = this.tableColumnName(row);
63+
break;
64+
65+
case 'active':
66+
columnSelector = this.tableColumnActive(row);
67+
break;
68+
69+
default:
70+
throw new Error(`Column ${columnName} was not found`);
71+
}
72+
73+
if (columnName === 'active') {
74+
return this.getAttributeContent(page, columnSelector, 'title');
75+
}
76+
77+
return this.getTextContent(page, columnSelector);
78+
}
79+
80+
/**
81+
* Select all rows
82+
* @param page {Page} Browser tab
83+
* @return {Promise<void>}
84+
*/
85+
async bulkSelectRows(page: Page): Promise<void> {
86+
await page.locator(this.bulkActionMenuButton).click();
87+
88+
await Promise.all([
89+
page.locator(this.selectAllLink).click(),
90+
this.waitForHiddenSelector(page, this.selectAllLink),
91+
]);
92+
}
93+
94+
/**
95+
* Delete tax rules by bulk action
96+
* @param page {Page} Browser tab
97+
* @returns {Promise<string>}
98+
*/
99+
async bulkDeleteTaxRules(page: Page): Promise<string> {
100+
await this.dialogListener(page, true);
101+
// Select all rows
102+
await this.bulkSelectRows(page);
103+
104+
// Click on Button Bulk actions
105+
await page.locator(this.bulkActionMenuButton).click();
106+
107+
// Click on delete
108+
await this.clickAndWaitForURL(page, this.bulkDeleteLink);
109+
110+
return this.getAlertSuccessBlockContent(page);
111+
}
112+
}
113+
114+
const boTaxRulesPage = new BOTaxRulesPage();
115+
export {boTaxRulesPage, BOTaxRulesPage};

src/versions/develop/pages/BO/international/taxes/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ class BOTaxesPage extends BOBasePage implements BOTaxesPageInterface {
449449
* @param page {Page} Browser tab
450450
* @return {Promise<string>}
451451
*/
452-
getPaginationLabel(page: Page): Promise<string> {
452+
async getPaginationLabel(page: Page): Promise<string> {
453453
return this.getTextContent(page, this.paginationLabel);
454454
}
455455

src/versions/develop/pages/BO/international/taxes/taxRules/create.ts

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,31 @@ import {type Page} from '@playwright/test';
1010
* @extends BOBasePage
1111
*/
1212
class BOTaxRulesCreatePage extends BOBasePage implements BOTaxRulesCreatePageInterface {
13-
public readonly pageTitleCreate: string;
13+
public pageTitleCreate: string;
1414

15-
public readonly pageTitleEdit: string;
15+
public pageTitleEdit: string;
1616

17-
private readonly addNewTaxRuleButton: string;
17+
protected addNewTaxRuleButton: string;
1818

19-
private readonly taxRuleGroupForm: string;
19+
protected taxRuleGroupForm: string;
2020

21-
private readonly nameInput: string;
21+
protected nameInput: string;
2222

23-
private readonly statusInput: (id: string) => string;
23+
protected statusInput: (id: string) => string;
2424

25-
private readonly saveTaxButton: string;
25+
protected saveTaxButton: string;
2626

27-
private readonly taxRuleForm: string;
27+
protected taxRuleForm: string;
2828

29-
private readonly countrySelect: string;
29+
protected countrySelect: string;
3030

31-
private readonly behaviourSelect: string;
31+
protected behaviourSelect: string;
3232

33-
private readonly taxSelect: string;
33+
protected taxSelect: string;
3434

35-
private readonly descriptionInput: string;
35+
protected descriptionInput: string;
3636

37-
private readonly saveAndStayButton: string;
37+
protected saveAndStayButton: string;
3838

3939
/**
4040
* @constructs
@@ -43,26 +43,26 @@ class BOTaxRulesCreatePage extends BOBasePage implements BOTaxRulesCreatePageInt
4343
constructor() {
4444
super();
4545

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

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

5353
// New tax rule group form
54-
this.taxRuleGroupForm = '#tax_rules_group_form';
55-
this.nameInput = `${this.taxRuleGroupForm} #name`;
56-
this.statusInput = (id: string) => `${this.taxRuleGroupForm} input#active_${id}`;
57-
this.saveTaxButton = `${this.taxRuleGroupForm} #tax_rules_group_form_submit_btn`;
54+
this.taxRuleGroupForm = 'form[name="tax_rules_group"]';
55+
this.nameInput = `${this.taxRuleGroupForm} #tax_rules_group_name`;
56+
this.statusInput = (id: string) => `${this.taxRuleGroupForm} input#tax_rules_group_is_enabled_${id}`;
57+
this.saveTaxButton = `${this.taxRuleGroupForm} #save-and-stay-button`;
5858

5959
// New tax rule form
60-
this.taxRuleForm = '#tax_rule_form';
61-
this.countrySelect = `${this.taxRuleForm} #country`;
62-
this.behaviourSelect = `${this.taxRuleForm} #behavior`;
63-
this.taxSelect = `${this.taxRuleForm} #id_tax`;
64-
this.descriptionInput = `${this.taxRuleForm} #description`;
65-
this.saveAndStayButton = `${this.taxRuleForm} #tax_rule_form_submit_btn_1`;
60+
this.taxRuleForm = 'iframe[name="tax-rule-form-modal-iframe"]';
61+
this.countrySelect = '#tax_rule_country';
62+
this.behaviourSelect = '#tax_rule_behavior';
63+
this.taxSelect = '#tax_rule_tax';
64+
this.descriptionInput = '#tax_rule_description';
65+
this.saveAndStayButton = '#tax-rule-form-modal .btn-confirm-submit';
6666
}
6767

6868
/*
@@ -77,11 +77,11 @@ class BOTaxRulesCreatePage extends BOBasePage implements BOTaxRulesCreatePageInt
7777
*/
7878
async createEditTaxRulesGroup(page: Page, taxRuleGroupData: FakerTaxRulesGroup): Promise<string> {
7979
await this.setValue(page, this.nameInput, taxRuleGroupData.name);
80-
await this.setChecked(page, this.statusInput(taxRuleGroupData.enabled ? 'on' : 'off'));
80+
await this.setChecked(page, this.statusInput(taxRuleGroupData.enabled ? '1' : '0'));
8181
// Save Tax rules group
8282
await this.clickAndWaitForURL(page, this.saveTaxButton);
8383

84-
return this.getAlertSuccessBlockContent(page);
84+
return this.getAlertSuccessBlockParagraphContent(page);
8585
}
8686

8787
/**
@@ -91,14 +91,17 @@ class BOTaxRulesCreatePage extends BOBasePage implements BOTaxRulesCreatePageInt
9191
* @returns {Promise<string>}
9292
*/
9393
async createEditTaxRules(page: Page, taxRuleData: FakerTaxRule): Promise<string> {
94-
await this.selectByVisibleText(page, this.countrySelect, taxRuleData.country);
95-
await this.selectByVisibleText(page, this.behaviourSelect, taxRuleData.behaviour);
96-
await this.selectByVisibleText(page, this.taxSelect, taxRuleData.name);
97-
await this.setValue(page, this.descriptionInput, taxRuleData.description);
98-
// Save Tax rules
94+
await page.locator(this.addNewTaxRuleButton).click();
95+
await page.locator(this.taxRuleForm).waitFor({state: 'visible'});
96+
97+
const iframeLocator = await page.frameLocator(this.taxRuleForm);
98+
await iframeLocator.locator(this.countrySelect).selectOption({label: taxRuleData.country});
99+
await iframeLocator.locator(this.behaviourSelect).selectOption({label: taxRuleData.behaviour});
100+
await iframeLocator.locator(this.taxSelect).selectOption({label: taxRuleData.name});
101+
await iframeLocator.locator(this.descriptionInput).fill(taxRuleData.description);
99102
await page.locator(this.saveAndStayButton).click();
100103

101-
return this.getAlertSuccessBlockContent(page);
104+
return this.getAlertSuccessBlockParagraphContent(page);
102105
}
103106

104107
/**
@@ -111,4 +114,5 @@ class BOTaxRulesCreatePage extends BOBasePage implements BOTaxRulesCreatePageInt
111114
}
112115
}
113116

114-
module.exports = new BOTaxRulesCreatePage();
117+
const boTaxRulesCreatePage = new BOTaxRulesCreatePage();
118+
export {boTaxRulesCreatePage, BOTaxRulesCreatePage};

0 commit comments

Comments
 (0)