|
| 1 | +import { expect } from "@playwright/test"; |
| 2 | + |
| 3 | + |
| 4 | +async function checkDataStructure(page, hasTitle, hasDescription, hasPrimaryKey, hasOptionalValue, hasName, hasTitleDescription, hasDataType, hasUnit) { |
| 5 | + await page.waitForLoadState('load'); |
| 6 | + // Wait for 500 milliseconds |
| 7 | + await page.waitForTimeout(500); |
| 8 | + // Click on the create button |
| 9 | + await page.locator('#create').click(); |
| 10 | + // Wait for 1000 milliseconds |
| 11 | + await page.waitForTimeout(1000); |
| 12 | + // Click on green create button |
| 13 | + await page.click('button.btn.variant-filled-primary.grow'); |
| 14 | + await page.waitForLoadState('load'); |
| 15 | + // Wait for 500 milliseconds |
| 16 | + await page.waitForTimeout(500); |
| 17 | + await page.click('button[title="add"]'); |
| 18 | + // Wait for 500 milliseconds |
| 19 | + await page.waitForTimeout(500); |
| 20 | + |
| 21 | + |
| 22 | + if (hasTitle) { |
| 23 | + // Fill in the title input |
| 24 | + await page.locator('input[id=title]').fill(hasTitle); |
| 25 | + } |
| 26 | + if (hasDescription) { |
| 27 | + // Fill in the title description input |
| 28 | + await page.locator('textarea.textarea.variant-form-material.input-success').fill('Test data structure'); |
| 29 | + } |
| 30 | + if (hasPrimaryKey) { |
| 31 | + // Click on make a part of primary key |
| 32 | + await page.click('text=Mark a part of primary key'); |
| 33 | + } |
| 34 | + |
| 35 | + if (hasOptionalValue) { |
| 36 | + // Click on optional value |
| 37 | + await page.click('text=Value can be optional'); |
| 38 | + } |
| 39 | + |
| 40 | + if (hasName) { |
| 41 | + // Fill in the name input |
| 42 | + await page.locator('input[id=name]').fill(hasName); |
| 43 | + } |
| 44 | + |
| 45 | + if (hasTitleDescription) { |
| 46 | + // Fill in the title description textarea |
| 47 | + await page.locator('textarea.textarea.variant-form-material.input-error').fill('Test data structure'); |
| 48 | + } |
| 49 | + |
| 50 | + if (hasDataType) { |
| 51 | + // Click the on data type dropdown |
| 52 | + await page.click('div.value-container.svelte-u3g5ju > input.svelte-u3g5ju'); |
| 53 | + await page.waitForTimeout(500); |
| 54 | + const dataType = await page.waitForSelector('.list-item .item:text("bool")', { visible: true, enabled: true }); |
| 55 | + await dataType.click() |
| 56 | + } |
| 57 | + |
| 58 | + if (hasUnit) { |
| 59 | + // Click the on unit dropdown |
| 60 | + await page.click('div.value-container.svelte-u3g5ju > input#unit'); |
| 61 | + await page.waitForTimeout(500); |
| 62 | + const unit = await page.waitForSelector('.list-item .item:text("none")', { visible: true, enabled: true }); |
| 63 | + await unit.click() |
| 64 | + await page.waitForTimeout(500); |
| 65 | + } |
| 66 | + |
| 67 | + // Handling different conditions based on parameters |
| 68 | + if (hasTitle && hasDescription && !hasPrimaryKey && !hasOptionalValue && !hasName && !hasTitleDescription && !hasDataType && !hasUnit) { |
| 69 | + await page.waitForLoadState('load'); |
| 70 | + await page.waitForTimeout(1500); |
| 71 | + // Check if the save button is disabled and reload the page |
| 72 | + const saveButton = page.locator('button#save'); |
| 73 | + await expect(saveButton).toBeDisabled(); |
| 74 | + |
| 75 | + } |
| 76 | + |
| 77 | + if (hasTitle && hasDescription && hasPrimaryKey && !hasOptionalValue && !hasName && !hasTitleDescription && !hasDataType && !hasUnit) { |
| 78 | + await page.waitForLoadState('load'); |
| 79 | + await page.waitForTimeout(1500); |
| 80 | + // Check if the save button is disabled and reload the page |
| 81 | + const saveButton = page.locator('button#save'); |
| 82 | + await expect(saveButton).toBeDisabled(); |
| 83 | + |
| 84 | + } |
| 85 | + else if (hasTitle && hasDescription && !hasPrimaryKey && hasOptionalValue && !hasName && !hasTitleDescription && !hasDataType && !hasUnit) { |
| 86 | + await page.waitForLoadState('load'); |
| 87 | + await page.waitForTimeout(1500); |
| 88 | + // Check if the save button is disabled and reload the page |
| 89 | + const saveButton = page.locator('button#save'); |
| 90 | + await expect(saveButton).toBeDisabled(); |
| 91 | + |
| 92 | + } |
| 93 | + else if (hasTitle && hasDescription && hasPrimaryKey && !hasOptionalValue && hasName && hasTitleDescription && !hasDataType && !hasUnit) { |
| 94 | + await page.waitForLoadState('load'); |
| 95 | + await page.waitForTimeout(1500); |
| 96 | + // Check if the save button is disabled and reload the page |
| 97 | + const saveButton = page.locator('button#save'); |
| 98 | + await expect(saveButton).toBeDisabled(); |
| 99 | + |
| 100 | + } |
| 101 | + else if (hasTitle && hasDescription && !hasPrimaryKey && hasOptionalValue && hasName && hasTitleDescription && !hasDataType && !hasUnit) { |
| 102 | + await page.waitForLoadState('load'); |
| 103 | + await page.waitForTimeout(1500); |
| 104 | + // Check if the save button is disabled and reload the page |
| 105 | + const saveButton = page.locator('button#save'); |
| 106 | + await expect(saveButton).toBeDisabled(); |
| 107 | + |
| 108 | + } |
| 109 | + |
| 110 | + else if (hasTitle && hasDescription && hasPrimaryKey && hasOptionalValue && hasName && hasTitleDescription && hasDataType && !hasUnit) { |
| 111 | + await page.waitForLoadState('load'); |
| 112 | + await page.waitForTimeout(1500); |
| 113 | + // Check if the save button is disabled and reload the page |
| 114 | + const saveButton = page.locator('button#save'); |
| 115 | + await expect(saveButton).toBeDisabled(); |
| 116 | + |
| 117 | + } |
| 118 | + else if (hasTitle && hasDescription && hasPrimaryKey && hasOptionalValue && hasName && hasTitleDescription && !hasDataType && hasUnit) { |
| 119 | + await page.waitForLoadState('load'); |
| 120 | + await page.waitForTimeout(1500); |
| 121 | + // Check if the save button is disabled and reload the page |
| 122 | + const saveButton = page.locator('button#save'); |
| 123 | + await expect(saveButton).toBeDisabled(); |
| 124 | + |
| 125 | + } |
| 126 | +} |
| 127 | + |
| 128 | +async function createDataStructure(page, titleName) { |
| 129 | + |
| 130 | + await page.waitForLoadState('load'); |
| 131 | + // Wait for 500 milliseconds |
| 132 | + await page.waitForTimeout(500); |
| 133 | + // Click on the create button |
| 134 | + await page.locator('#create').click(); |
| 135 | + // Wait for 1000 milliseconds |
| 136 | + await page.waitForTimeout(1000); |
| 137 | + // Click on green create button |
| 138 | + await page.click('button.btn.variant-filled-primary.grow'); |
| 139 | + await page.waitForLoadState('load'); |
| 140 | + // Wait for 500 milliseconds |
| 141 | + await page.waitForTimeout(500); |
| 142 | + |
| 143 | + // Fill in the title input |
| 144 | + await page.locator('input[id=title]').fill(titleName); |
| 145 | + |
| 146 | + // Fill in the title description textarea |
| 147 | + await page.locator('textarea[id=description]').fill('Test data structure'); |
| 148 | + |
| 149 | + await page.click('button[title="add"]'); |
| 150 | + // Wait for 500 milliseconds |
| 151 | + await page.waitForTimeout(500); |
| 152 | + |
| 153 | + // Click on make a part of primary key |
| 154 | + await page.click('text=Mark a part of primary key'); |
| 155 | + |
| 156 | + // Fill in the name input |
| 157 | + await page.locator('input[id=name]').fill(titleName); |
| 158 | + |
| 159 | + // Fill in the description textarea |
| 160 | + await page.locator('textarea.textarea.variant-form-material.input-error').fill('Test data structure'); |
| 161 | + |
| 162 | + // Click the on data type dropdown |
| 163 | + await page.click('div.value-container.svelte-u3g5ju > input.svelte-u3g5ju'); |
| 164 | + await page.waitForTimeout(500); |
| 165 | + const dataType = await page.waitForSelector('.list-item .item:text("bool")', { visible: true, enabled: true }); |
| 166 | + await dataType.click() |
| 167 | + |
| 168 | + // Click the on unit dropdown |
| 169 | + await page.click('div.value-container.svelte-u3g5ju > input#unit'); |
| 170 | + await page.waitForTimeout(500); |
| 171 | + const unit = await page.waitForSelector('.list-item .item:text("none")', { visible: true, enabled: true }); |
| 172 | + await unit.click() |
| 173 | + await page.waitForTimeout(500); |
| 174 | + |
| 175 | + // Click on the dropdown |
| 176 | + await page.locator('#constraints').click(); |
| 177 | + await page.waitForTimeout(500); |
| 178 | + const constraint = await page.waitForSelector('.list-item .item:text("Test Constraint")', { visible: true, timeout: 500 }); |
| 179 | + await constraint.click(); |
| 180 | + |
| 181 | + // Wait for 500 milliseconds |
| 182 | + await page.waitForTimeout(500); |
| 183 | + |
| 184 | + // Click on save button |
| 185 | + await page.click('#save'); |
| 186 | +} |
| 187 | + |
| 188 | +async function findDataStructure(page, dataStructure) { |
| 189 | + // Search for the data structure |
| 190 | + await page.locator('#datastructure-search').fill(dataStructure); |
| 191 | + |
| 192 | + // Click on the Search button |
| 193 | + await page.click('#datastructure-searchSubmit'); |
| 194 | + |
| 195 | + // Get the row |
| 196 | + const row = page.locator('[id^=datastructure-row-]'); |
| 197 | + await expect(row).toHaveCount(1); |
| 198 | + |
| 199 | + // Get the index of the data structure |
| 200 | + const id = await row.getAttribute('id'); |
| 201 | + const index = id.split('-')[2]; |
| 202 | + |
| 203 | + // Check the values |
| 204 | + await expect(page.locator(`#datastructure-title-${index}`)).toHaveText(dataStructure); |
| 205 | + await expect(page.locator(`#datastructure-description-${index}`)).toHaveText( |
| 206 | + 'Test data structure' |
| 207 | + ); |
| 208 | +} |
| 209 | + |
| 210 | +async function deleteDataStructure(page) { |
| 211 | + // Wait for 500 milliseconds |
| 212 | + await page.waitForTimeout(500); |
| 213 | + await page.locator('[id^=delete-]').click(); |
| 214 | + |
| 215 | + // Wait until the modal appears |
| 216 | + await page.waitForSelector('.modal'); |
| 217 | + |
| 218 | + // Check the modal title and body text |
| 219 | + await expect(page.locator('.modal-header')).toHaveText('Delete Structure'); |
| 220 | + await expect(page.locator('.modal-body')).toContainText(`Are you sure you wish to delete structure with id`); |
| 221 | + |
| 222 | + // Click the confirm button in the modal footer |
| 223 | + await page.locator('.modal-footer button.variant-filled').click(); |
| 224 | + await page.waitForLoadState('load'); |
| 225 | + |
| 226 | +} |
| 227 | +async function checkAndCloseToast(page) { |
| 228 | + await page.waitForLoadState('load'); |
| 229 | + // Wait for 500 milliseconds |
| 230 | + await page.waitForTimeout(500); |
| 231 | + // Wait until the toast appears |
| 232 | + await page.waitForSelector('.toast[data-testid=toast] .text-base'); |
| 233 | + |
| 234 | + // Check the toast message |
| 235 | + const toast = await page.locator('.toast[data-testid=toast]'); |
| 236 | + await expect(await toast.locator('.text-base')).toHaveText(`Structure deleted.`); |
| 237 | + |
| 238 | + // Close the toast |
| 239 | + await toast.locator('button').click(); |
| 240 | +} |
| 241 | + |
| 242 | +async function checkConstraint(page) { |
| 243 | + await page.waitForLoadState('load'); |
| 244 | + // Wait for 500 milliseconds |
| 245 | + await page.waitForTimeout(500); |
| 246 | + // Click on the create button |
| 247 | + await page.locator('#create').click(); |
| 248 | + // Wait for 1000 milliseconds |
| 249 | + await page.waitForTimeout(1000); |
| 250 | + // Click on green create button |
| 251 | + await page.click('button.btn.variant-filled-primary.grow'); |
| 252 | + await page.waitForLoadState('load'); |
| 253 | + // Wait for 500 milliseconds |
| 254 | + await page.waitForTimeout(500); |
| 255 | + |
| 256 | + await page.click('button[title="add"]'); |
| 257 | + // Wait for 500 milliseconds |
| 258 | + await page.waitForTimeout(500); |
| 259 | + |
| 260 | + try { |
| 261 | + // Click on the dropdown |
| 262 | + await page.locator('#constraints').click(); |
| 263 | + await page.waitForTimeout(500); |
| 264 | + |
| 265 | + let option; |
| 266 | + try { |
| 267 | + // Check if the "TestConstraint" exists |
| 268 | + await page.waitForSelector('.list-item .item:text("Test Constraint")', { visible: true, timeout: 500 }); |
| 269 | + |
| 270 | + |
| 271 | + } catch (error) { |
| 272 | + |
| 273 | + // Perform actions if the element is not found |
| 274 | + // Click on the SVG element |
| 275 | + await page.waitForSelector('div.hidden:nth-child(4)', { visible: true }); |
| 276 | + |
| 277 | + // Click on the div element |
| 278 | + await page.click('div.hidden:nth-child(4)'); |
| 279 | + await page.waitForSelector('text="Manage Constraints"', { visible: true }); |
| 280 | + |
| 281 | + // Click on the div element |
| 282 | + await page.click('text="Manage Constraints"'); |
| 283 | + await page.waitForLoadState('load'); |
| 284 | + await page.waitForTimeout(1000); |
| 285 | + await page.locator('#create').click(); |
| 286 | + await page.waitForTimeout(1000); |
| 287 | + await page.locator('input[id=name]').fill("Test Constraint"); |
| 288 | + await page.locator('textarea[id=description]').fill('Test constraint'); |
| 289 | + await page.selectOption('#constraintTypes', 'Domain'); |
| 290 | + await page.click('div.cm-activeLine.cm-line'); |
| 291 | + await page.waitForTimeout(1000); |
| 292 | + await page.keyboard.type('Hello Testing Domain'); |
| 293 | + await page.waitForTimeout(1000); |
| 294 | + await page.click('#save'); |
| 295 | + await page.waitForSelector('.toast[data-testid=toast] .text-base'); |
| 296 | + const toast = await page.locator('.toast[data-testid=toast]'); |
| 297 | + await expect(await toast.locator('.text-base')).toHaveText(`Constraint "Test Constraint" saved.`); |
| 298 | + await toast.locator('button').click(); |
| 299 | + console.log("Element 'Test Constraint' is added."); |
| 300 | + } |
| 301 | + |
| 302 | + } catch (error) { |
| 303 | + console.log("An error occurred:", error); |
| 304 | + } |
| 305 | +} |
| 306 | + |
| 307 | +async function navDataStructure(page) { |
| 308 | + |
| 309 | + // Click on the div element |
| 310 | + await page.click('div.hidden:nth-child(4)'); |
| 311 | + await page.waitForSelector('text="Manage Data Structures"', { visible: true }); |
| 312 | + |
| 313 | + // Click on the div element |
| 314 | + await page.click('text="Manage Data Structures"'); |
| 315 | +} |
| 316 | + |
| 317 | +async function editDataStructure(page) { |
| 318 | + |
| 319 | + // Wait for 500 milliseconds |
| 320 | + await page.waitForTimeout(500); |
| 321 | + await page.locator('[id^=edit-]').click(); |
| 322 | + await page.waitForLoadState('load'); |
| 323 | + await page.waitForTimeout(500); |
| 324 | + |
| 325 | + // Fill in the title description textarea |
| 326 | + await page.locator('textarea[id=description]').fill('Edited test data structure'); |
| 327 | + |
| 328 | + // Wait for 500 milliseconds |
| 329 | + await page.waitForTimeout(500); |
| 330 | + |
| 331 | + // Click on make a part of primary key |
| 332 | + await page.click('text=Value can be optional'); |
| 333 | + |
| 334 | + // Click the on data type dropdown |
| 335 | + await page.click('div.value-container.svelte-u3g5ju > input.svelte-u3g5ju'); |
| 336 | + await page.waitForTimeout(500); |
| 337 | + const dataType = await page.waitForSelector('.list-item .item:text("number")', { visible: true, enabled: true }); |
| 338 | + await dataType.click() |
| 339 | + |
| 340 | + // Click the on unit dropdown |
| 341 | + await page.click('div.value-container.svelte-u3g5ju > input#unit'); |
| 342 | + await page.waitForTimeout(500); |
| 343 | + const unit = await page.waitForSelector('.list-item .item:text("cm")', { visible: true, enabled: true }); |
| 344 | + await unit.click() |
| 345 | + await page.waitForTimeout(500); |
| 346 | + |
| 347 | + // Click on save button |
| 348 | + await page.locator('button[title="save"]').click(); |
| 349 | + |
| 350 | +} |
| 351 | + |
| 352 | +async function findEditedDataStructure(page, dataStructure) { |
| 353 | + await page.waitForLoadState('load'); |
| 354 | + // Wait for 500 milliseconds |
| 355 | + await page.waitForTimeout(500); |
| 356 | + // Search for the data structure |
| 357 | + await page.locator('#datastructure-search').fill(dataStructure); |
| 358 | + |
| 359 | + // Click on the Search button |
| 360 | + await page.click('#datastructure-searchSubmit'); |
| 361 | + |
| 362 | + // Get the row |
| 363 | + const row = page.locator('[id^=datastructure-row-]'); |
| 364 | + await expect(row).toHaveCount(1); |
| 365 | + |
| 366 | + // Get the index of the data structure |
| 367 | + const id = await row.getAttribute('id'); |
| 368 | + const index = id.split('-')[2]; |
| 369 | + |
| 370 | + // Check the values |
| 371 | + await expect(page.locator(`#datastructure-title-${index}`)).toHaveText(dataStructure); |
| 372 | + await expect(page.locator(`#datastructure-description-${index}`)).toHaveText( |
| 373 | + 'Edited test data structure' |
| 374 | + ); |
| 375 | +} |
| 376 | + |
| 377 | +module.exports = { |
| 378 | + |
| 379 | + createDataStructure, |
| 380 | + findDataStructure, |
| 381 | + deleteDataStructure, |
| 382 | + checkAndCloseToast, |
| 383 | + checkConstraint, |
| 384 | + navDataStructure, |
| 385 | + editDataStructure, |
| 386 | + findEditedDataStructure, |
| 387 | + checkDataStructure |
| 388 | + |
| 389 | +}; |
0 commit comments