|
| 1 | +/* eslint-disable testing-library/prefer-screen-queries */ |
| 2 | +import {expect, test} from '@playwright/test' |
| 3 | +import {login, UserRole} from '../../../../helper/auth' |
| 4 | +import {navigateTo} from '../../../../helper/menu' |
| 5 | +import {Dropdown} from '../../../../helper/dropdown' |
| 6 | +import {Tabs} from '../../../../helper/tabs' |
| 7 | +import {generateTestId, TestId} from '../../../../helper/testIds' |
| 8 | +import {Switch} from '../../../../helper/switch' |
| 9 | +import {Grid} from "../../../../helper/grid"; |
| 10 | +import {Filter, FilterType} from "../../../../helper/filter"; |
| 11 | +import {randomUUID} from "crypto"; |
| 12 | +import {AlertMessage, AlertMessageType} from "../../../../helper/alertMessage"; |
| 13 | + |
| 14 | +const resourceName = 'User' |
| 15 | + |
| 16 | +const testIds = { |
| 17 | + grid: generateTestId(TestId.TABLE, resourceName), |
| 18 | + filter: { |
| 19 | + firstName: 'firstName', |
| 20 | + lastName: 'lastName', |
| 21 | + email: 'email', |
| 22 | + isActive: 'isActive', |
| 23 | + roles: 'roles[]', |
| 24 | + }, |
| 25 | + form: { |
| 26 | + isActive: 'isActive', |
| 27 | + firstName: generateTestId(TestId.INPUT_TEXT, 'firstName'), |
| 28 | + lastName: generateTestId(TestId.INPUT_TEXT, 'lastName'), |
| 29 | + email: generateTestId(TestId.INPUT_TEXT, 'email'), |
| 30 | + roles: 'roles', |
| 31 | + dummyPassword: generateTestId(TestId.INPUT_TEXT, 'dummyPassword'), |
| 32 | + submitButton: generateTestId(TestId.BUTTON, 'submit'), |
| 33 | + deleteButton: generateTestId(TestId.BUTTON, 'delete'), |
| 34 | + backButton: generateTestId(TestId.BUTTON, 'back'), |
| 35 | + deleteBoostPopin: { |
| 36 | + dialogConfirmButton: generateTestId(TestId.DIALOG_CONFIRM_BUTTON, resourceName), |
| 37 | + }, |
| 38 | + }, |
| 39 | + createButton: generateTestId(TestId.GRID_CREATE_BUTTON, resourceName), |
| 40 | +} as const |
| 41 | + |
| 42 | +const texts = { |
| 43 | + labelMenuPage: 'Configuration', |
| 44 | + gridHeaders: { |
| 45 | + firstName: 'First name', |
| 46 | + lastName: 'Last name', |
| 47 | + email: 'E-mail', |
| 48 | + roles: 'Role(s)', |
| 49 | + isActive: 'Enable', |
| 50 | + actions: 'Actions', |
| 51 | + }, |
| 52 | + filtersToApply: { |
| 53 | + firstName: 'John', |
| 54 | + lastName: 'Doe', |
| 55 | + email: 'admin', |
| 56 | + roles: [ |
| 57 | + 'Administrator', |
| 58 | + ], |
| 59 | + isActive: true, |
| 60 | + }, |
| 61 | + createValues: { |
| 62 | + roles: [ |
| 63 | + 'Administrator', |
| 64 | + ], |
| 65 | + expectedRolesAfterSave: [ |
| 66 | + 'Administrator', |
| 67 | + 'Contributor', |
| 68 | + ], |
| 69 | + }, |
| 70 | + editValues: { |
| 71 | + roles: ['Contributor'], |
| 72 | + editedRoleDisplay: 'Contributor', |
| 73 | + }, |
| 74 | + paginationOptions: ['10', '25', '50'], |
| 75 | + tabs: { |
| 76 | + scope: 'Scope', |
| 77 | + attributes: 'Attributes', |
| 78 | + configurations: 'Configurations', |
| 79 | + users: 'Users', |
| 80 | + }, |
| 81 | +} as const |
| 82 | + |
| 83 | +test('Pages > Configuration > Users', { tag: ['@premium', '@standard'] }, async ({ page }) => { |
| 84 | + await test.step('Login as CONTRIBUTOR', async () => { |
| 85 | + await login(page, UserRole.CONTRIBUTOR) |
| 86 | + |
| 87 | + const gridDataTestId = generateTestId(TestId.TABLE, resourceName) |
| 88 | + |
| 89 | + await navigateTo( |
| 90 | + page, |
| 91 | + texts.labelMenuPage, |
| 92 | + '/admin/settings/scope/catalogs' |
| 93 | + ) |
| 94 | + |
| 95 | + await test.step('Verify if tab "Users" is not present', async () => { |
| 96 | + const tabs = new Tabs(page) |
| 97 | + await tabs.expectToHaveTabs([texts.tabs.scope, texts.tabs.attributes, texts.tabs.configurations]) |
| 98 | + }) |
| 99 | + |
| 100 | + await test.step('Verify if contributor user has no access to user user gird page', async () => { |
| 101 | + await page.goto('/admin/settings/user/grid') |
| 102 | + await expect(page.locator(`[data-testId="${gridDataTestId}"]`)).toHaveCount(0) |
| 103 | + }) |
| 104 | + |
| 105 | + await test.step('Verify if contributor user has no access to user create page', async () => { |
| 106 | + await page.goto('/admin/settings/user/create') |
| 107 | + await expect(page).toHaveURL('admin/settings/scope/catalogs') |
| 108 | + }) |
| 109 | + |
| 110 | + await test.step('Verify if contributor user has no access to user update page', async () => { |
| 111 | + await page.goto('/admin/settings/user/edit?id=1') |
| 112 | + await expect(page).toHaveURL('admin/settings/scope/catalogs') |
| 113 | + }) |
| 114 | + }) |
| 115 | + |
| 116 | + await test.step('Login and navigate to the users page as ADMIN', async () => { |
| 117 | + await login(page, UserRole.ADMIN) |
| 118 | + await navigateTo( |
| 119 | + page, |
| 120 | + texts.labelMenuPage, |
| 121 | + '/admin/settings/scope/catalogs' |
| 122 | + ) |
| 123 | + |
| 124 | + const tabs = new Tabs(page) |
| 125 | + await tabs.expectToHaveTabs(Object.values(texts.tabs)) |
| 126 | + await tabs.navigateTo(texts.tabs.users, '/admin/settings/user/grid') |
| 127 | + }) |
| 128 | + |
| 129 | + // Grid and Filters Locators: |
| 130 | + const grid = new Grid(page, resourceName) |
| 131 | + const filter = new Filter(page, resourceName, { |
| 132 | + [testIds.filter.firstName]: FilterType.TEXT, |
| 133 | + [testIds.filter.lastName]: FilterType.TEXT, |
| 134 | + [testIds.filter.email]: FilterType.TEXT, |
| 135 | + [testIds.filter.roles]: FilterType.DROPDOWN, |
| 136 | + [testIds.filter.isActive]: FilterType.BOOLEAN, |
| 137 | + }) |
| 138 | + const createButton = page.getByTestId(testIds.createButton) |
| 139 | + |
| 140 | + // Form Locators (Edit / Create): |
| 141 | + const isActiveSwitch = new Switch(page, testIds.form.isActive) |
| 142 | + const firstNameInput = page.getByTestId(testIds.form.firstName) |
| 143 | + const lastNameInput = page.getByTestId(testIds.form.lastName) |
| 144 | + const emailInput = page.getByTestId(testIds.form.email) |
| 145 | + const dummyPasswordInput = page.getByTestId(testIds.form.dummyPassword) |
| 146 | + const rolesDropdown = new Dropdown(page, testIds.form.roles, true) |
| 147 | + const saveButton = page.getByTestId(testIds.form.submitButton) |
| 148 | + const deleteButton = page.getByTestId(testIds.form.deleteButton) |
| 149 | + |
| 150 | + // Define an email for the new user. |
| 151 | + const newUserFirstName = 'Tony' |
| 152 | + const newUserLastName = 'Dark' |
| 153 | + const newUserEmail = `${randomUUID()}@example.com` |
| 154 | + |
| 155 | + |
| 156 | + await test.step('Verify grid headers and pagination', async () => { |
| 157 | + await grid.expectHeadersToBe(Object.values(texts.gridHeaders)) |
| 158 | + await grid.pagination.expectToHaveOptions(texts.paginationOptions) |
| 159 | + await grid.pagination.expectToHaveRowsPerPage(50) |
| 160 | + }) |
| 161 | + |
| 162 | + await test.step('Add some filters and remove them', async () => { |
| 163 | + const defaultRowCount = await grid.getCountLines() |
| 164 | + await test.step('Apply all filters available', async () => { |
| 165 | + await filter.addFilter(testIds.filter.firstName, texts.filtersToApply.firstName) |
| 166 | + await filter.addFilter(testIds.filter.lastName, texts.filtersToApply.lastName) |
| 167 | + await filter.addFilter(testIds.filter.email, texts.filtersToApply.email) |
| 168 | + await filter.addFilter(testIds.filter.roles, texts.filtersToApply.roles) |
| 169 | + await filter.addFilter(testIds.filter.isActive, true) |
| 170 | + }) |
| 171 | + |
| 172 | + await test.step('Remove applied filters one by one', async () => { |
| 173 | + await filter.removeFilter( |
| 174 | + testIds.filter.firstName, |
| 175 | + texts.filtersToApply.firstName |
| 176 | + ) |
| 177 | + |
| 178 | + await filter.removeFilter( |
| 179 | + testIds.filter.lastName, |
| 180 | + texts.filtersToApply.lastName |
| 181 | + ) |
| 182 | + |
| 183 | + await filter.removeFilter( |
| 184 | + testIds.filter.email, |
| 185 | + texts.filtersToApply.email |
| 186 | + ) |
| 187 | + |
| 188 | + for (let i = 0; i < texts.filtersToApply.roles.length; i++) { |
| 189 | + await filter.removeFilter( |
| 190 | + testIds.filter.roles, |
| 191 | + texts.filtersToApply.roles[i] |
| 192 | + ) |
| 193 | + } |
| 194 | + |
| 195 | + await filter.removeFilter( |
| 196 | + testIds.filter.isActive, |
| 197 | + texts.filtersToApply.isActive |
| 198 | + ) |
| 199 | + }) |
| 200 | + |
| 201 | + await test.step('Apply a filter and compare the grid to see if it works', async () => { |
| 202 | + await filter.addFilter( |
| 203 | + testIds.filter.firstName, |
| 204 | + texts.filtersToApply.firstName |
| 205 | + ) |
| 206 | + |
| 207 | + await grid.pagination.expectToHaveCount(1) |
| 208 | + |
| 209 | + await grid.expectToFindLineWhere([ |
| 210 | + { |
| 211 | + columnName: texts.gridHeaders.firstName, |
| 212 | + value: texts.filtersToApply.firstName, |
| 213 | + }, |
| 214 | + ]) |
| 215 | + }) |
| 216 | + |
| 217 | + await test.step('Clear filter', async () => { |
| 218 | + await filter.clearFilters() |
| 219 | + await grid.pagination.expectToHaveCount(defaultRowCount) |
| 220 | + }) |
| 221 | + }) |
| 222 | + |
| 223 | + await test.step('Create a User', async () => { |
| 224 | + await createButton.click() |
| 225 | + await expect(page).toHaveURL('/admin/settings/user/create') |
| 226 | + |
| 227 | + // isActive Switch |
| 228 | + await test.step('Disable and enable the "isActive" switch', async () => { |
| 229 | + await isActiveSwitch.expectToBeChecked() |
| 230 | + await isActiveSwitch.disable() |
| 231 | + await isActiveSwitch.enable() |
| 232 | + }) |
| 233 | + |
| 234 | + // firstName InputText |
| 235 | + await test.step('Fill the "first name" field text', async () => { |
| 236 | + await expect(firstNameInput).toBeEmpty() |
| 237 | + await firstNameInput.fill(newUserFirstName) |
| 238 | + await expect(firstNameInput).toHaveValue(newUserFirstName) |
| 239 | + }) |
| 240 | + |
| 241 | + // lastName InputText |
| 242 | + await test.step('Fill the "last name" field text', async () => { |
| 243 | + await expect(lastNameInput).toBeEmpty() |
| 244 | + await lastNameInput.fill(newUserLastName) |
| 245 | + await expect(lastNameInput).toHaveValue(newUserLastName) |
| 246 | + }) |
| 247 | + |
| 248 | + // email InputText |
| 249 | + await test.step('Fill the "email" field text', async () => { |
| 250 | + await expect(emailInput).toBeEmpty() |
| 251 | + await emailInput.fill(newUserEmail) |
| 252 | + await expect(emailInput).toHaveValue(newUserEmail) |
| 253 | + }) |
| 254 | + |
| 255 | + // Roles Multiple Dropdown |
| 256 | + await test.step('Choose role in "roles" dropdown', async () => { |
| 257 | + await rolesDropdown.selectValue(texts.createValues.roles) |
| 258 | + }) |
| 259 | + |
| 260 | + // dummyPassword InputText |
| 261 | + await test.step('Check password field text is disabled', async () => { |
| 262 | + await dummyPasswordInput.isDisabled() |
| 263 | + }) |
| 264 | + |
| 265 | + // Create the User |
| 266 | + await saveButton.click() |
| 267 | + await expect(page).toHaveURL('/admin/settings/user/grid') |
| 268 | + }) |
| 269 | + |
| 270 | + await test.step('Verify the user existence in the grid', async () => { |
| 271 | + await grid.expectToFindLineWhere([ |
| 272 | + { |
| 273 | + columnName: texts.gridHeaders.email, |
| 274 | + value: newUserEmail, |
| 275 | + }, |
| 276 | + ]) |
| 277 | + await filter.addFilter(testIds.filter.email, newUserEmail) |
| 278 | + await grid.pagination.expectToHaveCount(1) |
| 279 | + }) |
| 280 | + |
| 281 | + const editLink = page.locator(`[data-testid="${testIds.grid}"] a`) |
| 282 | + |
| 283 | + await test.step('Edit a User', async () => { |
| 284 | + await editLink.click() |
| 285 | + await expect(page).toHaveURL(/\/admin\/settings\/user\/edit\?id=\d+$/) |
| 286 | + |
| 287 | + await test.step('Check password field text is disabled', async () => { |
| 288 | + await dummyPasswordInput.isDisabled() |
| 289 | + }) |
| 290 | + |
| 291 | + await test.step('Check email field text is disabled', async () => { |
| 292 | + await emailInput.isDisabled() |
| 293 | + }) |
| 294 | + |
| 295 | + await rolesDropdown.expectToHaveValue(texts.createValues.expectedRolesAfterSave) |
| 296 | + await rolesDropdown.clear() |
| 297 | + await rolesDropdown.selectValue(texts.editValues.roles) |
| 298 | + |
| 299 | + await saveButton.click() |
| 300 | + const alertMessage = new AlertMessage(page) |
| 301 | + await alertMessage.expectToHaveText('Updating of the user with success', AlertMessageType.SUCCESS) |
| 302 | + |
| 303 | + const backButton = page.getByTestId(testIds.form.backButton) |
| 304 | + await backButton.click() |
| 305 | + await expect(page).toHaveURL('/admin/settings/user/grid') |
| 306 | + }) |
| 307 | + |
| 308 | + await test.step('Delete the User', async () => { |
| 309 | + await filter.addFilter(testIds.filter.email, newUserEmail) |
| 310 | + await grid.pagination.expectToHaveCount(1) |
| 311 | + await grid.expectToFindLineWhere([ |
| 312 | + { |
| 313 | + columnName: texts.gridHeaders.email, |
| 314 | + value: newUserEmail, |
| 315 | + }, |
| 316 | + { |
| 317 | + columnName: texts.gridHeaders.roles, |
| 318 | + value: texts.editValues.editedRoleDisplay |
| 319 | + }, |
| 320 | + ]) |
| 321 | + |
| 322 | + await editLink.click() |
| 323 | + |
| 324 | + await deleteButton.click() |
| 325 | + await page.getByTestId(testIds.form.deleteBoostPopin.dialogConfirmButton).click() |
| 326 | + await expect(page).toHaveURL('/admin/settings/user/grid') |
| 327 | + await filter.addFilter(testIds.filter.email, newUserEmail) |
| 328 | + await grid.pagination.expectToHaveCount(0) |
| 329 | + }) |
| 330 | +}) |
0 commit comments