users.cy.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /**
  2. * @copyright Copyright (c) 2023 Ferdinand Thiessen <opensource@fthiessen.de>
  3. *
  4. * @author Ferdinand Thiessen <opensource@fthiessen.de>
  5. *
  6. * @license AGPL-3.0-or-later
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /// <reference types="cypress-if" />
  23. import { User } from '@nextcloud/cypress'
  24. import { getUserListRow, handlePasswordConfirmation } from './usersUtils'
  25. const admin = new User('admin', 'admin')
  26. const john = new User('john', '123456')
  27. describe('Settings: Create and delete users', function() {
  28. before(function() {
  29. cy.login(admin)
  30. // open the User settings
  31. cy.visit('/settings/users')
  32. })
  33. beforeEach(function() {
  34. cy.login(admin)
  35. cy.listUsers().then((users) => {
  36. cy.login(admin)
  37. if ((users as string[]).includes(john.userId)) {
  38. // ensure created user is deleted
  39. cy.deleteUser(john).login(admin)
  40. // ensure deleted user is not present
  41. cy.reload().login(admin)
  42. }
  43. })
  44. })
  45. it('Can create a user', function() {
  46. // open the New user modal
  47. cy.get('button#new-user-button').click()
  48. cy.get('form[data-test="form"]').within(() => {
  49. // see that the username is ""
  50. cy.get('input[data-test="username"]').should('exist').and('have.value', '')
  51. // set the username to john
  52. cy.get('input[data-test="username"]').type(john.userId)
  53. // see that the username is john
  54. cy.get('input[data-test="username"]').should('have.value', john.userId)
  55. // see that the password is ""
  56. cy.get('input[type="password"]').should('exist').and('have.value', '')
  57. // set the password to 123456
  58. cy.get('input[type="password"]').type(john.password)
  59. // see that the password is 123456
  60. cy.get('input[type="password"]').should('have.value', john.password)
  61. // submit the new user form
  62. cy.get('button[type="submit"]').click()
  63. })
  64. // Make sure no confirmation modal is shown
  65. handlePasswordConfirmation(admin.password)
  66. // see that the created user is in the list
  67. getUserListRow(john.userId)
  68. // see that the list of users contains the user john
  69. .contains(john.userId).should('exist')
  70. })
  71. it('Can create a user with additional field data', function() {
  72. // open the New user modal
  73. cy.get('button#new-user-button').click()
  74. cy.get('form[data-test="form"]').within(() => {
  75. // set the username
  76. cy.get('input[data-test="username"]').should('exist').and('have.value', '')
  77. cy.get('input[data-test="username"]').type(john.userId)
  78. cy.get('input[data-test="username"]').should('have.value', john.userId)
  79. // set the display name
  80. cy.get('input[data-test="displayName"]').should('exist').and('have.value', '')
  81. cy.get('input[data-test="displayName"]').type('John Smith')
  82. cy.get('input[data-test="displayName"]').should('have.value', 'John Smith')
  83. // set the email
  84. cy.get('input[data-test="email"]').should('exist').and('have.value', '')
  85. cy.get('input[data-test="email"]').type('john@example.org')
  86. cy.get('input[data-test="email"]').should('have.value', 'john@example.org')
  87. // set the password
  88. cy.get('input[type="password"]').should('exist').and('have.value', '')
  89. cy.get('input[type="password"]').type(john.password)
  90. cy.get('input[type="password"]').should('have.value', john.password)
  91. // submit the new user form
  92. cy.get('button[type="submit"]').click()
  93. })
  94. // Make sure no confirmation modal is shown
  95. handlePasswordConfirmation(admin.password)
  96. // see that the created user is in the list
  97. getUserListRow(john.userId)
  98. // see that the list of users contains the user john
  99. .contains(john.userId)
  100. .should('exist')
  101. })
  102. it('Can delete a user', function() {
  103. let testUser
  104. // create user
  105. cy.createRandomUser()
  106. .then(($user) => {
  107. testUser = $user
  108. })
  109. cy.login(admin)
  110. // ensure created user is present
  111. cy.reload().then(() => {
  112. // see that the user is in the list
  113. getUserListRow(testUser.userId).within(() => {
  114. // see that the list of users contains the user testUser
  115. cy.contains(testUser.userId).should('exist')
  116. // open the actions menu for the user
  117. cy.get('[data-cy-user-list-cell-actions]')
  118. .find('button.action-item__menutoggle')
  119. .click({ force: true })
  120. })
  121. // The "Delete user" action in the actions menu is shown and clicked
  122. cy.get('.action-item__popper .action').contains('Delete user').should('exist').click({ force: true })
  123. // And confirmation dialog accepted
  124. cy.get('.oc-dialog button').contains(`Delete ${testUser.userId}`).click({ force: true })
  125. // Make sure no confirmation modal is shown
  126. handlePasswordConfirmation(admin.password)
  127. // deleted clicked the user is not shown anymore
  128. getUserListRow(testUser.userId).should('not.exist')
  129. })
  130. })
  131. })