|
| 1 | +import type FakerCarrier from '@data/faker/carrier'; |
| 2 | +import {type BOShippingPreferencesInterface} from '@interfaces/BO/shipping/preferences'; |
| 3 | +import BOBasePage from '@pages/BO/BOBasePage'; |
| 4 | +import {type Page} from '@playwright/test'; |
| 5 | + |
| 6 | +class BOShippingPreferences extends BOBasePage implements BOShippingPreferencesInterface { |
| 7 | + public readonly pageTitle: string; |
| 8 | + |
| 9 | + private readonly handlingForm: string; |
| 10 | + |
| 11 | + private readonly handlingChargesInput: string; |
| 12 | + |
| 13 | + private readonly saveHandlingButton: string; |
| 14 | + |
| 15 | + private readonly carrierOptionForm: string; |
| 16 | + |
| 17 | + private readonly defaultCarrierSelect: string; |
| 18 | + |
| 19 | + private readonly sortBySelect: string; |
| 20 | + |
| 21 | + private readonly orderBySelect: string; |
| 22 | + |
| 23 | + private readonly saveCarrierOptionsButton: string; |
| 24 | + |
| 25 | + constructor() { |
| 26 | + super(); |
| 27 | + |
| 28 | + this.pageTitle = 'Preferences •'; |
| 29 | + this.successfulUpdateMessage = 'Update successful'; |
| 30 | + |
| 31 | + // Handling form selectors |
| 32 | + this.handlingForm = '#handling'; |
| 33 | + this.handlingChargesInput = '#handling_shipping_handling_charges'; |
| 34 | + this.saveHandlingButton = `${this.handlingForm} button`; |
| 35 | + |
| 36 | + // Carrier options selectors |
| 37 | + this.carrierOptionForm = '#carrier-options'; |
| 38 | + this.defaultCarrierSelect = '#carrier-options_default_carrier'; |
| 39 | + this.sortBySelect = '#carrier-options_carrier_default_order_by'; |
| 40 | + this.orderBySelect = '#carrier-options_carrier_default_order_way'; |
| 41 | + this.saveCarrierOptionsButton = `${this.carrierOptionForm} button`; |
| 42 | + } |
| 43 | + |
| 44 | + /* Handling methods */ |
| 45 | + |
| 46 | + /** |
| 47 | + * Set handling charges button |
| 48 | + * @param page {Page} Browser tab |
| 49 | + * @param value {string} The handling charges value |
| 50 | + * @returns {Promise<string>} |
| 51 | + */ |
| 52 | + async setHandlingCharges(page: Page, value: string): Promise<string> { |
| 53 | + await this.setValue(page, this.handlingChargesInput, value); |
| 54 | + |
| 55 | + // Save handling form and return successful message |
| 56 | + await page.locator(this.saveHandlingButton).click(); |
| 57 | + return this.getAlertSuccessBlockParagraphContent(page); |
| 58 | + } |
| 59 | + |
| 60 | + /* Carrier options methods */ |
| 61 | + |
| 62 | + /** |
| 63 | + * Set default carrier in carrier options form |
| 64 | + * @param page {Page} Browser tab |
| 65 | + * @param carrier {FakerCarrier} List of carriers |
| 66 | + * @return {Promise<string>} |
| 67 | + */ |
| 68 | + async setDefaultCarrier(page: Page, carrier: FakerCarrier): Promise<string> { |
| 69 | + await this.selectByVisibleText( |
| 70 | + page, |
| 71 | + this.defaultCarrierSelect, |
| 72 | + `${carrier.id} - ${carrier.name} (${carrier.transitName})`, |
| 73 | + ); |
| 74 | + |
| 75 | + // Save configuration and return successful message |
| 76 | + await page.locator(this.saveCarrierOptionsButton).click(); |
| 77 | + return this.getAlertSuccessBlockParagraphContent(page); |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * Set carriers sort By 'Price' or 'Position' / order by 'Ascending' or 'descending' in carrier options form |
| 82 | + * @param page {Page} Browser tab |
| 83 | + * @param sortBy {String} Sort by 'Price' or 'Position' |
| 84 | + * @param orderBy {String} Order by 'Ascending' or 'Descending' |
| 85 | + * @returns {Promise<string>} |
| 86 | + */ |
| 87 | + async setCarrierSortOrderBy(page: Page, sortBy: string, orderBy: string = 'Ascending'): Promise<string> { |
| 88 | + await this.selectByVisibleText(page, this.sortBySelect, sortBy); |
| 89 | + await this.selectByVisibleText(page, this.orderBySelect, orderBy); |
| 90 | + |
| 91 | + // Save configuration and return successful message |
| 92 | + await page.locator(this.saveCarrierOptionsButton).click(); |
| 93 | + return this.getAlertSuccessBlockParagraphContent(page); |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +module.exports = new BOShippingPreferences(); |
0 commit comments