|
| 1 | +import type FakerOrderStatus from '@data/faker/orderStatus'; |
| 2 | +import {type BOOrderStatusesCreatePageInterface} from '@interfaces/BO/shopParameters/orderSettings/orderStatuses/create'; |
| 3 | +import BOBasePage from '@pages/BO/BOBasePage'; |
| 4 | +import {type Page} from '@playwright/test'; |
| 5 | + |
| 6 | +/** |
| 7 | + * Add order status page, contains selectors and functions for the page |
| 8 | + * @class |
| 9 | + * @extends BOBasePage |
| 10 | + */ |
| 11 | +class BOOrderStatusesCreatePage extends BOBasePage implements BOOrderStatusesCreatePageInterface { |
| 12 | + public readonly pageTitleCreate: string; |
| 13 | + |
| 14 | + public readonly pageTitleEdit: (name: string) => string; |
| 15 | + |
| 16 | + private readonly nameInput: string; |
| 17 | + |
| 18 | + private readonly colorInput: string; |
| 19 | + |
| 20 | + private readonly logableOnCheckbox: string; |
| 21 | + |
| 22 | + private readonly invoiceOnCheckbox: string; |
| 23 | + |
| 24 | + private readonly hiddenOnCheckbox: string; |
| 25 | + |
| 26 | + private readonly sendEmailOnCheckbox: string; |
| 27 | + |
| 28 | + private readonly pdfInvoiceOnCheckbox: string; |
| 29 | + |
| 30 | + private readonly pdfDeliveryOnCheckbox: string; |
| 31 | + |
| 32 | + private readonly shippedOnCheckbox: string; |
| 33 | + |
| 34 | + private readonly paidOnCheckbox: string; |
| 35 | + |
| 36 | + private readonly deliveryOnCheckbox: string; |
| 37 | + |
| 38 | + private readonly saveButton: string; |
| 39 | + |
| 40 | + /** |
| 41 | + * @constructs |
| 42 | + * Setting up titles and selectors to use on add order status page |
| 43 | + */ |
| 44 | + constructor() { |
| 45 | + super(); |
| 46 | + |
| 47 | + this.pageTitleCreate = `New order status • ${global.INSTALL.SHOP_NAME}`; |
| 48 | + this.pageTitleEdit = (name: string) => `Editing order status ${name} • ${global.INSTALL.SHOP_NAME}`; |
| 49 | + |
| 50 | + // Form selectors |
| 51 | + this.nameInput = '#order_state_name_1'; |
| 52 | + this.colorInput = '#order_state_color'; |
| 53 | + this.logableOnCheckbox = '#order_state_loggable'; |
| 54 | + this.invoiceOnCheckbox = '#order_state_invoice'; |
| 55 | + this.hiddenOnCheckbox = '#order_state_hidden'; |
| 56 | + this.sendEmailOnCheckbox = '#order_state_send_email'; |
| 57 | + this.pdfInvoiceOnCheckbox = '#order_state_pdf_invoice'; |
| 58 | + this.pdfDeliveryOnCheckbox = '#order_state_pdf_delivery'; |
| 59 | + this.shippedOnCheckbox = '#order_state_shipped'; |
| 60 | + this.paidOnCheckbox = '#order_state_paid'; |
| 61 | + this.deliveryOnCheckbox = '#order_state_delivery'; |
| 62 | + this.saveButton = '#save-button'; |
| 63 | + } |
| 64 | + |
| 65 | + /* Methods */ |
| 66 | + |
| 67 | + /** |
| 68 | + * Fill order status form in create or edit page and save |
| 69 | + * @param page {Page} Browser tab |
| 70 | + * @param orderStatusData {FakerOrderStatus} Data to set on order status form |
| 71 | + * @return {Promise<string>} |
| 72 | + */ |
| 73 | + async setOrderStatus(page: Page, orderStatusData: FakerOrderStatus): Promise<string> { |
| 74 | + await this.setValue(page, this.nameInput, orderStatusData.name); |
| 75 | + |
| 76 | + // Set color |
| 77 | + await this.setInputValue(page, this.colorInput, orderStatusData.color); |
| 78 | + |
| 79 | + await this.setHiddenCheckboxValue(page, this.logableOnCheckbox, orderStatusData.logableOn); |
| 80 | + await this.setHiddenCheckboxValue(page, this.invoiceOnCheckbox, orderStatusData.invoiceOn); |
| 81 | + await this.setHiddenCheckboxValue(page, this.hiddenOnCheckbox, orderStatusData.hiddenOn); |
| 82 | + await this.setHiddenCheckboxValue(page, this.sendEmailOnCheckbox, orderStatusData.sendEmailOn); |
| 83 | + await this.setHiddenCheckboxValue(page, this.pdfInvoiceOnCheckbox, orderStatusData.pdfInvoiceOn); |
| 84 | + await this.setHiddenCheckboxValue(page, this.pdfDeliveryOnCheckbox, orderStatusData.pdfDeliveryOn); |
| 85 | + await this.setHiddenCheckboxValue(page, this.shippedOnCheckbox, orderStatusData.shippedOn); |
| 86 | + await this.setHiddenCheckboxValue(page, this.paidOnCheckbox, orderStatusData.paidOn); |
| 87 | + await this.setHiddenCheckboxValue(page, this.deliveryOnCheckbox, orderStatusData.deliveryOn); |
| 88 | + |
| 89 | + // Save order status |
| 90 | + await this.clickAndWaitForURL(page, this.saveButton); |
| 91 | + |
| 92 | + // Return successful message |
| 93 | + return this.getAlertSuccessBlockParagraphContent(page); |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +module.exports = new BOOrderStatusesCreatePage(); |
0 commit comments