|
| 1 | +import { Page, Locator } from '@playwright/test'; |
| 2 | +import { ItemsPlanningPlanningPage, PlanningCreateUpdate } from './ItemsPlanningPlanningPage'; |
| 3 | +import { selectDateOnNewDatePicker, selectValueInNgSelector } from '../../helper-functions'; |
| 4 | + |
| 5 | +export class ItemsPlanningModalPage { |
| 6 | + private page: Page; |
| 7 | + |
| 8 | + constructor(page: Page) { |
| 9 | + this.page = page; |
| 10 | + } |
| 11 | + |
| 12 | + // Create page elements |
| 13 | + public createPlanningItemName(index: number): Locator { |
| 14 | + return this.page.locator(`#createPlanningNameTranslation_${index}`); |
| 15 | + } |
| 16 | + |
| 17 | + public get createPlanningSelector(): Locator { |
| 18 | + return this.page.locator('#createPlanningSelector'); |
| 19 | + } |
| 20 | + |
| 21 | + public get createPlanningItemDescription(): Locator { |
| 22 | + return this.page.locator('#createPlanningItemDescription'); |
| 23 | + } |
| 24 | + |
| 25 | + public get createRepeatEvery(): Locator { |
| 26 | + return this.page.locator('#createRepeatEvery'); |
| 27 | + } |
| 28 | + |
| 29 | + public async selectFolder(nameFolder: string) { |
| 30 | + await this.page.waitForTimeout(1000); |
| 31 | + const createFolder = this.createFolderName; |
| 32 | + const editFolder = this.editFolderName; |
| 33 | + if ((await createFolder.count()) > 0) { |
| 34 | + await createFolder.click(); |
| 35 | + } else { |
| 36 | + await editFolder.click(); |
| 37 | + } |
| 38 | + await this.page.waitForTimeout(1000); |
| 39 | + const treeViewport = this.page.locator('app-eform-tree-view-picker'); |
| 40 | + await treeViewport.waitFor({ state: 'visible', timeout: 20000 }); |
| 41 | + await this.page.locator('.folder-tree-name', { hasText: nameFolder }).first().click(); |
| 42 | + await treeViewport.waitFor({ state: 'hidden', timeout: 2000 }); |
| 43 | + } |
| 44 | + |
| 45 | + public get createFolderName(): Locator { |
| 46 | + return this.page.locator('#createFolderSelector'); |
| 47 | + } |
| 48 | + |
| 49 | + public get editFolderName(): Locator { |
| 50 | + return this.page.locator('#editFolderSelector'); |
| 51 | + } |
| 52 | + |
| 53 | + public get createRepeatUntil(): Locator { |
| 54 | + return this.page.locator('#createRepeatUntil'); |
| 55 | + } |
| 56 | + |
| 57 | + public get planningCreateSaveBtn(): Locator { |
| 58 | + return this.page.locator('#planningCreateSaveBtn'); |
| 59 | + } |
| 60 | + |
| 61 | + public get planningCreateCancelBtn(): Locator { |
| 62 | + return this.page.locator('#planningCreateCancelBtn'); |
| 63 | + } |
| 64 | + |
| 65 | + public get createPlanningTagsSelector(): Locator { |
| 66 | + return this.page.locator('#createPlanningTagsSelector'); |
| 67 | + } |
| 68 | + |
| 69 | + public get createStartFrom(): Locator { |
| 70 | + return this.page.locator('#createStartFrom'); |
| 71 | + } |
| 72 | + |
| 73 | + public get createItemNumber(): Locator { |
| 74 | + return this.page.locator('#createItemNumber'); |
| 75 | + } |
| 76 | + |
| 77 | + public get createItemLocationCode(): Locator { |
| 78 | + return this.page.locator('#createItemLocationCode'); |
| 79 | + } |
| 80 | + |
| 81 | + public get createItemBuildYear(): Locator { |
| 82 | + return this.page.locator('#createItemBuildYear'); |
| 83 | + } |
| 84 | + |
| 85 | + public get createItemType(): Locator { |
| 86 | + return this.page.locator('#createItemType'); |
| 87 | + } |
| 88 | + |
| 89 | + // Edit page elements |
| 90 | + public editPlanningItemName(index: number): Locator { |
| 91 | + return this.page.locator(`#editPlanningNameTranslation_${index}`); |
| 92 | + } |
| 93 | + |
| 94 | + public get editPlanningSelector(): Locator { |
| 95 | + return this.page.locator('#editPlanningSelector'); |
| 96 | + } |
| 97 | + |
| 98 | + public get editPlanningTagsSelector(): Locator { |
| 99 | + return this.page.locator('#editPlanningTagsSelector'); |
| 100 | + } |
| 101 | + |
| 102 | + public get editItemNumber(): Locator { |
| 103 | + return this.page.locator('#editItemNumber'); |
| 104 | + } |
| 105 | + |
| 106 | + public get editPlanningDescription(): Locator { |
| 107 | + return this.page.locator('#editPlanningItemDescription'); |
| 108 | + } |
| 109 | + |
| 110 | + public get editRepeatEvery(): Locator { |
| 111 | + return this.page.locator('#editRepeatEvery'); |
| 112 | + } |
| 113 | + |
| 114 | + public get planningId(): Locator { |
| 115 | + return this.page.locator('#planningId'); |
| 116 | + } |
| 117 | + |
| 118 | + public get editRepeatType(): Locator { |
| 119 | + return this.page.locator('#editRepeatType'); |
| 120 | + } |
| 121 | + |
| 122 | + public get editRepeatUntil(): Locator { |
| 123 | + return this.page.locator('#editRepeatUntil'); |
| 124 | + } |
| 125 | + |
| 126 | + public get editStartFrom(): Locator { |
| 127 | + return this.page.locator('#editStartFrom'); |
| 128 | + } |
| 129 | + |
| 130 | + public get editItemLocationCode(): Locator { |
| 131 | + return this.page.locator('#editItemLocationCode'); |
| 132 | + } |
| 133 | + |
| 134 | + public get editItemBuildYear(): Locator { |
| 135 | + return this.page.locator('#editItemBuildYear'); |
| 136 | + } |
| 137 | + |
| 138 | + public get editItemType(): Locator { |
| 139 | + return this.page.locator('#editItemType'); |
| 140 | + } |
| 141 | + |
| 142 | + public get planningEditSaveBtn(): Locator { |
| 143 | + return this.page.locator('#planningEditSaveBtn'); |
| 144 | + } |
| 145 | + |
| 146 | + public get planningEditCancelBtn(): Locator { |
| 147 | + return this.page.locator('#planningEditCancelBtn'); |
| 148 | + } |
| 149 | + |
| 150 | + // Add item elements |
| 151 | + public get addItemBtn(): Locator { |
| 152 | + return this.page.locator('#addItemBtn'); |
| 153 | + } |
| 154 | + |
| 155 | + // Delete page elements |
| 156 | + public get planningDeleteDeleteBtn(): Locator { |
| 157 | + return this.page.locator('#planningDeleteDeleteBtn'); |
| 158 | + } |
| 159 | + |
| 160 | + public get planningDeleteCancelBtn(): Locator { |
| 161 | + return this.page.locator('#planningDeleteCancelBtn'); |
| 162 | + } |
| 163 | + |
| 164 | + public get xlsxImportPlanningsInput(): Locator { |
| 165 | + return this.page.locator('#xlsxImportPlanningsInput'); |
| 166 | + } |
| 167 | + |
| 168 | + public get pushMessageEnabledCreate(): Locator { |
| 169 | + return this.page.locator('#pushMessageEnabledCreate'); |
| 170 | + } |
| 171 | + |
| 172 | + public get createDaysBeforeRedeploymentPushMessage(): Locator { |
| 173 | + return this.page.locator('#createDaysBeforeRedeploymentPushMessage'); |
| 174 | + } |
| 175 | + |
| 176 | + public get pushMessageEnabledEdit(): Locator { |
| 177 | + return this.page.locator('#pushMessageEnabledEdit'); |
| 178 | + } |
| 179 | + |
| 180 | + public get editDaysBeforeRedeploymentPushMessage(): Locator { |
| 181 | + return this.page.locator('#editDaysBeforeRedeploymentPushMessage'); |
| 182 | + } |
| 183 | + |
| 184 | + public get createRepeatType(): Locator { |
| 185 | + return this.page.locator('#createRepeatType'); |
| 186 | + } |
| 187 | + |
| 188 | + public async waitForSpinnerHide() { |
| 189 | + await this.page.locator('#spinner-animation').waitFor({ state: 'hidden', timeout: 90000 }); |
| 190 | + } |
| 191 | + |
| 192 | + public async createPlanning( |
| 193 | + planning: PlanningCreateUpdate, |
| 194 | + clickCancel = false |
| 195 | + ) { |
| 196 | + const planningPage = new ItemsPlanningPlanningPage(this.page); |
| 197 | + await planningPage.planningCreateBtn.waitFor({ state: 'visible', timeout: 90000 }); |
| 198 | + await planningPage.planningCreateBtn.click(); |
| 199 | + await this.planningCreateSaveBtn.waitFor({ state: 'visible', timeout: 20000 }); |
| 200 | + await this.page.locator('#spinner-animation').waitFor({ state: 'hidden', timeout: 90000 }); |
| 201 | + await this.page.waitForTimeout(1000); |
| 202 | + for (let i = 0; i < planning.name.length; i++) { |
| 203 | + await this.createPlanningItemName(i).waitFor({ state: 'visible', timeout: 20000 }); |
| 204 | + await this.createPlanningItemName(i).fill(planning.name[i]); |
| 205 | + } |
| 206 | + if (planning.description) { |
| 207 | + await this.createPlanningItemDescription.waitFor({ state: 'visible', timeout: 20000 }); |
| 208 | + await this.createPlanningItemDescription.fill(planning.description); |
| 209 | + } |
| 210 | + await selectValueInNgSelector(this.page, '#createPlanningSelector', planning.eFormName); |
| 211 | + if (planning.tags && planning.tags.length > 0) { |
| 212 | + for (let i = 0; i < planning.tags.length; i++) { |
| 213 | + await this.createPlanningTagsSelector.pressSequentially(planning.tags[i]); |
| 214 | + await this.page.keyboard.press('Enter'); |
| 215 | + } |
| 216 | + } |
| 217 | + if (planning.repeatEvery) { |
| 218 | + await this.page.locator('input.createRepeatEvery').fill(planning.repeatEvery); |
| 219 | + } |
| 220 | + if (planning.repeatType) { |
| 221 | + await selectValueInNgSelector(this.page, '#createRepeatType', planning.repeatType); |
| 222 | + } |
| 223 | + if (planning.startFrom) { |
| 224 | + await this.createStartFrom.click(); |
| 225 | + await selectDateOnNewDatePicker( |
| 226 | + this.page, |
| 227 | + planning.startFrom.year, |
| 228 | + planning.startFrom.month, |
| 229 | + planning.startFrom.day |
| 230 | + ); |
| 231 | + } |
| 232 | + if (planning.repeatUntil) { |
| 233 | + await this.createRepeatUntil.click(); |
| 234 | + await selectDateOnNewDatePicker( |
| 235 | + this.page, |
| 236 | + planning.repeatUntil.year, |
| 237 | + planning.repeatUntil.month, |
| 238 | + planning.repeatUntil.day |
| 239 | + ); |
| 240 | + } |
| 241 | + if (planning.number) { |
| 242 | + await this.createItemNumber.fill(planning.number); |
| 243 | + } |
| 244 | + if (planning.locationCode) { |
| 245 | + await this.createItemLocationCode.fill(planning.locationCode); |
| 246 | + } |
| 247 | + if (planning.buildYear) { |
| 248 | + await this.createItemBuildYear.fill(planning.buildYear); |
| 249 | + } |
| 250 | + if (planning.type) { |
| 251 | + await this.createItemType.fill(planning.type); |
| 252 | + } |
| 253 | + if (planning.pushMessageEnabled != null) { |
| 254 | + const status = planning.pushMessageEnabled ? 'Aktiveret' : 'Deaktiveret'; |
| 255 | + await selectValueInNgSelector(this.page, '#pushMessageEnabledCreate', status); |
| 256 | + await selectValueInNgSelector( |
| 257 | + this.page, '#createDaysBeforeRedeploymentPushMessage', planning.daysBeforeRedeploymentPushMessage.toString()); |
| 258 | + } |
| 259 | + if (planning.folderName) { |
| 260 | + await this.selectFolder(planning.folderName); |
| 261 | + } |
| 262 | + if (!clickCancel) { |
| 263 | + await this.planningCreateSaveBtn.click(); |
| 264 | + } else { |
| 265 | + await this.planningCreateCancelBtn.click(); |
| 266 | + } |
| 267 | + await planningPage.planningCreateBtn.waitFor({ state: 'visible' }); |
| 268 | + } |
| 269 | + |
| 270 | + public async addNewItem() { |
| 271 | + await this.addItemBtn.click(); |
| 272 | + } |
| 273 | +} |
| 274 | + |
| 275 | +export class PlanningItemRowObject { |
| 276 | + private page: Page; |
| 277 | + |
| 278 | + constructor(page: Page) { |
| 279 | + this.page = page; |
| 280 | + } |
| 281 | + |
| 282 | + public name: string; |
| 283 | + public description: string; |
| 284 | + public number: string; |
| 285 | + public locationCode: string; |
| 286 | + public deleteBtn: Locator; |
| 287 | + |
| 288 | + async getRow(rowNum: number): Promise<PlanningItemRowObject> { |
| 289 | + this.name = (await this.page.locator('#createItemName').nth(rowNum - 1).textContent()) || ''; |
| 290 | + this.description = (await this.page.locator('#createItemDescription').nth(rowNum - 1).textContent()) || ''; |
| 291 | + this.number = (await this.page.locator('#createItemNumber').nth(rowNum - 1).textContent()) || ''; |
| 292 | + this.locationCode = (await this.page.locator('#createItemLocationCode').nth(rowNum - 1).textContent()) || ''; |
| 293 | + this.deleteBtn = this.page.locator('#deleteItemBtn').nth(rowNum - 1); |
| 294 | + return this; |
| 295 | + } |
| 296 | + |
| 297 | + public async deleteItem() { |
| 298 | + await this.deleteBtn.click(); |
| 299 | + await this.page.waitForTimeout(500); |
| 300 | + } |
| 301 | +} |
0 commit comments