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