|
| 1 | +import FakerTax from '@data/faker/tax'; |
| 2 | +import {type BOTaxesCreatePageInterface} from '@interfaces/BO/international/taxes/create'; |
| 3 | +import BOBasePage from '@pages/BO/BOBasePage'; |
| 4 | +import { Page } from '@playwright/test'; |
| 5 | + |
| 6 | +/** |
| 7 | + * Add tax page, contains functions that can be used on the page |
| 8 | + * @class |
| 9 | + * @extends BOBasePage |
| 10 | + */ |
| 11 | +class BOTaxesCreatePage extends BOBasePage implements BOTaxesCreatePageInterface { |
| 12 | + public readonly pageTitleCreate: string; |
| 13 | + |
| 14 | + public readonly pageTitleEdit: string; |
| 15 | + |
| 16 | + private readonly successfulUpdateStatusMessage: string; |
| 17 | + |
| 18 | + private readonly nameEnInput: string; |
| 19 | + |
| 20 | + private readonly nameFrInput: string; |
| 21 | + |
| 22 | + private readonly inputLangDropdownButton: string; |
| 23 | + |
| 24 | + private readonly inputLangChoiceSpan: (lang: string) => string; |
| 25 | + |
| 26 | + private readonly rateInput: string; |
| 27 | + |
| 28 | + private readonly statusToggleInput: (toggle: number) => string; |
| 29 | + |
| 30 | + private readonly saveTaxButton: string; |
| 31 | + |
| 32 | + /** |
| 33 | + * @constructs |
| 34 | + * Setting up texts and selectors to use on add tax page |
| 35 | + */ |
| 36 | + constructor() { |
| 37 | + super(); |
| 38 | + |
| 39 | + this.pageTitleCreate = `New tax • ${global.INSTALL.SHOP_NAME}`; |
| 40 | + this.pageTitleEdit = 'Editing tax'; |
| 41 | + this.successfulUpdateStatusMessage = 'The status has been successfully updated.'; |
| 42 | + |
| 43 | + // Selectors |
| 44 | + this.nameEnInput = '#tax_name_1'; |
| 45 | + this.nameFrInput = '#tax_name_2'; |
| 46 | + this.inputLangDropdownButton = 'button#tax_name_dropdown'; |
| 47 | + this.inputLangChoiceSpan = (lang: string) => `div.dropdown-menu span[data-locale='${lang}']`; |
| 48 | + this.rateInput = '#tax_rate'; |
| 49 | + this.statusToggleInput = (toggle: number) => `#tax_is_enabled_${toggle}`; |
| 50 | + this.saveTaxButton = '#save-button'; |
| 51 | + } |
| 52 | + |
| 53 | + /* |
| 54 | + Methods |
| 55 | + */ |
| 56 | + |
| 57 | + /** |
| 58 | + * Change language for input name |
| 59 | + * @param page {Page} Browser tab |
| 60 | + * @param lang {string} Value of language to change |
| 61 | + * @return {Promise<void>} |
| 62 | + */ |
| 63 | + async changeInputLanguage(page: Page, lang: string): Promise<void> { |
| 64 | + await Promise.all([ |
| 65 | + page.locator(this.inputLangDropdownButton).click(), |
| 66 | + this.waitForVisibleSelector(page, `${this.inputLangDropdownButton}[aria-expanded='true']`), |
| 67 | + ]); |
| 68 | + await Promise.all([ |
| 69 | + page.locator(this.inputLangChoiceSpan(lang)).click(), |
| 70 | + this.waitForVisibleSelector(page, `${this.inputLangDropdownButton}[aria-expanded='false']`), |
| 71 | + ]); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * Fill form for add/edit tax |
| 76 | + * @param page {Page} Browser tab |
| 77 | + * @param taxData {FakerTax} Data to set on new/edit tax page |
| 78 | + * @returns {Promise<string>} |
| 79 | + */ |
| 80 | + async createEditTax(page: Page, taxData: FakerTax): Promise<string> { |
| 81 | + await this.changeInputLanguage(page, 'en'); |
| 82 | + await this.setValue(page, this.nameEnInput, taxData.name); |
| 83 | + await this.changeInputLanguage(page, 'fr'); |
| 84 | + await this.setValue(page, this.nameFrInput, taxData.frName); |
| 85 | + await this.setValue(page, this.rateInput, taxData.rate); |
| 86 | + await this.setChecked(page, this.statusToggleInput(taxData.enabled ? 1 : 0)); |
| 87 | + // Save Tax |
| 88 | + await this.clickAndWaitForURL(page, this.saveTaxButton); |
| 89 | + |
| 90 | + return this.getAlertSuccessBlockParagraphContent(page); |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +module.exports = new BOTaxesCreatePage(); |
0 commit comments