From 69c3c4866e053fe872ce17f72a5344e8bcc4b583 Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Wed, 1 Jul 2026 11:35:41 +0200 Subject: [PATCH] Functional Tests : Enable feature flag "Tax rule groups" --- .../BO/international/taxes/taxRules/create.ts | 9 +- .../BO/international/taxes/taxRules/index.ts | 9 +- .../BO/international/taxes/taxRules/create.ts | 71 +++++++++ .../BO/international/taxes/taxRules/index.ts | 140 ++++++++++++++++++ .../pages/BO/international/taxes/index.ts | 2 +- .../BO/international/taxes/taxRules/create.ts | 76 +++++----- .../BO/international/taxes/taxRules/index.ts | 138 +++++++++-------- 7 files changed, 345 insertions(+), 100 deletions(-) create mode 100644 src/versions/9.1/pages/BO/international/taxes/taxRules/create.ts create mode 100644 src/versions/9.1/pages/BO/international/taxes/taxRules/index.ts diff --git a/src/pages/BO/international/taxes/taxRules/create.ts b/src/pages/BO/international/taxes/taxRules/create.ts index ad3788a9c..74874ce51 100644 --- a/src/pages/BO/international/taxes/taxRules/create.ts +++ b/src/pages/BO/international/taxes/taxRules/create.ts @@ -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 */ diff --git a/src/pages/BO/international/taxes/taxRules/index.ts b/src/pages/BO/international/taxes/taxRules/index.ts index 22f15e340..c6b0145ab 100644 --- a/src/pages/BO/international/taxes/taxRules/index.ts +++ b/src/pages/BO/international/taxes/taxRules/index.ts @@ -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 */ diff --git a/src/versions/9.1/pages/BO/international/taxes/taxRules/create.ts b/src/versions/9.1/pages/BO/international/taxes/taxRules/create.ts new file mode 100644 index 000000000..5e4d5e78a --- /dev/null +++ b/src/versions/9.1/pages/BO/international/taxes/taxRules/create.ts @@ -0,0 +1,71 @@ +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.successfulUpdateMessage = 'Successful update'; + + 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} + */ + async createEditTaxRulesGroup(page: Page, taxRuleGroupData: FakerTaxRulesGroup): Promise { + 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} + */ + async createEditTaxRules(page: Page, taxRuleData: FakerTaxRule): Promise { + 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}; diff --git a/src/versions/9.1/pages/BO/international/taxes/taxRules/index.ts b/src/versions/9.1/pages/BO/international/taxes/taxRules/index.ts new file mode 100644 index 000000000..a1141d687 --- /dev/null +++ b/src/versions/9.1/pages/BO/international/taxes/taxRules/index.ts @@ -0,0 +1,140 @@ +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.toggleDropDown = (row: number) => `${this.tableRow(row)} button[data-toggle='dropdown']`; + this.deleteRowLink = (row: number) => `${this.tableRow(row)} a.delete`; + + // Confirmation modal + this.deleteModalButtonYes = '#popup_ok'; + + // 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} + */ + async getTextColumnFromTable(page: Page, row: number, columnName: string): Promise { + 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} + */ + async bulkSelectRows(page: Page): Promise { + 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} + */ + async bulkDeleteTaxRules(page: Page): Promise { + 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); + } + + /** + * Delete Tax Rule + * @param page {Page} Browser tab + * @param row {number} Row on table + * @returns {Promise} + */ + async deleteTaxRule(page: Page, row: number = 1): Promise { + // Click on dropDown + await page.locator(this.toggleDropDown(row)).click(); + // Click on delete + await this.clickAndWaitForURL(page, this.deleteRowLink(row)); + // Confirm delete action + await this.clickAndWaitForURL(page, this.deleteModalButtonYes); + + // Get successful message + return this.getAlertSuccessBlockContent(page); + } +} + +const boTaxRulesPage = new BOTaxRulesPage(); +export {boTaxRulesPage, BOTaxRulesPage}; diff --git a/src/versions/develop/pages/BO/international/taxes/index.ts b/src/versions/develop/pages/BO/international/taxes/index.ts index ea4d8110b..5a31a5108 100644 --- a/src/versions/develop/pages/BO/international/taxes/index.ts +++ b/src/versions/develop/pages/BO/international/taxes/index.ts @@ -449,7 +449,7 @@ class BOTaxesPage extends BOBasePage implements BOTaxesPageInterface { * @param page {Page} Browser tab * @return {Promise} */ - getPaginationLabel(page: Page): Promise { + async getPaginationLabel(page: Page): Promise { return this.getTextContent(page, this.paginationLabel); } diff --git a/src/versions/develop/pages/BO/international/taxes/taxRules/create.ts b/src/versions/develop/pages/BO/international/taxes/taxRules/create.ts index 954a4f70a..9694b6777 100644 --- a/src/versions/develop/pages/BO/international/taxes/taxRules/create.ts +++ b/src/versions/develop/pages/BO/international/taxes/taxRules/create.ts @@ -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 @@ -43,26 +43,28 @@ class BOTaxRulesCreatePage extends BOBasePage implements BOTaxRulesCreatePageInt constructor() { super(); - this.pageTitleCreate = 'Tax Rules > Add new'; - this.pageTitleEdit = 'Tax Rules > Edit'; + this.successfulUpdateMessage = 'Update successful'; + + 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'; } /* @@ -77,11 +79,11 @@ class BOTaxRulesCreatePage extends BOBasePage implements BOTaxRulesCreatePageInt */ async createEditTaxRulesGroup(page: Page, taxRuleGroupData: FakerTaxRulesGroup): Promise { 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); } /** @@ -91,14 +93,17 @@ class BOTaxRulesCreatePage extends BOBasePage implements BOTaxRulesCreatePageInt * @returns {Promise} */ async createEditTaxRules(page: Page, taxRuleData: FakerTaxRule): Promise { - 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); } /** @@ -111,4 +116,5 @@ class BOTaxRulesCreatePage extends BOBasePage implements BOTaxRulesCreatePageInt } } -module.exports = new BOTaxRulesCreatePage(); +const boTaxRulesCreatePage = new BOTaxRulesCreatePage(); +export {boTaxRulesCreatePage, BOTaxRulesCreatePage}; diff --git a/src/versions/develop/pages/BO/international/taxes/taxRules/index.ts b/src/versions/develop/pages/BO/international/taxes/taxRules/index.ts index 9dbd666e3..50d261bc6 100644 --- a/src/versions/develop/pages/BO/international/taxes/taxRules/index.ts +++ b/src/versions/develop/pages/BO/international/taxes/taxRules/index.ts @@ -12,45 +12,45 @@ class BOTaxRulesPage extends BOBasePage implements BOTaxRulesPageInterface { public readonly successfulUpdateStatusMessage: string; - private readonly addNewTaxRulesGroupLink: string; + protected addNewTaxRulesGroupLink: string; - private readonly gridForm: string; + protected readonly gridForm: string; - private readonly gridTableHeaderTitle: string; + protected gridTableHeaderTitle: string; - private readonly gridTableNumberOfTitlesSpan: string; + protected gridTableNumberOfTitlesSpan: string; - private readonly gridTable: string; + protected gridTable: string; - private readonly filterRow: string; + protected filterRow: string; - private readonly filterColumn: (filterBy: string) => string; + protected filterColumn: (filterBy: string) => string; - private readonly filterSearchButton: string; + protected filterSearchButton: string; - private readonly filterResetButton: string; + protected filterResetButton: string; - private readonly tableBody: string; + protected tableBody: string; - private readonly tableRow: (row: number) => string; + protected tableRow: (row: number) => string; - private readonly editRowLink: (row: number) => string; + protected editRowLink: (row: number) => string; - private readonly tableBodyColumn: (row: number) => string; + protected tableBodyColumn: (row: number) => string; - private readonly tableColumnId: (row: number) => string; + protected tableColumnId: (row: number) => string; - private readonly tableColumnName: (row: number) => string; + protected tableColumnName: (row: number) => string; - private readonly tableColumnActive: (row: number) => string; + protected tableColumnActive: (row: number) => string; - private readonly tableColumnCheckIcon: (row: number) => string; + protected tableColumnCheckIcon: (row: number) => string; - private readonly toggleDropDown: (row: number) => string; + protected toggleDropDown: (row: number) => string; - private readonly deleteRowLink: (row: number) => string; + protected deleteRowLink: (row: number) => string; - private readonly deleteModalButtonYes: string; + protected deleteModalButtonYes: string; private readonly tableHead: string; @@ -70,19 +70,23 @@ class BOTaxRulesPage extends BOBasePage implements BOTaxRulesPageInterface { private readonly paginationNextLink: string; - private readonly bulkActionBlock: string; + protected bulkActionBlock: string; - private readonly bulkActionMenuButton: string; + protected bulkActionMenuButton: string; - private readonly bulkActionDropdownMenu: string; + protected bulkActionDropdownMenu: string; - private readonly selectAllLink: string; + protected selectAllLink: string; - private readonly bulkDeleteLink: string; + protected bulkDeleteLink: string; - private readonly bulkEnableLink: string; + protected bulkEnableLink: string; - private readonly bulkDisableLink: string; + protected bulkDisableLink: string; + + private readonly modalConfirm: string; + + private readonly modalConfirmBtn: string; /** * @constructs @@ -96,38 +100,38 @@ class BOTaxRulesPage extends BOBasePage implements BOTaxRulesPageInterface { // Selectors // HEADER buttons - this.addNewTaxRulesGroupLink = 'a[data-role=page-header-desc-tax_rules_group-link]'; + this.addNewTaxRulesGroupLink = 'a#page-header-desc-configuration-add'; // Form selectors this.gridForm = '#form-tax_rules_group'; - this.gridTableHeaderTitle = `${this.gridForm} .panel-heading`; - this.gridTableNumberOfTitlesSpan = `${this.gridTableHeaderTitle} span.badge`; - this.gridTable = '#table-tax_rules_group'; + this.gridTableHeaderTitle = '#tax_rules_group_grid_panel .card-header'; + this.gridTableNumberOfTitlesSpan = `${this.gridTableHeaderTitle} .card-header-title`; + this.gridTable = '#tax_rules_group_grid_table'; // 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']`; + this.filterRow = `${this.gridTable} tr.column-filters`; + this.filterColumn = (filterBy: string) => `${this.filterRow} [name='tax_rules_group[${filterBy}]']`; + this.filterSearchButton = `${this.filterRow} .grid-search-button`; + this.filterResetButton = `${this.filterRow} .grid-reset-button`; // 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.editRowLink = (row: number) => `${this.tableRow(row)} a.grid-edit-row-link`; 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`; + this.tableColumnId = (row: number) => `${this.tableBodyColumn(row)}.column-id_tax_rules_group`; + this.tableColumnName = (row: number) => `${this.tableBodyColumn(row)}.column-name`; + this.tableColumnActive = (row: number) => `${this.tableBodyColumn(row)}.column-active`; + this.tableColumnCheckIcon = (row: number) => `${this.tableColumnActive(row)} .ps-switch`; // Bulk actions selectors - this.toggleDropDown = (row: number) => `${this.tableRow(row)} button[data-toggle='dropdown']`; - this.deleteRowLink = (row: number) => `${this.tableRow(row)} a.delete`; + this.toggleDropDown = (row: number) => `${this.tableRow(row)} a[data-toggle='dropdown']`; + this.deleteRowLink = (row: number) => `${this.tableRow(row)} a.grid-delete-row-link`; // Confirmation modal - this.deleteModalButtonYes = '#popup_ok'; + this.deleteModalButtonYes = '#tax_rules_group-grid-confirm-modal .btn-confirm-submit'; // Sort Selectors this.tableHead = `${this.gridTable} thead`; @@ -143,13 +147,17 @@ class BOTaxRulesPage extends BOBasePage implements BOTaxRulesPageInterface { this.paginationNextLink = `${this.gridForm} .icon-angle-right`; // 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)`; + this.bulkActionBlock = '#tax_rules_group_grid'; + this.bulkActionMenuButton = `${this.bulkActionBlock} .js-bulk-actions-btn`; + this.bulkActionDropdownMenu = `${this.bulkActionBlock} .dropdown-menu`; + this.selectAllLink = `${this.filterRow} .grid_bulk_action_select_all`; + this.bulkDeleteLink = `${this.bulkActionDropdownMenu} #tax_rules_group_grid_bulk_action_delete_selection`; + this.bulkEnableLink = `${this.bulkActionDropdownMenu} #tax_rules_group_grid_bulk_action_enable_selection`; + this.bulkDisableLink = `${this.bulkActionDropdownMenu} #tax_rules_group_grid_bulk_action_disable_selection`; + + // Modal + this.modalConfirm = '#tax_rules_group-grid-confirm-modal'; + this.modalConfirmBtn = `${this.modalConfirm} .btn-confirm-submit`; } /* @@ -224,7 +232,11 @@ class BOTaxRulesPage extends BOBasePage implements BOTaxRulesPageInterface { } if (columnName === 'active') { - return this.getAttributeContent(page, columnSelector, 'title'); + return (await this.getAttributeContent( + page, + `${columnSelector} input[checked]`, + 'value', + ) === '1' ? 'Enabled' : 'Disabled'); } return this.getTextContent(page, columnSelector); @@ -275,12 +287,12 @@ class BOTaxRulesPage extends BOBasePage implements BOTaxRulesPageInterface { // Click on dropDown await page.locator(this.toggleDropDown(row)).click(); // Click on delete - await this.clickAndWaitForURL(page, this.deleteRowLink(row)); + await page.locator(this.deleteRowLink(row)).click(); // Confirm delete action await this.clickAndWaitForURL(page, this.deleteModalButtonYes); // Get successful message - return this.getAlertSuccessBlockContent(page); + return this.getAlertSuccessBlockParagraphContent(page); } // Sort methods @@ -335,7 +347,7 @@ class BOTaxRulesPage extends BOBasePage implements BOTaxRulesPageInterface { * @param page {Page} Browser tab * @return {Promise} */ - getPaginationLabel(page: Page): Promise { + async getPaginationLabel(page: Page): Promise { return this.getTextContent(page, this.paginationActiveLabel); } @@ -381,11 +393,9 @@ class BOTaxRulesPage extends BOBasePage implements BOTaxRulesPageInterface { * @return {Promise} */ async bulkSelectRows(page: Page): Promise { - await page.locator(this.bulkActionMenuButton).click(); - await Promise.all([ - page.locator(this.selectAllLink).click(), - this.waitForHiddenSelector(page, this.selectAllLink), + page.locator(this.selectAllLink).evaluate((el: HTMLElement) => el.click()), + this.waitForVisibleSelector(page, `${this.bulkActionMenuButton}:not([disabled])`), ]); } @@ -395,7 +405,6 @@ class BOTaxRulesPage extends BOBasePage implements BOTaxRulesPageInterface { * @returns {Promise} */ async bulkDeleteTaxRules(page: Page): Promise { - await this.dialogListener(page, true); // Select all rows await this.bulkSelectRows(page); @@ -403,9 +412,13 @@ class BOTaxRulesPage extends BOBasePage implements BOTaxRulesPageInterface { await page.locator(this.bulkActionMenuButton).click(); // Click on delete - await this.clickAndWaitForURL(page, this.bulkDeleteLink); + await page.locator(this.bulkDeleteLink).click(); + + // Click on modal + await page.locator(this.modalConfirm).waitFor({state: 'visible'}); + await page.locator(this.modalConfirmBtn).click(); - return this.getAlertSuccessBlockContent(page); + return this.getAlertSuccessBlockParagraphContent(page); } /** @@ -459,4 +472,5 @@ class BOTaxRulesPage extends BOBasePage implements BOTaxRulesPageInterface { } } -module.exports = new BOTaxRulesPage(); +const boTaxRulesPage = new BOTaxRulesPage(); +export {boTaxRulesPage, BOTaxRulesPage};