|
| 1 | +import { expect } from "@playwright/test"; |
| 2 | + |
| 3 | + |
| 4 | +async function checkMeanings(page, meaningName, hasDescription, hasRelation, hasApproved, hasSelectable, hasConstraints) { |
| 5 | + await page.waitForLoadState('load'); |
| 6 | + |
| 7 | + await page.locator('#create').click(); |
| 8 | + await page.waitForTimeout(1000); |
| 9 | + |
| 10 | + // Fill in the name and description if provided |
| 11 | + if (meaningName) { |
| 12 | + await page.locator('input[id=name]').fill(meaningName); |
| 13 | + } |
| 14 | + if (hasDescription) { |
| 15 | + await page.locator('textarea[id=description]').fill('Test Meanings'); |
| 16 | + } |
| 17 | + if (hasRelation) { |
| 18 | + // Click the button |
| 19 | + await page.click('div.inline-block.align-bottom button.chip.variant-filled-primary'); |
| 20 | + |
| 21 | + // Click the input element |
| 22 | + await page.click('div#relation-container'); |
| 23 | + await page.waitForTimeout(500); |
| 24 | + await page.locator('.list-item .item.first').click(); |
| 25 | + |
| 26 | + // Click the input element |
| 27 | + await page.click('div#others-container'); |
| 28 | + await page.waitForTimeout(500); |
| 29 | + const objects = await page.waitForSelector('.list-item .item:text("occurrenceID")', { visible: true, enabled: true }); |
| 30 | + await objects.click() |
| 31 | + |
| 32 | + } |
| 33 | + |
| 34 | + if (hasApproved) { |
| 35 | + // Click on the element based on its text content |
| 36 | + await page.click('div.slide-toggle-text:has-text("Approved")'); |
| 37 | + } |
| 38 | + if (hasSelectable) { |
| 39 | + // Click on the element based on its text content |
| 40 | + await page.click('div.slide-toggle-text:has-text("Selectable")'); |
| 41 | + } |
| 42 | + |
| 43 | + if (hasConstraints) { |
| 44 | + // Select Constraint |
| 45 | + await page.locator('#constraints').click(); |
| 46 | + await page.waitForTimeout(500); |
| 47 | + const option = await page.waitForSelector('.list-item .item:text("Test Constraint")', { visible: true, enabled: true }); |
| 48 | + await option.click() |
| 49 | + |
| 50 | + } |
| 51 | + |
| 52 | + // Handling different conditions based on parameters |
| 53 | + if (meaningName && hasDescription && !hasRelation && !hasApproved && !hasSelectable && !hasConstraints) { |
| 54 | + await page.waitForLoadState('load'); |
| 55 | + await page.waitForTimeout(1500); |
| 56 | + // Check if the save button is enable and reload the page |
| 57 | + const saveButton = page.locator('button#save').click(); |
| 58 | + await page.waitForTimeout(500); |
| 59 | + |
| 60 | + await page.waitForSelector('.toast[data-testid=toast] .text-base'); |
| 61 | + const toast = await page.locator('.toast[data-testid=toast]'); |
| 62 | + |
| 63 | + let expectedMessage = 'Meaning created.'; |
| 64 | + await expect(await toast.locator('.text-base')).toHaveText(expectedMessage); |
| 65 | + await toast.locator('button').click(); // Close the toast |
| 66 | + await page.reload(); |
| 67 | + } |
| 68 | + |
| 69 | + else if (meaningName && hasDescription && hasRelation && !hasApproved && !hasSelectable && !hasConstraints) { |
| 70 | + await page.waitForLoadState('load'); |
| 71 | + await page.waitForTimeout(1500); |
| 72 | + // Check if the save button is enable and reload the page |
| 73 | + const saveButton = page.locator('button#save').click(); |
| 74 | + await page.waitForTimeout(500); |
| 75 | + |
| 76 | + await page.waitForSelector('.toast[data-testid=toast] .text-base'); |
| 77 | + const toast = await page.locator('.toast[data-testid=toast]'); |
| 78 | + |
| 79 | + let expectedMessage = 'Meaning created.'; |
| 80 | + await expect(await toast.locator('.text-base')).toHaveText(expectedMessage); |
| 81 | + await toast.locator('button').click(); // Close the toast |
| 82 | + await page.reload(); |
| 83 | + } |
| 84 | + |
| 85 | + else if (meaningName && hasDescription && hasRelation && hasApproved && !hasSelectable && !hasConstraints) { |
| 86 | + await page.waitForLoadState('load'); |
| 87 | + await page.waitForTimeout(1500); |
| 88 | + // Check if the save button is enable and reload the page |
| 89 | + const saveButton = page.locator('button#save').click(); |
| 90 | + await page.waitForTimeout(500); |
| 91 | + |
| 92 | + await page.waitForSelector('.toast[data-testid=toast] .text-base'); |
| 93 | + const toast = await page.locator('.toast[data-testid=toast]'); |
| 94 | + |
| 95 | + let expectedMessage = 'Meaning created.'; |
| 96 | + await expect(await toast.locator('.text-base')).toHaveText(expectedMessage); |
| 97 | + await toast.locator('button').click(); // Close the toast |
| 98 | + await page.reload(); |
| 99 | + } |
| 100 | + |
| 101 | + else if (meaningName && hasDescription && hasRelation && hasApproved && hasSelectable && !hasConstraints) { |
| 102 | + await page.waitForLoadState('load'); |
| 103 | + await page.waitForTimeout(1500); |
| 104 | + // Check if the save button is enable and reload the page |
| 105 | + const saveButton = page.locator('button#save').click(); |
| 106 | + await page.waitForTimeout(500); |
| 107 | + |
| 108 | + await page.waitForSelector('.toast[data-testid=toast] .text-base'); |
| 109 | + const toast = await page.locator('.toast[data-testid=toast]'); |
| 110 | + |
| 111 | + let expectedMessage = 'Meaning created.'; |
| 112 | + await expect(await toast.locator('.text-base')).toHaveText(expectedMessage); |
| 113 | + await toast.locator('button').click(); // Close the toast |
| 114 | + await page.reload(); |
| 115 | + } |
| 116 | + |
| 117 | + else if (meaningName && hasDescription && hasRelation && !hasApproved && !hasSelectable && hasConstraints) { |
| 118 | + await page.waitForLoadState('load'); |
| 119 | + await page.waitForTimeout(1500); |
| 120 | + // Check if the save button is enable and reload the page |
| 121 | + const saveButton = page.locator('button#save').click(); |
| 122 | + await page.waitForTimeout(1000); |
| 123 | + |
| 124 | + await page.waitForSelector('.toast[data-testid=toast] .text-base'); |
| 125 | + const toast = await page.locator('.toast[data-testid=toast]'); |
| 126 | + |
| 127 | + let expectedMessage = 'Meaning created.'; |
| 128 | + await expect(await toast.locator('.text-base')).toHaveText(expectedMessage); |
| 129 | + await toast.locator('button').click(); // Close the toast |
| 130 | + await page.reload(); |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +async function findMeanings(page, meaningName) { |
| 135 | + // await page.reload() |
| 136 | + await page.waitForLoadState('load'); |
| 137 | + // Wait for 500 milliseconds |
| 138 | + await page.waitForTimeout(500); |
| 139 | + // Search for the variable |
| 140 | + await page.locator('#Meaning-search').fill(meaningName); |
| 141 | + // Wait for 1000 milliseconds |
| 142 | + await page.waitForTimeout(1000); |
| 143 | + // Click on the Search button |
| 144 | + await page.click('form.flex > button:nth-child(2)'); |
| 145 | + // Wait for 500 milliseconds |
| 146 | + await page.waitForTimeout(500); |
| 147 | + // Locate the correct row |
| 148 | + const row = page.locator('[id^=Meaning-row-]'); |
| 149 | + await expect(row).toHaveCount(1); |
| 150 | + // Wait for 500 milliseconds |
| 151 | + await page.waitForTimeout(500); |
| 152 | + // Get the index of the row |
| 153 | + const id = (await row.getAttribute('id')); |
| 154 | + const index = id.split('-')[2]; |
| 155 | + // Check values for the row |
| 156 | + await expect(page.locator(`#Meaning-name-${index}`)).toHaveText(meaningName); |
| 157 | + await expect(page.locator(`#Meaning-description-${index}`)).toHaveText( |
| 158 | + 'Test Meanings' |
| 159 | + ); |
| 160 | +} |
| 161 | + |
| 162 | +async function deleteMeanings(page) { |
| 163 | + // Click on the delete button |
| 164 | + await page.locator('[id^=delete-]').click(); |
| 165 | + |
| 166 | + // Wait until the modal appears |
| 167 | + await page.waitForSelector('.modal'); |
| 168 | + |
| 169 | + // Check the modal title and body text |
| 170 | + await expect(page.locator('.modal-header')).toHaveText('Delete Meaning'); |
| 171 | + await expect(page.locator('.modal-body')).toContainText(`Are you sure you wish to delete Meaning`); |
| 172 | + |
| 173 | + // Click the confirm button in the modal footer |
| 174 | + await page.locator('.modal-footer button.variant-filled').click(); |
| 175 | + // Wait for 750 milliseconds |
| 176 | + await page.waitForTimeout(750); |
| 177 | + await page.reload() |
| 178 | + |
| 179 | +} |
| 180 | + |
| 181 | +async function createMeanings(page, meaningName) { |
| 182 | + await page.waitForLoadState('load'); |
| 183 | + |
| 184 | + await page.locator('#create').click(); |
| 185 | + await page.waitForTimeout(1000); |
| 186 | + |
| 187 | + // Fill in the name and description if provided |
| 188 | + await page.locator('input[id=name]').fill(meaningName); |
| 189 | + // Wait for 500 milliseconds |
| 190 | + await page.waitForTimeout(500); |
| 191 | + |
| 192 | + await page.locator('textarea[id=description]').fill('Test Meanings'); |
| 193 | + // Wait for 500 milliseconds |
| 194 | + await page.waitForTimeout(500); |
| 195 | + |
| 196 | + // Click the button |
| 197 | + await page.click('div.inline-block.align-bottom button.chip.variant-filled-primary'); |
| 198 | + // Wait for 500 milliseconds |
| 199 | + await page.waitForTimeout(500); |
| 200 | + |
| 201 | + // Click the input element |
| 202 | + await page.click('div#relation-container'); |
| 203 | + |
| 204 | + await page.waitForTimeout(500); |
| 205 | + await page.locator('.list-item .item.first').click(); |
| 206 | + |
| 207 | + // Click the input element |
| 208 | + await page.click('div#others-container'); |
| 209 | + await page.waitForTimeout(500); |
| 210 | + |
| 211 | + const objects = await page.waitForSelector('.list-item .item:text("occurrenceID")', { visible: true, enabled: true }); |
| 212 | + await objects.click() |
| 213 | + |
| 214 | + // Click on the element based on its text content |
| 215 | + await page.click('div.slide-toggle-text:has-text("Approved")'); |
| 216 | + await page.waitForTimeout(500); |
| 217 | + |
| 218 | + // Click on the element based on its text content |
| 219 | + await page.click('div.slide-toggle-text:has-text("Selectable")'); |
| 220 | + await page.waitForTimeout(500); |
| 221 | + |
| 222 | + // Check if the save button is enable and reload the page |
| 223 | + const saveButton = page.locator('button#save').click(); |
| 224 | + await page.waitForTimeout(1000); |
| 225 | + |
| 226 | + await page.waitForSelector('.toast[data-testid=toast] .text-base'); |
| 227 | + const toast = await page.locator('.toast[data-testid=toast]'); |
| 228 | + |
| 229 | + let expectedMessage = 'Meaning created.'; |
| 230 | + await expect(await toast.locator('.text-base')).toHaveText(expectedMessage); |
| 231 | + await toast.locator('button').click(); // Close the toast |
| 232 | + await page.reload(); |
| 233 | +} |
| 234 | + |
| 235 | +async function editMeaning(page, meaning) { |
| 236 | + |
| 237 | + // Click on the delete button |
| 238 | + await page.locator('[id^=edit-]').click(); |
| 239 | + // Wait for 500 milliseconds |
| 240 | + await page.waitForTimeout(500); |
| 241 | + await page.locator('input[id=name]').fill(meaning); |
| 242 | + |
| 243 | + // Click on the element based on its text content |
| 244 | + await page.click('div.slide-toggle-text:has-text("Approved")'); |
| 245 | + await page.waitForTimeout(500); |
| 246 | + |
| 247 | + // Click on the element based on its text content |
| 248 | + await page.click('div.slide-toggle-text:has-text("Selectable")'); |
| 249 | + await page.waitForTimeout(500); |
| 250 | + await page.locator('button[id=save]').click(); |
| 251 | + |
| 252 | + // Wait until the toast appears |
| 253 | + await page.waitForSelector('.toast[data-testid=toast] .text-base'); |
| 254 | + |
| 255 | + // Check the toast message |
| 256 | + const toast = await page.locator('.toast[data-testid=toast]'); |
| 257 | + await expect(await toast.locator('.text-base')).toHaveText( |
| 258 | + `Meaning updated.` |
| 259 | + ); |
| 260 | + await toast.locator('button').click(); // Close the toast |
| 261 | +} |
| 262 | + |
| 263 | +async function findEditedMeanings(page, meaning) { |
| 264 | + |
| 265 | + // Search for the new Meaning |
| 266 | + await page.locator('#Meaning-search').fill(meaning); |
| 267 | + // Locate the correct row |
| 268 | + const row = page.locator('[id^=Meaning-row-]'); |
| 269 | + await expect(row).toHaveCount(1); |
| 270 | + // Get the index of the row |
| 271 | + const id = (await row.getAttribute('id')); |
| 272 | + const index = id.split('-')[2]; |
| 273 | + // Check values for the row |
| 274 | + await expect(page.locator(`#Meaning-name-${index}`)).toHaveText(meaning); |
| 275 | + await expect(page.locator(`#Meaning-description-${index}`)).toHaveText( |
| 276 | + 'Test Meanings' |
| 277 | + ); |
| 278 | + |
| 279 | +} |
| 280 | + |
| 281 | +module.exports = { |
| 282 | + checkMeanings, |
| 283 | + findMeanings, |
| 284 | + deleteMeanings, |
| 285 | + createMeanings, |
| 286 | + editMeaning, |
| 287 | + findEditedMeanings |
| 288 | +}; |
0 commit comments