Skip to content

Commit

Permalink
Merge pull request #325 from Progi1984/boDeliverySlipsPage
Browse files Browse the repository at this point in the history
Migrate `@pages/BO/orders/deliverySlips` from Core
  • Loading branch information
Progi1984 authored Jan 16, 2025
2 parents 5722275 + 4ebf1bd commit 5db5222
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export {default as boCustomersPage} from '@pages/BO/customers';
export {default as boCustomersCreatePage} from '@pages/BO/customers/create';
export {default as boDashboardPage} from '@pages/BO/dashboard';
export {default as boDbBackupPage} from '@pages/BO/advancedParameters/database/dbBackup';
export {default as boDeliverySlipsPage} from '@pages/BO/orders/deliverySlips';
export {default as boDesignEmailThemesPage} from '@pages/BO/design/emailThemes';
export {default as boDesignEmailThemesPreviewPage} from '@pages/BO/design/emailThemes/preview';
export {default as boDesignLinkListPage} from '@pages/BO/design/linkList';
Expand Down
14 changes: 14 additions & 0 deletions src/interfaces/BO/orders/deliverySlips.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {BOBasePagePageInterface} from '@interfaces/BO';
import {type Page} from '@playwright/test';

export interface BODeliverySlipsPageInterface extends BOBasePagePageInterface {
readonly errorMessageWhenGenerateFileByDate: string;
readonly pageTitle: string;

changeNumber(page: Page, number: number): Promise<void>;
changePrefix(page: Page, prefix: string): Promise<void>;
generatePDFByDateAndDownload(page: Page, dateFrom?: string, dateTo?: string): Promise<string | null>;
generatePDFByDateAndFail(page: Page, dateFrom?: string, dateTo?: string): Promise<string>;
saveDeliverySlipOptions(page: Page): Promise<string>;
setEnableProductImage(page: Page, enable?: boolean): Promise<void>
}
10 changes: 10 additions & 0 deletions src/pages/BO/orders/deliverySlips.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type {BODeliverySlipsPageInterface} from '@interfaces/BO/orders/deliverySlips';

/* eslint-disable global-require, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */
function requirePage(): BODeliverySlipsPageInterface {
return require('@versions/develop/pages/BO/orders/deliverySlips');
}

/* eslint-enable global-require, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */

export default requirePage();
144 changes: 144 additions & 0 deletions src/versions/develop/pages/BO/orders/deliverySlips.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import {type BODeliverySlipsPageInterface} from '@interfaces/BO/orders/deliverySlips';
import BOBasePage from '@pages/BO/BOBasePage';
import {type Page} from '@playwright/test';

/**
* Delivery slips page, contains functions that can be used on delivery slips page
* @class
* @extends BOBasePage
*/
class BODeliverySlipsPage extends BOBasePage implements BODeliverySlipsPageInterface {
public readonly pageTitle: string;

public readonly errorMessageWhenGenerateFileByDate: string;

private readonly generateByDateForm: string;

private readonly dateFromInput: string;

private readonly dateToInput: string;

private readonly generatePdfByDateButton: string;

private readonly deliverySlipForm: string;

private readonly deliveryPrefixInput: string;

private readonly deliveryNumberInput: string;

private readonly deliveryProductImageStatusToggleInput: (toggle: number) => string;

private readonly saveDeliverySlipOptionsButton: string;

/**
* @constructs
* Setting up texts and selectors to use on delivery slips page
*/
constructor() {
super();

this.pageTitle = `Delivery slips • ${global.INSTALL.SHOP_NAME}`;
this.errorMessageWhenGenerateFileByDate = 'No delivery slip was found for this period.';
this.successfulUpdateMessage = 'Update successful';

// Delivery slips page
// By date form
this.generateByDateForm = '#form-delivery-slips-print-pdf';
this.dateFromInput = '#slip_pdf_form_date_from';
this.dateToInput = '#slip_pdf_form_date_to';
this.generatePdfByDateButton = `${this.generateByDateForm} #generate-delivery-slip-by-date`;

// Delivery slip options form
this.deliverySlipForm = '#form-delivery-slips-options';
this.deliveryPrefixInput = '#form_prefix_1';
this.deliveryNumberInput = '#form_number';
this.deliveryProductImageStatusToggleInput = (toggle: number) => `#form_enable_product_image_${toggle}`;
this.saveDeliverySlipOptionsButton = `${this.deliverySlipForm} #save-delivery-slip-options-button`;
}

/*
Methods
*/

/**
* Generate PDF by date and download
* @param page {Page} Browser tab
* @param dateFrom {string} Value to set on date from input
* @param dateTo {string} Value to set on date to input
* @returns {Promise<string>}
*/
async generatePDFByDateAndDownload(page: Page, dateFrom: string = '', dateTo: string = ''): Promise<string | null> {
await this.setValuesForGeneratingPDFByDate(page, dateFrom, dateTo);

return this.clickAndWaitForDownload(page, this.generatePdfByDateButton);
}

/**
* Get message error after generate delivery slip fail
* @param page {Page} Browser tab
* @param dateFrom {string} Value to set on date from input
* @param dateTo {string} Value to set on date to input
* @returns {Promise<string>}
*/
async generatePDFByDateAndFail(page: Page, dateFrom: string = '', dateTo: string = ''): Promise<string> {
await this.setValuesForGeneratingPDFByDate(page, dateFrom, dateTo);
await page.locator(this.generatePdfByDateButton).click();
return this.getAlertDangerBlockParagraphContent(page);
}

/**
* Set values to generate pdf by date
* @param page {Page} Browser tab
* @param dateFrom {string} Value to set on date from input
* @param dateTo {string} Value to set on date to input
* @returns {Promise<void>}
*/
async setValuesForGeneratingPDFByDate(page: Page, dateFrom: string = '', dateTo: string = ''): Promise<void> {
if (dateFrom) {
await this.setValue(page, this.dateFromInput, dateFrom);
}

if (dateTo) {
await this.setValue(page, this.dateToInput, dateTo);
}
}

/** Edit delivery slip Prefix
* @param page {Page} Browser tab
* @param prefix {string} Prefix value to set
* @returns {Promise<void>}
*/
async changePrefix(page: Page, prefix: string): Promise<void> {
await this.setValue(page, this.deliveryPrefixInput, prefix);
}

/** Edit delivery slip number
* @param page {Page} Browser tab
* @param number {number} Number value to change
* @returns {Promise<void>}
*/
async changeNumber(page: Page, number: number): Promise<void> {
await this.setValue(page, this.deliveryNumberInput, number);
}

/**
* Enable disable product image
* @param page {Page} Browser tab
* @param enable {boolean} True if we need to enable product image
* @returns {Promise<void>}
*/
async setEnableProductImage(page: Page, enable: boolean = true): Promise<void> {
await this.setChecked(page, this.deliveryProductImageStatusToggleInput(enable ? 1 : 0));
}

/** Save delivery slip options
* @param page {Page} Browser tab
* @returns {Promise<string>}
*/
async saveDeliverySlipOptions(page: Page): Promise<string> {
await page.locator(this.saveDeliverySlipOptionsButton).click();
return this.getAlertSuccessBlockParagraphContent(page);
}
}

module.exports = new BODeliverySlipsPage();

0 comments on commit 5db5222

Please sign in to comment.