|
| 1 | +import { expect } from "@playwright/test"; |
| 2 | + |
| 3 | +async function checkEntityTemplate(page, hasEntityName, hasEntityType, hasDescription, hasMetaData, hasRequiredField, hasDataSet, hasFileType) { |
| 4 | + |
| 5 | + // Open the form |
| 6 | + await page.locator('button[title=create]').click(); |
| 7 | + // Wait for the requests to finish |
| 8 | + await page.waitForLoadState('domcontentloaded'); |
| 9 | + |
| 10 | + if (hasEntityName) { |
| 11 | + await page.waitForTimeout(250); |
| 12 | + // Fill in the entity name |
| 13 | + await page.locator('#name').fill(hasEntityName); |
| 14 | + } |
| 15 | + |
| 16 | + if (hasEntityType) { |
| 17 | + await page.waitForTimeout(250); |
| 18 | + await page.locator('#entityType').selectOption('1'); |
| 19 | + } |
| 20 | + |
| 21 | + if (hasDescription) { |
| 22 | + await page.waitForTimeout(250); |
| 23 | + // Fill in the description |
| 24 | + await page.locator('#description').fill(hasDescription); |
| 25 | + } |
| 26 | + |
| 27 | + if (hasMetaData) { |
| 28 | + await page.waitForTimeout(250); |
| 29 | + // Choose the metadata structure |
| 30 | + await page.locator('#metadataStructure').selectOption(hasMetaData); |
| 31 | + await page.locator('#metadataStructure').dispatchEvent('change'); |
| 32 | + } |
| 33 | + |
| 34 | + if (hasRequiredField == "Description") { |
| 35 | + // Choose required fields |
| 36 | + await page.waitForTimeout(500); |
| 37 | + await page.locator('#metadataFields-container .svelte-select.multi').click(); |
| 38 | + await page.waitForTimeout(250); |
| 39 | + await page.locator('#metadataFields-container .list-item .item:has-text("Description")').click(); |
| 40 | + } |
| 41 | + |
| 42 | + if (hasDataSet == "hasDataSet") { |
| 43 | + await page.waitForTimeout(250); |
| 44 | + // Choose dataset components to be disabled |
| 45 | + await page.locator('#disabledHooks-container .svelte-select.multi').click(); |
| 46 | + await page.locator('#disabledHooks-container .list-item .item:has-text("File Upload")').click(); |
| 47 | + |
| 48 | + await page.locator('#disabledHooks-container .svelte-select.multi').click(); |
| 49 | + await page.locator('#disabledHooks-container .list-item .item:has-text("Data Structure")').click(); |
| 50 | + } |
| 51 | + |
| 52 | + if (hasFileType == "hasFileType") { |
| 53 | + await page.waitForTimeout(250); |
| 54 | + // Choose allowed file types for file upload |
| 55 | + await page.locator('#allowedFileTypes-container .svelte-select.multi').click(); |
| 56 | + await page.locator('#allowedFileTypes-container .list-item .item:has-text(".avi")').click(); |
| 57 | + |
| 58 | + await page.locator('#allowedFileTypes-container .svelte-select.multi').click(); |
| 59 | + await page.locator('#allowedFileTypes-container .list-item .item:has-text(".bmp")').click(); |
| 60 | + } |
| 61 | + |
| 62 | + |
| 63 | + // Handling different conditions based on parameters |
| 64 | + if (hasEntityName && hasEntityType && !hasDescription && !hasMetaData && !hasRequiredField && !hasDataSet && !hasFileType) { |
| 65 | + |
| 66 | + const saveButton = page.locator('button[title=save]') |
| 67 | + await expect(saveButton).toBeDisabled(); |
| 68 | + await page.reload() |
| 69 | + } |
| 70 | + |
| 71 | + else if (hasEntityName && !hasEntityType && hasDescription && !hasMetaData && !hasRequiredField && !hasDataSet && !hasFileType) { |
| 72 | + |
| 73 | + const saveButton = page.locator('button[title=save]') |
| 74 | + await expect(saveButton).toBeDisabled(); |
| 75 | + await page.reload() |
| 76 | + } |
| 77 | + |
| 78 | + else if (hasEntityName && hasEntityType && hasDescription && !hasMetaData && !hasRequiredField && !hasDataSet && !hasFileType) { |
| 79 | + |
| 80 | + const saveButton = page.locator('button[title=save]') |
| 81 | + await expect(saveButton).toBeDisabled(); |
| 82 | + await page.reload() |
| 83 | + } |
| 84 | + else if (hasEntityName && hasEntityType && hasDescription && hasMetaData && !hasRequiredField && !hasDataSet && !hasFileType) { |
| 85 | + |
| 86 | + // Click save |
| 87 | + await page.locator('button[title=save]').click(); |
| 88 | + |
| 89 | + // Verify entity's existence and contents |
| 90 | + const card = await page.locator('.card', { |
| 91 | + has: page.locator(`header h2:has-text("${hasEntityName}")`), |
| 92 | + }); |
| 93 | + await expect( |
| 94 | + card.locator('header .badge.variant-filled-surface') |
| 95 | + ).toHaveText('Basic ABCD'); |
| 96 | + await expect( |
| 97 | + card.locator('header .badge.variant-filled-secondary') |
| 98 | + ).toHaveText('Dataset'); |
| 99 | + |
| 100 | + await page.reload() |
| 101 | + } |
| 102 | + |
| 103 | + else if (hasEntityName && hasEntityType && hasDescription && hasMetaData && hasRequiredField && !hasDataSet && !hasFileType) { |
| 104 | + |
| 105 | + // Click save |
| 106 | + await page.locator('button[title=save]').click(); |
| 107 | + |
| 108 | + // Verify entity's existence and contents |
| 109 | + const card = await page.locator('.card', { |
| 110 | + has: page.locator(`header h2:has-text("${hasEntityName}")`), |
| 111 | + }); |
| 112 | + await expect( |
| 113 | + card.locator('header .badge.variant-filled-surface') |
| 114 | + ).toHaveText('Basic ABCD'); |
| 115 | + await expect( |
| 116 | + card.locator('header .badge.variant-filled-secondary') |
| 117 | + ).toHaveText('Dataset'); |
| 118 | + |
| 119 | + await page.reload() |
| 120 | + } |
| 121 | + |
| 122 | + else if (hasEntityName && hasEntityType && hasDescription && hasMetaData && hasRequiredField && hasDataSet && !hasFileType) { |
| 123 | + |
| 124 | + // Click save |
| 125 | + await page.locator('button[title=save]').click(); |
| 126 | + |
| 127 | + // Verify entity's existence and contents |
| 128 | + const card = await page.locator('.card', { |
| 129 | + has: page.locator(`header h2:has-text("${hasEntityName}")`), |
| 130 | + }); |
| 131 | + await expect( |
| 132 | + card.locator('header .badge.variant-filled-surface') |
| 133 | + ).toHaveText('Basic ABCD'); |
| 134 | + await expect( |
| 135 | + card.locator('header .badge.variant-filled-secondary') |
| 136 | + ).toHaveText('Dataset'); |
| 137 | + |
| 138 | + await page.reload() |
| 139 | + } |
| 140 | + |
| 141 | + else if (hasEntityName && hasEntityType && hasDescription && hasMetaData && hasRequiredField && !hasDataSet && hasFileType) { |
| 142 | + |
| 143 | + // Click save |
| 144 | + await page.locator('button[title=save]').click(); |
| 145 | + |
| 146 | + // Verify entity's existence and contents |
| 147 | + const card = await page.locator('.card', { |
| 148 | + has: page.locator(`header h2:has-text("${hasEntityName}")`), |
| 149 | + }); |
| 150 | + await expect( |
| 151 | + card.locator('header .badge.variant-filled-surface') |
| 152 | + ).toHaveText('Basic ABCD'); |
| 153 | + await expect( |
| 154 | + card.locator('header .badge.variant-filled-secondary') |
| 155 | + ).toHaveText('Dataset'); |
| 156 | + |
| 157 | + await page.reload() |
| 158 | + } |
| 159 | + |
| 160 | + |
| 161 | +} |
| 162 | +async function createEntityTemplate(page, entityName) { |
| 163 | + |
| 164 | + // Open the form |
| 165 | + await page.locator('button[title=create]').click(); |
| 166 | + // Fill in the name |
| 167 | + await page.locator('#name').fill(entityName); |
| 168 | + await page.waitForTimeout(250); |
| 169 | + // Choose the entity type |
| 170 | + await page.locator('#entityType').selectOption('1'); |
| 171 | + await page.waitForTimeout(250); |
| 172 | + // Fill in the description |
| 173 | + await page.locator('#description').fill('Test description'); |
| 174 | + // Wait for the requests to finish |
| 175 | + await page.waitForLoadState('domcontentloaded'); |
| 176 | + |
| 177 | + // Choose the metadata structure |
| 178 | + await page.waitForTimeout(250); |
| 179 | + await page.locator('#metadataStructure').selectOption('1'); |
| 180 | + await page.locator('#metadataStructure').dispatchEvent('change'); |
| 181 | + |
| 182 | + // Choose required fields |
| 183 | +await page.waitForTimeout(500); |
| 184 | +await page.locator('#metadataFields-container .svelte-select.multi').click(); |
| 185 | +await page.waitForTimeout(250); |
| 186 | +await page.locator('#metadataFields-container .list-item .item:has-text("Description")').click(); |
| 187 | +await page.locator('#metadataFields-container .svelte-select.multi').click(); |
| 188 | +await page.locator('#metadataFields-container .list-item .item:has-text("ProjectTitle")').click(); |
| 189 | + |
| 190 | +// Choose dataset components to be disabled |
| 191 | +await page.waitForTimeout(250); |
| 192 | +await page.locator('#disabledHooks-container .svelte-select.multi').click(); |
| 193 | +await page.locator('#disabledHooks-container .list-item .item:has-text("File Upload")').click(); |
| 194 | +await page.locator('#disabledHooks-container .svelte-select.multi').click(); |
| 195 | +await page.locator('#disabledHooks-container .list-item .item:has-text("Data Structure")').click(); |
| 196 | + |
| 197 | +// Choose allowed file types for file upload |
| 198 | +await page.waitForTimeout(250); |
| 199 | +await page.locator('#allowedFileTypes-container .svelte-select.multi').click(); |
| 200 | +await page.locator('#allowedFileTypes-container .list-item .item:has-text(".avi")').click(); |
| 201 | +await page.locator('#allowedFileTypes-container .svelte-select.multi').click(); |
| 202 | +await page.locator('#allowedFileTypes-container .list-item .item:has-text(".bmp")').click(); |
| 203 | + |
| 204 | + |
| 205 | + // Click save |
| 206 | + await page.locator('button[title=save]').click(); |
| 207 | + |
| 208 | + // Verify entity's existence and contents |
| 209 | + const card = await page.locator('.card', { |
| 210 | + has: page.locator(`header h2:has-text("${entityName}")`), |
| 211 | + }); |
| 212 | + await expect( |
| 213 | + card.locator('header .badge.variant-filled-surface') |
| 214 | + ).toHaveText('Basic ABCD'); |
| 215 | + await expect( |
| 216 | + card.locator('header .badge.variant-filled-secondary') |
| 217 | + ).toHaveText('Dataset'); |
| 218 | + await expect(card.locator('blockquote')).toHaveText('Test description'); |
| 219 | + await expect(card.locator('i')).toHaveText( |
| 220 | + 'Restricted to these file types: .avi, .bmp' |
| 221 | + ); |
| 222 | + |
| 223 | +} |
| 224 | + |
| 225 | + |
| 226 | +async function editEntityTemplate(page, entityName) { |
| 227 | + |
| 228 | + const card = await page.locator('.card', { |
| 229 | + has: page.locator(`header h2:has-text("${entityName}")`), |
| 230 | + }); |
| 231 | + |
| 232 | + // Click edit |
| 233 | + await card.locator('button[title=edit]').click(); |
| 234 | + await page.waitForTimeout(250); |
| 235 | + |
| 236 | + // Change the name |
| 237 | + await page.locator('#name').fill('Test Edited'); |
| 238 | + |
| 239 | + // Change the description |
| 240 | + await page.waitForTimeout(250); |
| 241 | + await page.locator('#description').fill('Test description edited'); |
| 242 | + |
| 243 | + // Choose the metadata structure |
| 244 | + await page.waitForTimeout(250); |
| 245 | + await page.locator('#metadataStructure').selectOption('2'); |
| 246 | + |
| 247 | + // Clear the required fields |
| 248 | + await page.waitForTimeout(250); |
| 249 | +await expect(page.locator('#metadataFields-container .multi-item .multi-item-clear')).toHaveCount(2); |
| 250 | +await page.locator('#metadataFields-container .multi-item .multi-item-clear').first().click(); |
| 251 | +await page.locator('#metadataFields-container .multi-item .multi-item-clear').click(); |
| 252 | + |
| 253 | +// Choose required fields |
| 254 | +await page.waitForTimeout(500); |
| 255 | +await page.locator('#metadataFields-container .svelte-select.multi').click(); |
| 256 | +await page.waitForTimeout(250); |
| 257 | +await page.locator('#metadataFields-container .list-item .item:has-text("Author")').click(); |
| 258 | +await page.locator('#metadataFields-container .svelte-select.multi').click(); |
| 259 | +await page.locator('#metadataFields-container .list-item .item:text-is("Title")').click(); |
| 260 | + |
| 261 | +// Clear the dataset components to be disabled |
| 262 | +await page.waitForTimeout(250); |
| 263 | +await expect(page.locator('#disabledHooks-container .multi-item .multi-item-clear')).toHaveCount(2); |
| 264 | +await page.locator('#disabledHooks-container .multi-item .multi-item-clear').first().click(); |
| 265 | +await page.locator('#disabledHooks-container .multi-item .multi-item-clear').click(); |
| 266 | + |
| 267 | +// Choose dataset components to be disabled |
| 268 | +await page.waitForTimeout(250); |
| 269 | +await page.locator('#disabledHooks-container .svelte-select.multi').click(); |
| 270 | +await page.locator('#disabledHooks-container .list-item .item:has-text("Metadata")').click(); |
| 271 | +await page.locator('#disabledHooks-container .svelte-select.multi').click(); |
| 272 | +await page.locator('#disabledHooks-container .list-item .item:has-text("Validation")').click(); |
| 273 | + |
| 274 | +// Clear the allowed file types for file upload |
| 275 | +await page.waitForTimeout(250); |
| 276 | +await expect(page.locator('#allowedFileTypes-container .multi-item .multi-item-clear')).toHaveCount(2); |
| 277 | +await page.locator('#allowedFileTypes-container .multi-item .multi-item-clear').first().click(); |
| 278 | +await page.locator('#allowedFileTypes-container .multi-item .multi-item-clear').click(); |
| 279 | + |
| 280 | +// Choose allowed file types for file upload |
| 281 | +await page.waitForTimeout(250); |
| 282 | +await page.locator('#allowedFileTypes-container .svelte-select.multi').click(); |
| 283 | +await page.locator('#allowedFileTypes-container .list-item .item:has-text(".csv")').click(); |
| 284 | +await page.locator('#allowedFileTypes-container .svelte-select.multi').click(); |
| 285 | +await page.locator('#allowedFileTypes-container .list-item .item:has-text(".dbf")').click(); |
| 286 | + |
| 287 | + |
| 288 | + |
| 289 | + // Click save |
| 290 | + await page.locator('button[title=save]').click(); |
| 291 | + |
| 292 | + // Verify entity's existence and contents |
| 293 | + const editedCard = await page.locator('.card', { |
| 294 | + has: page.locator('header h2:has-text("Test edited")'), |
| 295 | + }); |
| 296 | + await expect( |
| 297 | + editedCard.locator('header .badge.variant-filled-surface') |
| 298 | + ).toHaveText('GBIF'); |
| 299 | + await expect( |
| 300 | + editedCard.locator('header .badge.variant-filled-secondary') |
| 301 | + ).toHaveText('Dataset'); |
| 302 | + await expect(editedCard.locator('blockquote')).toHaveText( |
| 303 | + 'Test description edited' |
| 304 | + ); |
| 305 | + await expect(editedCard.locator('i')).toHaveText( |
| 306 | + 'Restricted to these file types: .csv, .dbf' |
| 307 | + ); |
| 308 | + |
| 309 | +} |
| 310 | + |
| 311 | +async function deleteEntityTemplate(page, entityName) { |
| 312 | + |
| 313 | + const card = await page.locator('.card', { |
| 314 | + has: page.locator(`header h2:has-text("${entityName}")`), |
| 315 | + }); |
| 316 | + |
| 317 | + // Click delete |
| 318 | + await card.locator('button[title=delete]').click(); |
| 319 | + |
| 320 | + // Wait until the modal appears |
| 321 | + await page.waitForSelector('.modal'); |
| 322 | + |
| 323 | + // Check the modal title |
| 324 | + await expect(page.locator('.modal-header')).toHaveText('Please Confirm'); |
| 325 | + await expect(page.locator('.modal-body')).toHaveText( |
| 326 | + 'Are you sure you wish to remove?' |
| 327 | + ); |
| 328 | + |
| 329 | + // Click Confirm |
| 330 | + await page |
| 331 | + .locator('.modal-footer') |
| 332 | + .locator('button.variant-filled') |
| 333 | + .click(); |
| 334 | + |
| 335 | + // Verify the entity template is deleted |
| 336 | + await expect(card).not.toBeVisible(); |
| 337 | + |
| 338 | +} |
| 339 | + |
| 340 | + |
| 341 | +async function deleteEditedEntityTemplate(page) { |
| 342 | + |
| 343 | + const card = await page.locator('.card', { |
| 344 | + has: page.locator('header h2:has-text("Test edited")'), |
| 345 | + }); |
| 346 | + |
| 347 | + // Click delete |
| 348 | + await card.locator('button[title=delete]').click(); |
| 349 | + |
| 350 | + // Wait until the modal appears |
| 351 | + await page.waitForSelector('.modal'); |
| 352 | + |
| 353 | + // Check the modal title |
| 354 | + await expect(page.locator('.modal-header')).toHaveText('Please Confirm'); |
| 355 | + await expect(page.locator('.modal-body')).toHaveText( |
| 356 | + 'Are you sure you wish to remove?' |
| 357 | + ); |
| 358 | + |
| 359 | + // Click Confirm |
| 360 | + await page |
| 361 | + .locator('.modal-footer') |
| 362 | + .locator('button.variant-filled') |
| 363 | + .click(); |
| 364 | + |
| 365 | + // Verify the entity template is deleted |
| 366 | + await expect(card).not.toBeVisible(); |
| 367 | + |
| 368 | +} |
| 369 | + |
| 370 | +module.exports = { |
| 371 | + checkEntityTemplate, |
| 372 | + deleteEntityTemplate, |
| 373 | + createEntityTemplate, |
| 374 | + editEntityTemplate, |
| 375 | + deleteEditedEntityTemplate, |
| 376 | + }; |
| 377 | + |
0 commit comments