|
| 1 | +import {type BOImportPageInterface} from '@interfaces/BO/advancedParameters/import'; |
| 2 | +import BOBasePage from '@pages/BO/BOBasePage'; |
| 3 | +import {type Page} from '@playwright/test'; |
| 4 | + |
| 5 | +/** |
| 6 | + * Import page, contains functions that can be used on the page |
| 7 | + * @class |
| 8 | + * @extends BOBasePage |
| 9 | + */ |
| 10 | +class BOImportPage extends BOBasePage implements BOImportPageInterface { |
| 11 | + public readonly pageTitle: string; |
| 12 | + |
| 13 | + public readonly importModalTitle: string; |
| 14 | + |
| 15 | + public readonly importFileChangFileButton: string; |
| 16 | + |
| 17 | + public readonly chooseFromHistoryButton: string; |
| 18 | + |
| 19 | + public readonly fileHistoryTable: string; |
| 20 | + |
| 21 | + public readonly fileHistoryTableBody: string; |
| 22 | + |
| 23 | + public readonly fileHistoryTableRow: (row: number) => string; |
| 24 | + |
| 25 | + public readonly fileHistoryTableRowColumn: (row: number, column: number) => string; |
| 26 | + |
| 27 | + public readonly fileHistoryTableRowDropDownButton: (row: number) => string; |
| 28 | + |
| 29 | + public readonly fileHistoryTableRowDeleteButton: (row: number) => string; |
| 30 | + |
| 31 | + public readonly fileHistoryTableRowUseButton: (row: number) => string; |
| 32 | + |
| 33 | + public readonly importPanelTitle: string; |
| 34 | + |
| 35 | + private readonly downloadSampleFileLink: (type: string) => string; |
| 36 | + |
| 37 | + private readonly fileInputField: string; |
| 38 | + |
| 39 | + private readonly nextStepButton: string; |
| 40 | + |
| 41 | + private readonly importButton: string; |
| 42 | + |
| 43 | + private readonly confirmationModalAlert: string; |
| 44 | + |
| 45 | + private readonly importModalCloseButton: string; |
| 46 | + |
| 47 | + private readonly fileTypeSelector: string; |
| 48 | + |
| 49 | + private readonly importFileSecondStepPanelTitle: string; |
| 50 | + |
| 51 | + private readonly importProgressModal: string; |
| 52 | + |
| 53 | + private readonly progressValidateBarInfo: string; |
| 54 | + |
| 55 | + private readonly progressImportBarInfo: string; |
| 56 | + |
| 57 | + private readonly importDetailsFinished: string; |
| 58 | + |
| 59 | + private readonly importProgressModalCloseButton: string; |
| 60 | + |
| 61 | + private readonly forceAllIDNumber: (toggle: number) => string; |
| 62 | + |
| 63 | + /** |
| 64 | + * @constructs |
| 65 | + * Setting up texts and selectors to use on import page |
| 66 | + */ |
| 67 | + constructor() { |
| 68 | + super(); |
| 69 | + |
| 70 | + this.pageTitle = 'Import • '; |
| 71 | + this.importModalTitle = 'Importing your data...'; |
| 72 | + this.importPanelTitle = 'Match your data'; |
| 73 | + |
| 74 | + // Selectors |
| 75 | + this.alertSuccessBlockParagraph = `${this.alertSuccessBlock} p.alert-text.js-import-file`; |
| 76 | + this.importFileChangFileButton = 'div.js-import-file-alert button.js-change-import-file-btn'; |
| 77 | + this.chooseFromHistoryButton = '#main-div button.js-from-files-history-btn'; |
| 78 | + this.fileHistoryTable = '#fileHistoryTable'; |
| 79 | + this.fileHistoryTableBody = `${this.fileHistoryTable} tbody`; |
| 80 | + this.fileHistoryTableRow = (row: number) => `${this.fileHistoryTableBody} tr:nth-child(${row})`; |
| 81 | + this.fileHistoryTableRowColumn = (row: number, column: number) => `${this.fileHistoryTableRow(row)} td:nth-child(${column})`; |
| 82 | + this.fileHistoryTableRowDropDownButton = (row: number) => `${this.fileHistoryTableRowColumn(row, 2)}` |
| 83 | + + ' button.dropdown-toggle-split'; |
| 84 | + this.fileHistoryTableRowDeleteButton = (row: number) => `${this.fileHistoryTableRowColumn(row, 2)} a:nth-child(3)`; |
| 85 | + this.fileHistoryTableRowUseButton = (row: number) => `${this.fileHistoryTableRowColumn(row, 2)} button.js-use-file-btn`; |
| 86 | + this.downloadSampleFileLink = (type: string) => `#download-sample-${type}-file-link`; |
| 87 | + this.fileInputField = '#file'; |
| 88 | + this.nextStepButton = 'button[name=submitImportFile]'; |
| 89 | + this.importButton = '#import'; |
| 90 | + this.confirmationModalAlert = '#import_details_finished'; |
| 91 | + this.importModalCloseButton = '#import_close_button'; |
| 92 | + this.fileTypeSelector = '#entity'; |
| 93 | + this.importFileSecondStepPanelTitle = '#container-customer > h3'; |
| 94 | + this.importProgressModal = '#importProgress'; |
| 95 | + this.progressValidateBarInfo = '#validate_progressbar_done'; |
| 96 | + this.progressImportBarInfo = '#import_progressbar_done'; |
| 97 | + this.importDetailsFinished = '#import_details_finished'; |
| 98 | + this.importProgressModalCloseButton = '#import_close_button'; |
| 99 | + this.forceAllIDNumber = (toggle: number) => `#forceIDs_${toggle}`; |
| 100 | + } |
| 101 | + |
| 102 | + /* |
| 103 | + Methods |
| 104 | + */ |
| 105 | + /** |
| 106 | + * Click on simple file link to download it |
| 107 | + * @param page {Page} Browser tab |
| 108 | + * @param type {string} Type of the data to import |
| 109 | + * @return {Promise<string|null>} |
| 110 | + */ |
| 111 | + async downloadSampleFile(page: Page, type: string): Promise<string | null> { |
| 112 | + return this.clickAndWaitForDownload(page, this.downloadSampleFileLink(type)); |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * Select file type |
| 117 | + * @param page {Page} Browser tab |
| 118 | + * @param fileType {string} |
| 119 | + * @return {Promise<void>} |
| 120 | + */ |
| 121 | + async selectFileType(page: Page, fileType: string): Promise<void> { |
| 122 | + await this.selectByVisibleText(page, this.fileTypeSelector, fileType); |
| 123 | + } |
| 124 | + |
| 125 | + /** |
| 126 | + * Select the type of the file and upload the sample file |
| 127 | + * @param page {Page} Browser tab |
| 128 | + * @param fileType {string} Value of file type to select |
| 129 | + * @param filePath {string} Value of file path to set on file input |
| 130 | + * @return {Promise<string>} |
| 131 | + */ |
| 132 | + async uploadImportFile(page: Page, fileType: string, filePath: string): Promise<string> { |
| 133 | + await this.selectByVisibleText(page, this.fileTypeSelector, fileType); |
| 134 | + await this.uploadFile(page, this.fileInputField, filePath); |
| 135 | + |
| 136 | + await page.waitForTimeout(2000); |
| 137 | + return this.getAlertSuccessBlockParagraphContent(page); |
| 138 | + } |
| 139 | + |
| 140 | + /** |
| 141 | + * Click on downloaded file |
| 142 | + * @param page {Page} Browser tab |
| 143 | + * @return {Promise<void>} |
| 144 | + */ |
| 145 | + async clickOnDownloadedFile(page: Page): Promise<void> { |
| 146 | + await this.waitForSelectorAndClick(page, this.importFileChangFileButton); |
| 147 | + } |
| 148 | + |
| 149 | + /** |
| 150 | + * Is choose from history button visible |
| 151 | + * @param page {Page} Browser tab |
| 152 | + * @return {Promise<boolean>} |
| 153 | + */ |
| 154 | + async isChooseFromHistoryButtonVisible(page: Page): Promise<boolean> { |
| 155 | + return this.elementVisible(page, this.chooseFromHistoryButton, 2000); |
| 156 | + } |
| 157 | + |
| 158 | + /** |
| 159 | + * Choose from history FTP |
| 160 | + * @param page {Page} Browser tab |
| 161 | + * @return {Promise<boolean>} |
| 162 | + */ |
| 163 | + async chooseFromHistoryFTP(page: Page): Promise<boolean> { |
| 164 | + await this.waitForSelectorAndClick(page, this.chooseFromHistoryButton); |
| 165 | + |
| 166 | + return this.elementVisible(page, this.fileHistoryTable, 2000); |
| 167 | + } |
| 168 | + |
| 169 | + /** |
| 170 | + * Get imported files list |
| 171 | + * @param page {Page} Browser tab |
| 172 | + * @return {Promise<string>} |
| 173 | + */ |
| 174 | + async getImportedFilesList(page: Page): Promise<string> { |
| 175 | + return this.getTextContent(page, this.fileHistoryTableBody); |
| 176 | + } |
| 177 | + |
| 178 | + /** |
| 179 | + * Delete file |
| 180 | + * @param page {Page} Browser tab |
| 181 | + * @param row {number} Row number in the files table |
| 182 | + * @return {Promise<boolean>} |
| 183 | + */ |
| 184 | + async deleteFile(page: Page, row: number = 1): Promise<boolean> { |
| 185 | + await this.waitForSelectorAndClick(page, this.fileHistoryTableRowDropDownButton(row + 1)); |
| 186 | + await this.waitForSelectorAndClick(page, this.fileHistoryTableRowDeleteButton(row + 1)); |
| 187 | + |
| 188 | + return this.isChooseFromHistoryButtonVisible(page); |
| 189 | + } |
| 190 | + |
| 191 | + /** |
| 192 | + * Use file |
| 193 | + * @param page {Page} Browser tab |
| 194 | + * @param row {number} Row number in the files table |
| 195 | + * @return {Promise<string>} |
| 196 | + */ |
| 197 | + async useFile(page: Page, row: number = 1): Promise<string> { |
| 198 | + await this.waitForSelectorAndClick(page, this.fileHistoryTableRowUseButton(row + 1)); |
| 199 | + await this.waitForVisibleSelector(page, this.importFileChangFileButton); |
| 200 | + |
| 201 | + return this.getAlertSuccessBlockParagraphContent(page); |
| 202 | + } |
| 203 | + |
| 204 | + /** |
| 205 | + * Is force all id numbers visible |
| 206 | + * @param page {Page} Browser tab |
| 207 | + * @returns {Promise<boolean>} |
| 208 | + */ |
| 209 | + async isForceAllIDNumbersVisible(page: Page): Promise<boolean> { |
| 210 | + return this.elementVisible(page, this.forceAllIDNumber(1), 2000); |
| 211 | + } |
| 212 | + |
| 213 | + /** |
| 214 | + * Enable/Disable force all ID numbers |
| 215 | + * @param page {Page} Browser tab |
| 216 | + * @param toEnable {boolean} True if we need to enable all id numbers |
| 217 | + * @returns {Promise<void>} |
| 218 | + */ |
| 219 | + async setForceAllIDNumbers(page: Page, toEnable: boolean = true): Promise<void> { |
| 220 | + await this.setChecked(page, this.forceAllIDNumber(toEnable ? 1 : 0)); |
| 221 | + } |
| 222 | + |
| 223 | + /** |
| 224 | + * Go to 'Next step' of import |
| 225 | + * @param page {Page} Browser tab |
| 226 | + * @return {Promise<string>} |
| 227 | + */ |
| 228 | + async goToImportNextStep(page: Page): Promise<string> { |
| 229 | + await page.locator(this.nextStepButton).click(); |
| 230 | + |
| 231 | + return this.getTextContent(page, this.importFileSecondStepPanelTitle); |
| 232 | + } |
| 233 | + |
| 234 | + /** |
| 235 | + * Confirm the upload by clicking on the 'import' button |
| 236 | + * @param page {Page} Browser tab |
| 237 | + * @return {Promise<string>} |
| 238 | + */ |
| 239 | + async startFileImport(page: Page): Promise<string> { |
| 240 | + await page.locator(this.importButton).click(); |
| 241 | + |
| 242 | + return this.getTextContent(page, this.importProgressModal); |
| 243 | + } |
| 244 | + |
| 245 | + /** |
| 246 | + * Get import validation message |
| 247 | + * @param page {Page} Browser tab |
| 248 | + * @returns {Promise<string>} |
| 249 | + */ |
| 250 | + async getImportValidationMessage(page: Page): Promise<string> { |
| 251 | + await this.waitForVisibleSelector(page, `${this.progressValidateBarInfo}[style="width: 100%;"]`); |
| 252 | + await this.waitForVisibleSelector(page, `${this.progressImportBarInfo}[style="width: 100%;"]`); |
| 253 | + |
| 254 | + return this.getTextContent(page, this.importDetailsFinished); |
| 255 | + } |
| 256 | + |
| 257 | + /** |
| 258 | + * Close modal at the end of the import |
| 259 | + * @param page {Page} Browser tab |
| 260 | + * @return {Promise<boolean>} |
| 261 | + */ |
| 262 | + async closeImportModal(page: Page): Promise<boolean> { |
| 263 | + await this.waitForVisibleSelector(page, this.importProgressModalCloseButton); |
| 264 | + await this.clickAndWaitForURL(page, this.importProgressModalCloseButton); |
| 265 | + |
| 266 | + return this.elementNotVisible(page, this.importProgressModalCloseButton, 1000); |
| 267 | + } |
| 268 | +} |
| 269 | + |
| 270 | +module.exports = new BOImportPage(); |
0 commit comments