From b2420d50d55a1148cc8894061a4a880662386ce1 Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Wed, 15 Jan 2025 16:16:56 +0100 Subject: [PATCH] Migrate `@pages/BO/orders/creditSlips` from Core --- src/index.ts | 1 + src/interfaces/BO/orders/creditSlips.ts | 24 ++ src/pages/BO/orders/creditSlips.ts | 10 + .../develop/pages/BO/orders/creditSlips.ts | 372 ++++++++++++++++++ 4 files changed, 407 insertions(+) create mode 100644 src/interfaces/BO/orders/creditSlips.ts create mode 100644 src/pages/BO/orders/creditSlips.ts create mode 100644 src/versions/develop/pages/BO/orders/creditSlips.ts diff --git a/src/index.ts b/src/index.ts index 6bc0e3e7..d0526805 100644 --- a/src/index.ts +++ b/src/index.ts @@ -198,6 +198,7 @@ export {default as boCarriersPage} from '@pages/BO/shipping/carriers'; export {default as boCarriersCreatePage} from '@pages/BO/shipping/carriers/create'; export {default as boCountriesPage} from '@pages/BO/international/locations/countries'; export {default as boCountriesCreatePage} from '@pages/BO/international/locations/countries/create'; +export {default as boCreditSlipsPage} from '@pages/BO/orders/creditSlips'; export {default as boCustomerGroupsPage} from '@pages/BO/shopParameters/customerSettings/groups'; export {default as boCustomerGroupsCreatePage} from '@pages/BO/shopParameters/customerSettings/groups/create'; export {default as boCustomerSettingsPage} from '@pages/BO/shopParameters/customerSettings'; diff --git a/src/interfaces/BO/orders/creditSlips.ts b/src/interfaces/BO/orders/creditSlips.ts new file mode 100644 index 00000000..5c926889 --- /dev/null +++ b/src/interfaces/BO/orders/creditSlips.ts @@ -0,0 +1,24 @@ +import {BOBasePagePageInterface} from '@interfaces/BO'; +import {type Page} from '@playwright/test'; + +export interface BOCreditSlipsPageInterface extends BOBasePagePageInterface { + readonly errorMessageWhenGenerateFileByDate: string; + readonly pageTitle: string; + + changePrefix(page: Page, prefixEN: string, prefixFR?: string): Promise; + deletePrefix(page: Page): Promise; + downloadCreditSlip(page: Page, row?: number): Promise; + filterCreditSlips(page: Page, filterBy: string, value?: string): Promise; + filterCreditSlipsByDate(page: Page, dateFrom: string, dateTo: string): Promise; + generatePDFByDateAndDownload(page: Page, dateFrom?: string, dateTo?: string): Promise; + generatePDFByDateAndFail(page: Page, dateFrom?: string, dateTo?: string): Promise; + getAllRowsColumnContent(page: Page, column: string): Promise; + getNumberOfElementInGrid(page: Page): Promise; + getTextColumnFromTableCreditSlips(page: Page, row: number, column: string): Promise; + paginationNext(page: Page): Promise; + paginationPrevious(page: Page): Promise; + resetAndGetNumberOfLines(page: Page): Promise; + saveCreditSlipOptions(page: Page): Promise; + selectPaginationLimit(page: Page, number: number): Promise; + sortTable(page: Page, sortBy: string, sortDirection: string): Promise; +} diff --git a/src/pages/BO/orders/creditSlips.ts b/src/pages/BO/orders/creditSlips.ts new file mode 100644 index 00000000..513ff74f --- /dev/null +++ b/src/pages/BO/orders/creditSlips.ts @@ -0,0 +1,10 @@ +import type {BOCreditSlipsPageInterface} from '@interfaces/BO/orders/creditSlips'; + +/* eslint-disable global-require, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */ +function requirePage(): BOCreditSlipsPageInterface { + return require('@versions/develop/pages/BO/orders/creditSlips'); +} + +/* eslint-enable global-require, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */ + +export default requirePage(); diff --git a/src/versions/develop/pages/BO/orders/creditSlips.ts b/src/versions/develop/pages/BO/orders/creditSlips.ts new file mode 100644 index 00000000..7e1ed5fe --- /dev/null +++ b/src/versions/develop/pages/BO/orders/creditSlips.ts @@ -0,0 +1,372 @@ +import {type BOCreditSlipsPageInterface} from '@interfaces/BO/orders/creditSlips'; +import BOBasePage from '@pages/BO/BOBasePage'; +import {type Page} from '@playwright/test'; + +/** + * Credit slips page, contains functions that can be used on credit slips page + * @class + * @extends BOBasePage + */ +class BOCreditSlipsPage extends BOBasePage implements BOCreditSlipsPageInterface { + public readonly pageTitle: string; + + public readonly pageTitleFR: string; + + public readonly errorMessageWhenGenerateFileByDate: string; + + private readonly creditSlipGridPanel: string; + + private readonly creditSlipsGridTitle: string; + + private readonly creditSlipGridTable: string; + + private readonly filterResetButton: string; + + private readonly filterSearchButton: string; + + private readonly tableHead: string; + + private readonly sortColumnDiv: (column: string) => string; + + private readonly sortColumnSpanButton: (column: string) => string; + + private readonly paginationBlock: string; + + private readonly paginationLimitSelect: string; + + private readonly paginationLabel: string; + + private readonly paginationNextLink: string; + + private readonly paginationPreviousLink: string; + + private readonly creditSlipsFilterColumnInput: (filterBy: string) => string; + + private readonly creditSlipsTableRow: (row: number) => string; + + private readonly creditSlipsTableColumn: (row: number, column: string) => string; + + private readonly creditSlipDownloadButton: (id: number) => string; + + private readonly generateByDateForm: string; + + private readonly dateFromInput: string; + + private readonly dateToInput: string; + + private readonly generatePdfByDateButton: string; + + private readonly creditSlipOptionsForm: string; + + private readonly invoicePrefixENInput: string; + + private readonly invoicePrefixFRInput: string; + + private readonly languageDropDownButton: string; + + private readonly invoicePrefixFrenchSelect: string; + + private readonly saveCreditSlipOptionsButton: string; + + /** + * @constructs + * Setting up texts and selectors to use on credit slips page + */ + constructor() { + super(); + + this.pageTitle = `Credit slips • ${global.INSTALL.SHOP_NAME}`; + this.pageTitleFR = `Avoirs • ${global.INSTALL.SHOP_NAME}`; + this.errorMessageWhenGenerateFileByDate = 'No order slips were found for this period.'; + this.successfulUpdateMessage = 'Update successful'; + + // Credit slips page + // List of credit slips + this.creditSlipGridPanel = '#credit_slip_grid_panel'; + this.creditSlipsGridTitle = `${this.creditSlipGridPanel} h3.card-header-title`; + this.creditSlipGridTable = '#credit_slip_grid_table'; + this.filterResetButton = `${this.creditSlipGridTable} .grid-reset-button`; + this.filterSearchButton = `${this.creditSlipGridTable} .grid-search-button`; + + // Sort Credit Slip Selectors + this.tableHead = `${this.creditSlipGridTable} thead`; + this.sortColumnDiv = (column: string) => `${this.tableHead} div.ps-sortable-column[data-sort-col-name='${column}']`; + this.sortColumnSpanButton = (column: string) => `${this.sortColumnDiv(column)} span.ps-sort`; + + // Pagination selectors + this.paginationBlock = '.pagination-block'; + this.paginationLimitSelect = '#paginator_select_page_limit'; + this.paginationLabel = `${this.creditSlipGridPanel} .col-form-label`; + this.paginationNextLink = `${this.creditSlipGridPanel} #pagination_next_url`; + this.paginationPreviousLink = `${this.creditSlipGridPanel} .pagination .previous a.page-link`; + + this.creditSlipsFilterColumnInput = (filterBy: string) => `#credit_slip_${filterBy}`; + this.creditSlipsTableRow = (row: number) => `${this.creditSlipGridTable} tbody tr:nth-child(${row})`; + this.creditSlipsTableColumn = (row: number, column: string) => `${this.creditSlipsTableRow(row)} td.column-${column}`; + this.creditSlipDownloadButton = (id: number) => `${this.creditSlipGridTable} tr:nth-child(${id}) td.link-type.column-pdf`; + + // By date form + this.generateByDateForm = '#form-generate-credit-slips-by-date'; + this.dateFromInput = '#generate_pdf_by_date_from'; + this.dateToInput = '#generate_pdf_by_date_to'; + this.generatePdfByDateButton = `${this.generateByDateForm} #generate-credit-slip-by-date`; + + // Credit slip options form + this.creditSlipOptionsForm = '#form-credit-slips-options'; + this.invoicePrefixENInput = '#form_slip_prefix_1'; + this.invoicePrefixFRInput = '#form_slip_prefix_2'; + this.languageDropDownButton = '#form_slip_prefix_dropdown'; + this.invoicePrefixFrenchSelect = 'div.dropdown.show span[data-locale="fr"]'; + this.saveCreditSlipOptionsButton = `${this.creditSlipOptionsForm} #save-credit-slip-options-button`; + } + + /* + Methods + */ + /** + * Reset input filters + * @param page {Page} Browser tab + * @returns {Promise} + */ + async resetFilter(page: Page): Promise { + if (await this.elementVisible(page, this.filterResetButton, 2000)) { + await this.clickAndWaitForLoadState(page, this.filterResetButton); + await this.elementNotVisible(page, this.filterResetButton, 2000); + } + } + + /** + * Get number of elements in grid + * @param page {Page} Browser tab + * @returns {Promise} + */ + async getNumberOfElementInGrid(page: Page): Promise { + return this.getNumberFromText(page, this.creditSlipsGridTitle); + } + + /** + * Reset Filter And get number of elements in list + * @param page {Page} Browser tab + * @returns {Promise} + */ + async resetAndGetNumberOfLines(page: Page): Promise { + await this.resetFilter(page); + return this.getNumberOfElementInGrid(page); + } + + /** + * Filter credit slips + * @param page {Page} Browser tab + * @param filterBy {string} Column to filter with + * @param value {string} value to filter with + * @returns {Promise} + */ + async filterCreditSlips(page: Page, filterBy: string, value: string = ''): Promise { + await this.setValue(page, this.creditSlipsFilterColumnInput(filterBy), value.toString()); + // click on search + await this.clickAndWaitForURL(page, this.filterSearchButton); + } + + /** + * Filter credit slips by date + * @param page {Page} Browser tab + * @param dateFrom {string} Value to set on filter date from input + * @param dateTo {string} Value to set on filter date to input + * @returns {Promise} + */ + async filterCreditSlipsByDate(page: Page, dateFrom: string, dateTo: string): Promise { + await page.locator(this.creditSlipsFilterColumnInput('date_issued_from')).fill(dateFrom); + await page.locator(this.creditSlipsFilterColumnInput('date_issued_to')).fill(dateTo); + // click on search + await this.clickAndWaitForURL(page, this.filterSearchButton); + } + + /** + * get text from a column + * @param page {Page} Browser tab + * @param row {number} Credit slip row on table + * @param column {string} Column name to get + * @returns {Promise} + */ + async getTextColumnFromTableCreditSlips(page: Page, row: number, column: string): Promise { + return this.getTextContent(page, this.creditSlipsTableColumn(row, column)); + } + + /** + * Download credit slip + * @param page {Page} Browser tab + * @param row {number} Credit slip row on table + * @returns {Promise} + */ + async downloadCreditSlip(page: Page, row: number = 1): Promise { + return this.clickAndWaitForDownload(page, this.creditSlipDownloadButton(row)); + } + + /** + * Generate PDF by date and download it + * @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} + */ + async generatePDFByDateAndDownload(page: Page, dateFrom: string = '', dateTo: string = ''): Promise { + await this.setValuesForGeneratingPDFByDate(page, dateFrom, dateTo); + + return this.clickAndWaitForDownload(page, this.generatePdfByDateButton); + } + + /** + * Get message error after generate credit 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} + */ + async generatePDFByDateAndFail(page: Page, dateFrom: string = '', dateTo: string = ''): Promise { + 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} + */ + async setValuesForGeneratingPDFByDate(page: Page, dateFrom: string = '', dateTo: string = ''): Promise { + if (dateFrom) { + await this.setValue(page, this.dateFromInput, dateFrom); + } + + if (dateTo) { + await this.setValue(page, this.dateToInput, dateTo); + } + } + + /** Edit credit slip Prefix on FR and on EN + * @param page {Page} Browser tab + * @param prefixEN {string} Prefix on english language value to change + * @param prefixFR {string} Prefix on french language value to change + * @returns {Promise} + */ + async changePrefix(page: Page, prefixEN: string, prefixFR: string = prefixEN): Promise { + await this.setValue(page, this.invoicePrefixENInput, prefixEN); + await this.waitForSelectorAndClick(page, this.languageDropDownButton); + await this.waitForSelectorAndClick(page, this.invoicePrefixFrenchSelect); + await this.setValue(page, this.invoicePrefixFRInput, prefixFR); + } + + /** + * Delete prefix + * @param page {Page} Browser tab + * @returns {Promise} + */ + async deletePrefix(page: Page): Promise { + await this.clearInput(page, this.invoicePrefixENInput); + await this.waitForSelectorAndClick(page, this.languageDropDownButton); + await this.waitForSelectorAndClick(page, this.invoicePrefixFrenchSelect); + await this.clearInput(page, this.invoicePrefixFRInput); + } + + /** Save credit slip options + * @param page {Page} Browser tab + * @returns {Promise} + */ + async saveCreditSlipOptions(page: Page): Promise { + await page.locator(this.saveCreditSlipOptionsButton).click(); + return this.getAlertSuccessBlockParagraphContent(page); + } + + /* Sort functions */ + /** + * Sort table by clicking on column name + * @param page {Page} Browser tab + * @param sortBy {string} Column to sort with + * @param sortDirection {string} Sort direction asc or desc + * @returns {Promise} + */ + async sortTable(page: Page, sortBy: string, sortDirection: string): Promise { + const sortColumnDiv = `${this.sortColumnDiv(sortBy)}[data-sort-direction='${sortDirection}']`; + const sortColumnSpanButton = this.sortColumnSpanButton(sortBy); + + let i = 0; + while (await this.elementNotVisible(page, sortColumnDiv, 2000) && i < 2) { + await this.clickAndWaitForURL(page, sortColumnSpanButton); + i += 1; + } + + await this.waitForVisibleSelector(page, sortColumnDiv, 20000); + } + + /** + * Get column content in all rows + * @param page {Page} Browser tab + * @param column {string} Column name on table + * @returns {Promise>} + */ + async getAllRowsColumnContent(page: Page, column: string): Promise { + let rowContent: string; + const rowsNumber = await this.getNumberOfElementInGrid(page); + const allRowsContentTable: string[] = []; + + for (let i = 1; i <= rowsNumber; i++) { + rowContent = await this.getTextColumnFromTableCreditSlips(page, i, column); + allRowsContentTable.push(rowContent); + } + + return allRowsContentTable; + } + + /* Pagination methods */ + /** + * Get pagination label + * @param page {Page} Browser tab + * @return {Promise} + */ + getPaginationLabel(page: Page): Promise { + return this.getTextContent(page, this.paginationLabel); + } + + /** + * Select pagination limit + * @param page {Page} Browser tab + * @param number {number} Value of pagination limit to select + * @returns {Promise} + */ + async selectPaginationLimit(page: Page, number: number): Promise { + const currentUrl: string = page.url(); + + await Promise.all([ + this.selectByVisibleText(page, this.paginationLimitSelect, number), + page.waitForURL((url: URL): boolean => url.toString() !== currentUrl, {waitUntil: 'networkidle'}), + ]); + + return this.getPaginationLabel(page); + } + + /** + * Click on next + * @param page {Page} Browser tab + * @returns {Promise} + */ + async paginationNext(page: Page): Promise { + await this.clickAndWaitForURL(page, this.paginationNextLink); + + return this.getPaginationLabel(page); + } + + /** + * Click on previous + * @param page {Page} Browser tab + * @returns {Promise} + */ + async paginationPrevious(page: Page): Promise { + await this.clickAndWaitForURL(page, this.paginationPreviousLink); + + return this.getPaginationLabel(page); + } +} + +module.exports = new BOCreditSlipsPage();