Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate @pages/BO/international/taxes/add from Core #458

Merged
merged 1 commit into from
Mar 3, 2025
Merged
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
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();