From 409d29bb3b0a3bcd07918a721ae442bd95ccc7c6 Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Wed, 15 Jan 2025 15:19:10 +0100 Subject: [PATCH] Migrate `@pages/BO/advancedParameters/logs` from Core --- src/index.ts | 1 + src/interfaces/BO/advancedParameters/logs.ts | 22 ++ src/pages/BO/advancedParameters/logs.ts | 9 + .../pages/BO/advancedParameters/logs.ts | 331 ++++++++++++++++++ 4 files changed, 363 insertions(+) create mode 100644 src/interfaces/BO/advancedParameters/logs.ts create mode 100644 src/pages/BO/advancedParameters/logs.ts create mode 100644 src/versions/develop/pages/BO/advancedParameters/logs.ts diff --git a/src/index.ts b/src/index.ts index e7dc037b..6bc0e3e7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -220,6 +220,7 @@ export {default as boInformationPage} from '@pages/BO/advancedParameters/informa export {default as boImportPage} from '@pages/BO/advancedParameters/import'; export {default as boLanguagesPage} from '@pages/BO/international/languages'; export {default as boLanguagesCreatePage} from '@pages/BO/international/languages/create'; +export {default as boLogsPage} from '@pages/BO/advancedParameters/logs'; export {default as boLocalizationPage} from '@pages/BO/international/localization'; export {default as boLoginPage} from '@pages/BO/login'; export {default as boMaintenancePage} from '@pages/BO/shopParameters/general/maintenance'; diff --git a/src/interfaces/BO/advancedParameters/logs.ts b/src/interfaces/BO/advancedParameters/logs.ts new file mode 100644 index 00000000..7763186f --- /dev/null +++ b/src/interfaces/BO/advancedParameters/logs.ts @@ -0,0 +1,22 @@ +import {type BOBasePagePageInterface} from '@interfaces/BO'; +import {type Page} from '@playwright/test'; + +export interface BOLogsPageInterface extends BOBasePagePageInterface { + readonly pageTitle: string; + + eraseAllLogs(page: Page): Promise; + filterLogs(page: Page, filterType: string, filterBy: string, value?: string): Promise; + filterLogsByDate(page: Page, dateFrom: string, dateTo: string): Promise; + getAllRowsColumnContent(page: Page, column: string): Promise; + getNumberOfElementInGrid(page: Page): Promise; + getNumberOfRowsInGrid(page: Page): Promise; + getTextColumn(page: Page, row: number, column: string): Promise; + paginationNext(page: Page): Promise; + paginationPrevious(page: Page): Promise; + resetAndGetNumberOfLines(page: Page): Promise; + resetFilter(page: Page): Promise; + selectPaginationLimit(page: Page, number: number): Promise; + setEmail(page: Page, email: string): Promise; + setMinimumSeverityLevel(page: Page, severityLevel: string): Promise; + sortTable(page: Page, sortBy: string, sortDirection: string): Promise; +} diff --git a/src/pages/BO/advancedParameters/logs.ts b/src/pages/BO/advancedParameters/logs.ts new file mode 100644 index 00000000..728554c1 --- /dev/null +++ b/src/pages/BO/advancedParameters/logs.ts @@ -0,0 +1,9 @@ +import {type BOLogsPageInterface} from '@interfaces/BO/advancedParameters/logs'; + +/* eslint-disable global-require, @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires */ +function requirePage(): BOLogsPageInterface { + return require('@versions/develop/pages/BO/advancedParameters/logs'); +} +/* 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/advancedParameters/logs.ts b/src/versions/develop/pages/BO/advancedParameters/logs.ts new file mode 100644 index 00000000..62c2240d --- /dev/null +++ b/src/versions/develop/pages/BO/advancedParameters/logs.ts @@ -0,0 +1,331 @@ +import BOBasePage from '@pages/BO/BOBasePage'; +import {type BOLogsPageInterface} from '@interfaces/BO/advancedParameters/logs'; +import {type Page} from '@playwright/test'; + +/** + * Logs page, contains functions that can be used on the page + * @class + * @extends BOBasePage + */ +class BOLogsPage extends BOBasePage implements BOLogsPageInterface { + public readonly pageTitle: string; + + private readonly gridPanel: string; + + private readonly gridTitle: string; + + private readonly listForm: string; + + private readonly listTableRows: string; + + private readonly listTableRow: (row: number) => string; + + private readonly listTableColumn: (row: number, column: string) => string; + + private readonly gridActionButton: string; + + private readonly eraseAllButton: string; + + private readonly filterColumnInput: (filterBy: string) => string; + + private readonly filterSearchButton: string; + + private readonly filterResetButton: string; + + private readonly tableHead: string; + + private readonly sortColumnDiv: (column: string) => string; + + private readonly sortColumnSpanButton: (column: string) => string; + + private readonly paginationLimitSelect: string; + + private readonly paginationLabel: string; + + private readonly paginationNextLink: string; + + private readonly paginationPreviousLink: string; + + private readonly severityLevelSelect: string; + + private readonly sendEmailToInput: string; + + private readonly saveButton: string; + + /** + * @constructs + * Setting up texts and selectors to use on logs page + */ + constructor() { + super(); + + this.pageTitle = 'Logs •'; + + // List of logs + this.gridPanel = '#logs_grid_panel'; + this.gridTitle = `${this.gridPanel} h3.card-header-title`; + this.listForm = '#logs_grid'; + this.listTableRows = `${this.listForm} tbody tr:not(.empty_row)`; + this.listTableRow = (row: number) => `${this.listForm} tbody tr:nth-child(${row})`; + this.listTableColumn = (row: number, column: string) => `${this.listTableRow(row)} td.column-${column}`; + this.gridActionButton = '#logs-grid-actions-button'; + this.eraseAllButton = '#logs_grid_action_delete_all_email_logs'; + + // Filters + this.filterColumnInput = (filterBy: string) => `${this.listForm} #logs_${filterBy}`; + this.filterSearchButton = `${this.listForm} .grid-search-button`; + this.filterResetButton = `${this.listForm} .grid-reset-button`; + + // Sort Selectors + this.tableHead = `${this.listForm} 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.paginationLimitSelect = '#paginator_select_page_limit'; + this.paginationLabel = `${this.gridPanel} .col-form-label`; + this.paginationNextLink = `${this.gridPanel} [data-role=next-page-link]`; + this.paginationPreviousLink = `${this.gridPanel} [data-role='previous-page-link']`; + + // Logs by email selectors + this.severityLevelSelect = '#form_logs_by_email'; + this.sendEmailToInput = '#form_logs_email_receivers'; + this.saveButton = '#main-div div.card-footer button'; + } + + /* + Methods + */ + /** + * Reset input filters + * @param page {Page} Browser tab + * @returns {Promise} + */ + async resetFilter(page: Page): Promise { + if (!(await this.elementNotVisible(page, this.filterResetButton, 2000))) { + await this.clickAndWaitForURL(page, this.filterResetButton); + } + } + + /** + * Get number of elements in grid + * @param page {Page} Browser tab + * @returns {Promise} + */ + async getNumberOfElementInGrid(page: Page): Promise { + return this.getNumberFromText(page, this.gridTitle); + } + + /** + * Get number of rows currently displayed by the grid + * @param page {Page} Browser tab + * @returns {Promise} + */ + async getNumberOfRowsInGrid(page: Page): Promise { + const rows = page.locator(this.listTableRows); + + return rows.count(); + } + + /** + * 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 list of logs + * @param page {Page} Browser tab + * @param filterType {string} Input or select to choose method of filter + * @param filterBy {string} Column to filter + * @param value {string} Value to filter with + * @return {Promise} + */ + async filterLogs(page: Page, filterType: string, filterBy: string, value: string = ''): Promise { + switch (filterType) { + case 'input': + await this.setValue(page, this.filterColumnInput(filterBy), value); + break; + case 'select': + await this.selectByVisibleText( + page, + this.filterColumnInput(filterBy), + value, + ); + break; + default: + // Do nothing + } + // click on search + await this.clickAndWaitForURL(page, this.filterSearchButton); + } + + /** + * Get text from a column + * @param page {Page} Browser tab + * @param row {number} Row in table + * @param column {string} Column name to get text content + * @returns {Promise} + */ + async getTextColumn(page: Page, row: number, column: string): Promise { + return this.getTextContent(page, this.listTableColumn(row, column)); + } + + /** + * Erase all logs + * @param page {Page} Browser tab + * @returns {Promise} + */ + async eraseAllLogs(page: Page): Promise { + // Add listener to dialog to accept erase + await this.dialogListener(page); + + await page.locator(this.gridActionButton).click(); + await this.waitForSelectorAndClick(page, this.eraseAllButton); + + return this.getTextContent(page, this.alertSuccessBlockParagraph); + } + + /** + * Get content from all rows + * @param page {Page} Browser tab + * @param column {string} Column name to get all rows content + * @return {Promise>} + */ + async getAllRowsColumnContent(page: Page, column: string): Promise { + const rowsNumber = await this.getNumberOfRowsInGrid(page); + const allRowsContentTable: string[] = []; + + for (let i = 1; i <= rowsNumber; i++) { + let rowContent: string = await this.getTextColumn(page, i, column); + + if (column === 'employee' && rowContent === 'N/A') { + rowContent = ''; + } + + allRowsContentTable.push(rowContent); + } + + return allRowsContentTable; + } + + /* Sort methods */ + /** + * 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 + * @return {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: number = 0; + while (await this.elementNotVisible(page, sortColumnDiv, 2000) && i < 2) { + await page.locator(this.sortColumnDiv(sortBy)).hover(); + await this.clickAndWaitForURL(page, sortColumnSpanButton); + i += 1; + } + + await this.waitForVisibleSelector(page, sortColumnDiv, 20000); + } + + // 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); + } + + /** + * Filter logs by date + * @param page {Page} Browser tab + * @param dateFrom {string} Value of date from to set on filter input + * @param dateTo {string} Value of date to to set on filter input + * @returns {Promise} + */ + async filterLogsByDate(page: Page, dateFrom: string, dateTo: string): Promise { + await page.locator(this.filterColumnInput('date_add_from')).fill(dateFrom); + await page.locator(this.filterColumnInput('date_add_to')).fill(dateTo); + // click on search + await this.clickAndWaitForURL(page, this.filterSearchButton); + } + + // Methods for logs by email form + + /** + * Set minimum severity level + * @param page {Page} Browser tab + * @param severityLevel {string} Severity to select + * @returns {Promise} + */ + async setMinimumSeverityLevel(page: Page, severityLevel: string): Promise { + await this.selectByVisibleText(page, this.severityLevelSelect, severityLevel); + await this.waitForSelectorAndClick(page, this.saveButton); + + return this.getAlertBlockContent(page); + } + + /** + * Set email + * @param page {Page} Browser tab + * @param email {string} Email to set in the input + * @returns {Promise} + */ + async setEmail(page: Page, email: string): Promise { + await this.setValue(page, this.sendEmailToInput, email); + await this.waitForSelectorAndClick(page, this.saveButton); + + return this.getAlertBlockContent(page); + } +} + +module.exports = new BOLogsPage();