|
| 1 | +import type FakerState from '@data/faker/state'; |
| 2 | +import {type BOStatesCreatePageInterface} from '@interfaces/BO/international/locations/states/create'; |
| 3 | +import BOBasePage from '@pages/BO/BOBasePage'; |
| 4 | +import {type Page} from '@playwright/test'; |
| 5 | + |
| 6 | +/** |
| 7 | + * Add state page, contains functions that can be used on the page |
| 8 | + * @class |
| 9 | + * @extends BOBasePage |
| 10 | + */ |
| 11 | +class BOStatesCreatePage extends BOBasePage implements BOStatesCreatePageInterface { |
| 12 | + public readonly pageTitleCreate: string; |
| 13 | + |
| 14 | + public readonly pageTitleEdit: string; |
| 15 | + |
| 16 | + private readonly nameInput: string; |
| 17 | + |
| 18 | + private readonly isoCodeInput: string; |
| 19 | + |
| 20 | + private readonly countrySelect: string; |
| 21 | + |
| 22 | + private readonly zoneSelect: string; |
| 23 | + |
| 24 | + private readonly statusToggle: (toggle: number) => string; |
| 25 | + |
| 26 | + private readonly saveStateButton: string; |
| 27 | + |
| 28 | + /** |
| 29 | + * @constructs |
| 30 | + * Setting up texts and selectors to use on add state page |
| 31 | + */ |
| 32 | + constructor() { |
| 33 | + super(); |
| 34 | + |
| 35 | + this.pageTitleCreate = `New state • ${global.INSTALL.SHOP_NAME}`; |
| 36 | + this.pageTitleEdit = 'Editing state'; |
| 37 | + |
| 38 | + // Selectors |
| 39 | + this.nameInput = '#state_name'; |
| 40 | + this.isoCodeInput = '#state_iso_code'; |
| 41 | + this.countrySelect = '#state_id_country'; |
| 42 | + this.zoneSelect = '#state_id_zone'; |
| 43 | + this.statusToggle = (toggle: number) => `#state_active_${toggle}`; |
| 44 | + this.saveStateButton = '#save-button'; |
| 45 | + } |
| 46 | + |
| 47 | + /* |
| 48 | + Methods |
| 49 | + */ |
| 50 | + /** |
| 51 | + * Fill form for add/edit state |
| 52 | + * @param page {Page} Browser tab |
| 53 | + * @param stateData {FakerState} Data to set on new/edit state form |
| 54 | + * @returns {Promise<string>} |
| 55 | + */ |
| 56 | + async createEditState(page: Page, stateData: FakerState): Promise<string> { |
| 57 | + // Fill form |
| 58 | + await this.setValue(page, this.nameInput, stateData.name); |
| 59 | + await this.setValue(page, this.isoCodeInput, stateData.isoCode); |
| 60 | + await this.selectByVisibleText(page, this.countrySelect, stateData.country); |
| 61 | + await this.selectByVisibleText(page, this.zoneSelect, stateData.zone); |
| 62 | + await this.setChecked(page, this.statusToggle(stateData.status ? 1 : 0)); |
| 63 | + |
| 64 | + // Save zone |
| 65 | + await this.clickAndWaitForURL(page, this.saveStateButton); |
| 66 | + |
| 67 | + // Return successful message |
| 68 | + return this.getAlertSuccessBlockParagraphContent(page); |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +module.exports = new BOStatesCreatePage(); |
0 commit comments