Skip to content

Commit

Permalink
Merge pull request #458 from Progi1984/boStatesCreatePage
Browse files Browse the repository at this point in the history
Migrate `@pages/BO/international/taxes/add` from Core
  • Loading branch information
Progi1984 authored Mar 3, 2025
2 parents 775b410 + 27685b5 commit 2275bc1
Show file tree
Hide file tree
Showing 4 changed files with 114 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 @@ -331,6 +331,7 @@ export {default as boSuppliersCreatePage} from '@pages/BO/catalog/suppliers/crea
export {default as boSuppliersPage} from '@pages/BO/catalog/suppliers';
export {default as boSuppliersViewPage} from '@pages/BO/catalog/suppliers/view';
export {default as boTaxesPage} from '@pages/BO/international/taxes';
export {default as boTaxesCreatePage} from '@pages/BO/international/taxes/create';
export {default as boTaxRulesPage} from '@pages/BO/international/taxes/taxRules';
export {default as boTaxRulesCreatePage} from '@pages/BO/international/taxes/taxRules/create';
export {default as boThemeAdvancedConfigurationPage} from '@pages/BO/design/themeAndLogo/advancedConfiguration';
Expand Down
10 changes: 10 additions & 0 deletions src/interfaces/BO/international/taxes/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type FakerTax from '@data/faker/tax';
import {BOBasePagePageInterface} from '@interfaces/BO';
import {type Page} from '@playwright/test';

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

createEditTax(page: Page, taxData: FakerTax): Promise<string>;
}
9 changes: 9 additions & 0 deletions src/pages/BO/international/taxes/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {type BOTaxesCreatePageInterface} from '@interfaces/BO/international/taxes/create';

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

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

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

public readonly pageTitleEdit: string;

private readonly successfulUpdateStatusMessage: string;

private readonly nameEnInput: string;

private readonly nameFrInput: string;

private readonly inputLangDropdownButton: string;

private readonly inputLangChoiceSpan: (lang: string) => string;

private readonly rateInput: string;

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

private readonly saveTaxButton: string;

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

this.pageTitleCreate = `New tax • ${global.INSTALL.SHOP_NAME}`;
this.pageTitleEdit = 'Editing tax';
this.successfulUpdateStatusMessage = 'The status has been successfully updated.';

// Selectors
this.nameEnInput = '#tax_name_1';
this.nameFrInput = '#tax_name_2';
this.inputLangDropdownButton = 'button#tax_name_dropdown';
this.inputLangChoiceSpan = (lang: string) => `div.dropdown-menu span[data-locale='${lang}']`;
this.rateInput = '#tax_rate';
this.statusToggleInput = (toggle: number) => `#tax_is_enabled_${toggle}`;
this.saveTaxButton = '#save-button';
}

/*
Methods
*/

/**
* Change language for input name
* @param page {Page} Browser tab
* @param lang {string} Value of language to change
* @return {Promise<void>}
*/
async changeInputLanguage(page: Page, lang: string): Promise<void> {
await Promise.all([
page.locator(this.inputLangDropdownButton).click(),
this.waitForVisibleSelector(page, `${this.inputLangDropdownButton}[aria-expanded='true']`),
]);
await Promise.all([
page.locator(this.inputLangChoiceSpan(lang)).click(),
this.waitForVisibleSelector(page, `${this.inputLangDropdownButton}[aria-expanded='false']`),
]);
}

/**
* Fill form for add/edit tax
* @param page {Page} Browser tab
* @param taxData {FakerTax} Data to set on new/edit tax page
* @returns {Promise<string>}
*/
async createEditTax(page: Page, taxData: FakerTax): Promise<string> {
await this.changeInputLanguage(page, 'en');
await this.setValue(page, this.nameEnInput, taxData.name);
await this.changeInputLanguage(page, 'fr');
await this.setValue(page, this.nameFrInput, taxData.frName);
await this.setValue(page, this.rateInput, taxData.rate);
await this.setChecked(page, this.statusToggleInput(taxData.enabled ? 1 : 0));
// Save Tax
await this.clickAndWaitForURL(page, this.saveTaxButton);

return this.getAlertSuccessBlockParagraphContent(page);
}
}

module.exports = new BOTaxesCreatePage();

0 comments on commit 2275bc1

Please sign in to comment.