diff --git a/src/index.ts b/src/index.ts index e6c3f25e..801e6873 100644 --- a/src/index.ts +++ b/src/index.ts @@ -202,6 +202,7 @@ export {default as boCurrenciesCreatePage} from '@pages/BO/international/localiz export {default as boCurrenciesPage} from '@pages/BO/international/localization/currencies'; export {default as boCustomersPage} from '@pages/BO/customers'; export {default as boDashboardPage} from '@pages/BO/dashboard'; +export {default as boDbBackupPage} from '@pages/BO/advancedParameters/database/dbBackup'; export {default as boDesignPositionsPage} from '@pages/BO/design/positions/index'; export {default as boDesignPositionsHookModulePage} from '@pages/BO/design/positions/hookModule'; export {default as boInformationPage} from '@pages/BO/advancedParameters/information'; diff --git a/src/interfaces/BO/advancedParameters/database/dbBackup/index.ts b/src/interfaces/BO/advancedParameters/database/dbBackup/index.ts new file mode 100644 index 00000000..a365d43b --- /dev/null +++ b/src/interfaces/BO/advancedParameters/database/dbBackup/index.ts @@ -0,0 +1,16 @@ +import {BOBasePagePageInterface} from '@interfaces/BO'; +import type {Page} from '@playwright/test'; + +export interface BODbBackupPageInterface extends BOBasePagePageInterface { + readonly pageTitle: string; + readonly successfulBackupCreationMessage: string; + + createDbDbBackup(page: Page): Promise; + deleteBackup(page: Page, row: number): Promise; + deleteWithBulkActions(page: Page): Promise; + downloadDbBackup(page: Page): Promise; + getNumberOfElementInGrid(page: Page): Promise; + paginationNext(page: Page): Promise; + paginationPrevious(page: Page): Promise; + selectPaginationLimit(page: Page, number: number): Promise; +} diff --git a/src/pages/BO/advancedParameters/database/dbBackup/index.ts b/src/pages/BO/advancedParameters/database/dbBackup/index.ts new file mode 100644 index 00000000..7be2e26e --- /dev/null +++ b/src/pages/BO/advancedParameters/database/dbBackup/index.ts @@ -0,0 +1,9 @@ +import type {BODbBackupPageInterface} from '@interfaces/BO/advancedParameters/database/dbBackup'; + +/* eslint-disable global-require, @typescript-eslint/no-var-requires */ +function requirePage(): BODbBackupPageInterface { + return require('@versions/develop/pages/BO/advancedParameters/database/dbBackup'); +} +/* eslint-enable global-require, @typescript-eslint/no-var-requires */ + +export default requirePage(); diff --git a/src/versions/develop/pages/BO/advancedParameters/database/dbBackup/index.ts b/src/versions/develop/pages/BO/advancedParameters/database/dbBackup/index.ts new file mode 100644 index 00000000..c5a42a77 --- /dev/null +++ b/src/versions/develop/pages/BO/advancedParameters/database/dbBackup/index.ts @@ -0,0 +1,261 @@ +import {type BODbBackupPageInterface} from '@interfaces/BO/advancedParameters/database/dbBackup'; +import BOBasePage from '@pages/BO/BOBasePage'; +import {type Page} from '@playwright/test'; + +/** + * DB Backup page, contains functions that can be used on the page + * @class + * @extends BOBasePage + */ +class BODbBackupPage extends BOBasePage implements BODbBackupPageInterface { + public readonly pageTitle: string; + + public readonly successfulBackupCreationMessage: string; + + private readonly sqlManagerSubTabLink: string; + + private readonly newBackupButton: string; + + private readonly downloadBackupButton: string; + + private readonly gridPanel: string; + + private readonly gridTable: string; + + private readonly gridHeaderTitle: string; + + private readonly tableBody: string; + + private readonly tableRow: (row: number) => string; + + private readonly tableEmptyRow: string; + + private readonly tableColumn: (row: number, column: string) => string; + + private readonly actionsColumn: (row: number) => string; + + private readonly dropdownToggleButton: (row: number) => string; + + private readonly dropdownToggleMenu: (row: number) => string; + + private readonly deleteRowLink: (row: number) => string; + + private readonly selectAllRowsLabel: string; + + private readonly bulkActionsToggleButton: string; + + private readonly bulkActionsDeleteButton: string; + + private readonly confirmDeleteModal: string; + + private readonly confirmDeleteButton: string; + + private readonly paginationLimitSelect: string; + + private readonly paginationLabel: string; + + private readonly paginationNextLink: string; + + private readonly paginationPreviousLink: string; + + /** + * @constructs + * Setting up texts and selectors to use on db backup page + */ + constructor() { + super(); + + this.pageTitle = 'DB Backup •'; + this.successfulBackupCreationMessage = 'It appears the backup was successful, however you must download ' + + 'and carefully verify the backup file before proceeding.'; + + // Header selectors + this.sqlManagerSubTabLink = '#subtab-AdminRequestSql'; + + // New Backup for selectors + this.newBackupButton = 'button[data-role=create-backup-btn]'; + + // Download backup selectors + this.downloadBackupButton = 'a.download-file-link'; + + // DB backup grid selectors + this.gridPanel = '#backup_grid_panel'; + this.gridTable = '#backup_grid_table'; + this.gridHeaderTitle = `${this.gridPanel} div.card-header h3`; + this.tableBody = `${this.gridTable} tbody`; + this.tableRow = (row: number) => `${this.tableBody} tr:nth-child(${row})`; + this.tableEmptyRow = `${this.tableBody} tr.empty_row`; + this.tableColumn = (row: number, column: string) => `${this.tableRow(row)} td.column-${column}`; + + // Actions buttons in Row + this.actionsColumn = (row: number) => `${this.tableRow(row)} td.column-actions`; + this.dropdownToggleButton = (row: number) => `${this.actionsColumn(row)} a.dropdown-toggle`; + this.dropdownToggleMenu = (row: number) => `${this.actionsColumn(row)} div.dropdown-menu`; + this.deleteRowLink = (row: number) => `${this.dropdownToggleMenu(row)} a.grid-delete-row-link`; + + // Bulk Actions + this.selectAllRowsLabel = `${this.gridPanel} tr.column-filters .grid_bulk_action_select_all`; + this.bulkActionsToggleButton = `${this.gridPanel} button.js-bulk-actions-btn`; + this.bulkActionsDeleteButton = `${this.gridPanel} #backup_grid_bulk_action_delete_selection`; + this.confirmDeleteModal = '#backup-grid-confirm-modal'; + this.confirmDeleteButton = `${this.confirmDeleteModal} button.btn-confirm-submit`; + + // 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]`; + } + + /* Header methods */ + /** + * Go to db Backup page + * @param page {Page} Browser tab + * @returns {Promise} + */ + async goToSqlManagerPage(page: Page): Promise { + await this.clickAndWaitForURL(page, this.sqlManagerSubTabLink); + } + + /* Form and grid methods */ + /** + * Get number of backups + * @param page {Page} Browser tab + * @returns {Promise} + */ + async getNumberOfElementInGrid(page: Page): Promise { + return this.getNumberFromText(page, this.gridHeaderTitle); + } + + /** + * Create new db backup + * @param page {Page} Browser tab + * @returns {Promise} + */ + async createDbDbBackup(page: Page): Promise { + await Promise.all([ + page.locator(this.newBackupButton).click(), + this.waitForVisibleSelector(page, this.tableRow(1)), + this.waitForVisibleSelector(page, this.downloadBackupButton), + ]); + + return this.getAlertSuccessBlockParagraphContent(page); + } + + /** + * Download backup + * @param page {Page} Browser tab + * @return {Promise} + */ + async downloadDbBackup(page: Page): Promise { + return this.clickAndWaitForDownload(page, this.downloadBackupButton); + } + + /** + * Delete backup + * @param page {Page} Browser tab + * @param row {number} Row on table + * @returns {Promise} + */ + async deleteBackup(page: Page, row: number): Promise { + await Promise.all([ + page.locator(this.dropdownToggleButton(row)).click(), + this.waitForVisibleSelector(page, `${this.dropdownToggleButton(row)}[aria-expanded='true']`), + ]); + // Click on delete and wait for modal + await Promise.all([ + page.locator(this.deleteRowLink(row)).click(), + this.waitForVisibleSelector(page, `${this.confirmDeleteModal}.show`), + ]); + await this.confirmDeleteDbBackups(page); + + return this.getAlertSuccessBlockParagraphContent(page); + } + + /** + * Confirm delete with in modal + * @param page {Page} Browser tab + * @return {Promise} + */ + async confirmDeleteDbBackups(page: Page): Promise { + await this.clickAndWaitForURL(page, this.confirmDeleteButton); + } + + /** + * Delete with bulk actions + * @param page {Page} Browser tab + * @returns {Promise} + */ + async deleteWithBulkActions(page: Page): Promise { + // Click on Select All + await Promise.all([ + page.locator(this.selectAllRowsLabel).evaluate((el: HTMLElement) => el.click()), + this.waitForVisibleSelector(page, `${this.bulkActionsToggleButton}:not([disabled])`), + ]); + // Click on Button Bulk actions + await Promise.all([ + page.locator(this.bulkActionsToggleButton).click(), + this.waitForVisibleSelector(page, `${this.bulkActionsToggleButton}[aria-expanded='true']`), + ]); + + // Click on delete and wait for modal + await Promise.all([ + page.locator(this.bulkActionsDeleteButton).click(), + this.waitForVisibleSelector(page, `${this.confirmDeleteModal}.show`), + ]); + + await this.confirmDeleteDbBackups(page); + + return this.getAlertSuccessBlockParagraphContent(page); + } + + /* Pagination methods */ + /** + * Get pagination label + * @param page {Page} Browser tab + * @return {Promise} + */ + async getPaginationLabel(page: Page): Promise { + return this.getTextContent(page, this.paginationLabel); + } + + /** + * Select pagination limit + * @param page {Page} Browser tab + * @param number {number} Pagination limit number 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 BODbBackupPage();