1
0

users.cy.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**
  2. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: AGPL-3.0-or-later
  4. */
  5. /// <reference types="cypress-if" />
  6. import { User } from '@nextcloud/cypress'
  7. import { getUserListRow, handlePasswordConfirmation } from './usersUtils'
  8. const admin = new User('admin', 'admin')
  9. const john = new User('john', '123456')
  10. describe('Settings: Create and delete accounts', function() {
  11. beforeEach(function() {
  12. cy.listUsers().then((users) => {
  13. if ((users as string[]).includes(john.userId)) {
  14. // ensure created user is deleted
  15. cy.deleteUser(john)
  16. }
  17. })
  18. cy.login(admin)
  19. // open the User settings
  20. cy.visit('/settings/users')
  21. })
  22. it('Can create a user', function() {
  23. // open the New user modal
  24. cy.get('button#new-user-button').click()
  25. cy.get('form[data-test="form"]').within(() => {
  26. // see that the username is ""
  27. cy.get('input[data-test="username"]').should('exist').and('have.value', '')
  28. // set the username to john
  29. cy.get('input[data-test="username"]').type(john.userId)
  30. // see that the username is john
  31. cy.get('input[data-test="username"]').should('have.value', john.userId)
  32. // see that the password is ""
  33. cy.get('input[type="password"]').should('exist').and('have.value', '')
  34. // set the password to 123456
  35. cy.get('input[type="password"]').type(john.password)
  36. // see that the password is 123456
  37. cy.get('input[type="password"]').should('have.value', john.password)
  38. })
  39. cy.get('form[data-test="form"]').parents('[role="dialog"]').within(() => {
  40. // submit the new user form
  41. cy.get('button[type="submit"]').click({ force: true })
  42. })
  43. // Make sure no confirmation modal is shown
  44. handlePasswordConfirmation(admin.password)
  45. // see that the created user is in the list
  46. getUserListRow(john.userId)
  47. // see that the list of users contains the user john
  48. .contains(john.userId).should('exist')
  49. })
  50. it('Can create a user with additional field data', function() {
  51. // open the New user modal
  52. cy.get('button#new-user-button').click()
  53. cy.get('form[data-test="form"]').within(() => {
  54. // set the username
  55. cy.get('input[data-test="username"]').should('exist').and('have.value', '')
  56. cy.get('input[data-test="username"]').type(john.userId)
  57. cy.get('input[data-test="username"]').should('have.value', john.userId)
  58. // set the display name
  59. cy.get('input[data-test="displayName"]').should('exist').and('have.value', '')
  60. cy.get('input[data-test="displayName"]').type('John Smith')
  61. cy.get('input[data-test="displayName"]').should('have.value', 'John Smith')
  62. // set the email
  63. cy.get('input[data-test="email"]').should('exist').and('have.value', '')
  64. cy.get('input[data-test="email"]').type('john@example.org')
  65. cy.get('input[data-test="email"]').should('have.value', 'john@example.org')
  66. // set the password
  67. cy.get('input[type="password"]').should('exist').and('have.value', '')
  68. cy.get('input[type="password"]').type(john.password)
  69. cy.get('input[type="password"]').should('have.value', john.password)
  70. })
  71. cy.get('form[data-test="form"]').parents('[role="dialog"]').within(() => {
  72. // submit the new user form
  73. cy.get('button[type="submit"]').click({ force: true })
  74. })
  75. // Make sure no confirmation modal is shown
  76. handlePasswordConfirmation(admin.password)
  77. // see that the created user is in the list
  78. getUserListRow(john.userId)
  79. // see that the list of users contains the user john
  80. .contains(john.userId)
  81. .should('exist')
  82. })
  83. it('Can delete a user', function() {
  84. let testUser
  85. // create user
  86. cy.createRandomUser()
  87. .then(($user) => {
  88. testUser = $user
  89. })
  90. cy.login(admin)
  91. // ensure created user is present
  92. cy.reload().then(() => {
  93. // see that the user is in the list
  94. getUserListRow(testUser.userId).within(() => {
  95. // see that the list of users contains the user testUser
  96. cy.contains(testUser.userId).should('exist')
  97. // open the actions menu for the user
  98. cy.get('[data-cy-user-list-cell-actions]')
  99. .find('button.action-item__menutoggle')
  100. .click({ force: true })
  101. })
  102. // The "Delete account" action in the actions menu is shown and clicked
  103. cy.get('.action-item__popper .action').contains('Delete account').should('exist').click({ force: true })
  104. // And confirmation dialog accepted
  105. cy.get('.nc-generic-dialog button').contains(`Delete ${testUser.userId}`).click({ force: true })
  106. // Make sure no confirmation modal is shown
  107. handlePasswordConfirmation(admin.password)
  108. // deleted clicked the user is not shown anymore
  109. getUserListRow(testUser.userId).should('not.exist')
  110. })
  111. })
  112. })