1
0

users.cy.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 accounts', function() {
  28. beforeEach(function() {
  29. cy.listUsers().then((users) => {
  30. if ((users as string[]).includes(john.userId)) {
  31. // ensure created user is deleted
  32. cy.deleteUser(john)
  33. }
  34. })
  35. cy.login(admin)
  36. // open the User settings
  37. cy.visit('/settings/users')
  38. })
  39. it('Can create a user', function() {
  40. // open the New user modal
  41. cy.get('button#new-user-button').click()
  42. cy.get('form[data-test="form"]').within(() => {
  43. // see that the username is ""
  44. cy.get('input[data-test="username"]').should('exist').and('have.value', '')
  45. // set the username to john
  46. cy.get('input[data-test="username"]').type(john.userId)
  47. // see that the username is john
  48. cy.get('input[data-test="username"]').should('have.value', john.userId)
  49. // see that the password is ""
  50. cy.get('input[type="password"]').should('exist').and('have.value', '')
  51. // set the password to 123456
  52. cy.get('input[type="password"]').type(john.password)
  53. // see that the password is 123456
  54. cy.get('input[type="password"]').should('have.value', john.password)
  55. // submit the new user form
  56. cy.get('button[type="submit"]').click({ force: true })
  57. })
  58. // Make sure no confirmation modal is shown
  59. handlePasswordConfirmation(admin.password)
  60. // see that the created user is in the list
  61. getUserListRow(john.userId)
  62. // see that the list of users contains the user john
  63. .contains(john.userId).should('exist')
  64. })
  65. it('Can create a user with additional field data', function() {
  66. // open the New user modal
  67. cy.get('button#new-user-button').click()
  68. cy.get('form[data-test="form"]').within(() => {
  69. // set the username
  70. cy.get('input[data-test="username"]').should('exist').and('have.value', '')
  71. cy.get('input[data-test="username"]').type(john.userId)
  72. cy.get('input[data-test="username"]').should('have.value', john.userId)
  73. // set the display name
  74. cy.get('input[data-test="displayName"]').should('exist').and('have.value', '')
  75. cy.get('input[data-test="displayName"]').type('John Smith')
  76. cy.get('input[data-test="displayName"]').should('have.value', 'John Smith')
  77. // set the email
  78. cy.get('input[data-test="email"]').should('exist').and('have.value', '')
  79. cy.get('input[data-test="email"]').type('john@example.org')
  80. cy.get('input[data-test="email"]').should('have.value', 'john@example.org')
  81. // set the password
  82. cy.get('input[type="password"]').should('exist').and('have.value', '')
  83. cy.get('input[type="password"]').type(john.password)
  84. cy.get('input[type="password"]').should('have.value', john.password)
  85. // submit the new user form
  86. cy.get('button[type="submit"]').click({ force: true })
  87. })
  88. // Make sure no confirmation modal is shown
  89. handlePasswordConfirmation(admin.password)
  90. // see that the created user is in the list
  91. getUserListRow(john.userId)
  92. // see that the list of users contains the user john
  93. .contains(john.userId)
  94. .should('exist')
  95. })
  96. it('Can delete a user', function() {
  97. let testUser
  98. // create user
  99. cy.createRandomUser()
  100. .then(($user) => {
  101. testUser = $user
  102. })
  103. cy.login(admin)
  104. // ensure created user is present
  105. cy.reload().then(() => {
  106. // see that the user is in the list
  107. getUserListRow(testUser.userId).within(() => {
  108. // see that the list of users contains the user testUser
  109. cy.contains(testUser.userId).should('exist')
  110. // open the actions menu for the user
  111. cy.get('[data-cy-user-list-cell-actions]')
  112. .find('button.action-item__menutoggle')
  113. .click({ force: true })
  114. })
  115. // The "Delete account" action in the actions menu is shown and clicked
  116. cy.get('.action-item__popper .action').contains('Delete account').should('exist').click({ force: true })
  117. // And confirmation dialog accepted
  118. cy.get('.nc-generic-dialog button').contains(`Delete ${testUser.userId}`).click({ force: true })
  119. // Make sure no confirmation modal is shown
  120. handlePasswordConfirmation(admin.password)
  121. // deleted clicked the user is not shown anymore
  122. getUserListRow(testUser.userId).should('not.exist')
  123. })
  124. })
  125. })