|
| 1 | +import type FakerCountry from '@data/faker/country'; |
| 2 | +import {type BOCountriesCreatePageInterface} from '@interfaces/BO/international/locations/countries/create'; |
| 3 | +import {type Page} from '@playwright/test'; |
| 4 | +import { |
| 5 | + BOCountriesCreatePage as BOCountriesCreatePageVersion, |
| 6 | +} from '@versions/develop/pages/BO/international/locations/countries/create'; |
| 7 | + |
| 8 | +class BOCountriesCreatePage extends BOCountriesCreatePageVersion implements BOCountriesCreatePageInterface { |
| 9 | + /** |
| 10 | + * @constructs |
| 11 | + */ |
| 12 | + constructor() { |
| 13 | + super(); |
| 14 | + |
| 15 | + this.pageTitleCreate = 'Countries > Add new •'; |
| 16 | + this.errorMessageIsoCode = 'This ISO code already exists.You cannot create two countries with the same ISO code.'; |
| 17 | + |
| 18 | + // Selectors |
| 19 | + this.nameInputEn = '#name_1'; |
| 20 | + this.nameInputFr = '#name_2'; |
| 21 | + this.isoCodeInput = '#iso_code'; |
| 22 | + this.callPrefixInput = '#call_prefix'; |
| 23 | + this.defaultCurrencySelect = '#id_currency'; |
| 24 | + this.zoneSelect = '#id_zone'; |
| 25 | + this.needZipCodeLabel = (toggle: string) => `#need_zip_code_${toggle}`; |
| 26 | + this.zipCodeFormatInput = '#zip_code_format'; |
| 27 | + this.activeLabel = (toggle: string) => `#active_${toggle}`; |
| 28 | + this.containsStatesLabel = (toggle: string) => `#contains_states_${toggle}`; |
| 29 | + this.needIdentificationNumberLabel = (toggle: string) => `#need_identification_number_${toggle}`; |
| 30 | + this.displayTaxLabel = (toggle: string) => `#display_tax_label_${toggle}`; |
| 31 | + this.saveCountryButton = '#country_form_submit_btn'; |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * Fill form for add/edit country |
| 36 | + * @param page {Page} Browser tab |
| 37 | + * @param countryData {FakerCountry} Data to set on new country form |
| 38 | + * @returns {Promise<string>} |
| 39 | + */ |
| 40 | + async createEditCountry(page: Page, countryData: FakerCountry): Promise<string> { |
| 41 | + await this.setValue(page, this.nameInputEn, countryData.name); |
| 42 | + await this.setValue(page, this.isoCodeInput, countryData.isoCode); |
| 43 | + await this.setValue(page, this.callPrefixInput, countryData.callPrefix.toString()); |
| 44 | + await this.selectByVisibleText(page, this.defaultCurrencySelect, countryData.currency); |
| 45 | + await this.selectByVisibleText(page, this.zoneSelect, countryData.zone); |
| 46 | + await this.setChecked(page, this.needZipCodeLabel(countryData.needZipCode ? 'on' : 'off')); |
| 47 | + await this.setValue(page, this.zipCodeFormatInput, countryData.zipCodeFormat); |
| 48 | + await this.setChecked(page, this.activeLabel(countryData.active ? 'on' : 'off')); |
| 49 | + await this.setChecked(page, this.containsStatesLabel(countryData.containsStates ? 'on' : 'off')); |
| 50 | + await this.setChecked( |
| 51 | + page, |
| 52 | + this.needIdentificationNumberLabel(countryData.needIdentificationNumber ? 'on' : 'off'), |
| 53 | + ); |
| 54 | + await this.setChecked(page, this.displayTaxLabel(countryData.displayTaxNumber ? 'on' : 'off')); |
| 55 | + // Save country |
| 56 | + await this.clickAndWaitForURL(page, this.saveCountryButton); |
| 57 | + |
| 58 | + return this.getTextContent(page, this.alertBlock); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Get the value of an input |
| 63 | + * @param page {Page} Browser tab |
| 64 | + * @param input {string} ID of the input |
| 65 | + * @returns {Promise<string>} |
| 66 | + */ |
| 67 | + async isCheckboxChecked(page: Page, input: string): Promise<boolean> { |
| 68 | + let selector: string; |
| 69 | + |
| 70 | + switch (input) { |
| 71 | + case 'active': |
| 72 | + selector = this.activeLabel('on'); |
| 73 | + break; |
| 74 | + case 'contains_states': |
| 75 | + selector = this.containsStatesLabel('on'); |
| 76 | + break; |
| 77 | + case 'display_tax_label': |
| 78 | + selector = this.displayTaxLabel('on'); |
| 79 | + break; |
| 80 | + case 'need_identification_number': |
| 81 | + selector = this.needIdentificationNumberLabel('on'); |
| 82 | + break; |
| 83 | + case 'need_zip_code': |
| 84 | + selector = this.needZipCodeLabel('on'); |
| 85 | + break; |
| 86 | + default: |
| 87 | + throw new Error(`Field ${input} was not found`); |
| 88 | + } |
| 89 | + |
| 90 | + return this.isChecked(page, selector); |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +const boCountriesCreatePage = new BOCountriesCreatePage(); |
| 95 | +export {boCountriesCreatePage, BOCountriesCreatePage}; |
0 commit comments