users_modify.cy.ts 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /**
  2. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: AGPL-3.0-or-later
  4. */
  5. import { User } from '@nextcloud/cypress'
  6. import { getUserListRow, handlePasswordConfirmation, toggleEditButton, waitLoading } from './usersUtils'
  7. import { clearState } from '../../support/commonUtils'
  8. const admin = new User('admin', 'admin')
  9. describe('Settings: Change user properties', function() {
  10. let user: User
  11. beforeEach(function() {
  12. clearState()
  13. cy.createRandomUser().then(($user) => { user = $user })
  14. cy.login(admin)
  15. })
  16. it('Can change the display name', function() {
  17. // open the User settings as admin
  18. cy.visit('/settings/users')
  19. // toggle edit button into edit mode
  20. toggleEditButton(user, true)
  21. getUserListRow(user.userId).within(() => {
  22. // set the display name
  23. cy.get('[data-cy-user-list-input-displayname]').should('exist').and('have.value', user.userId)
  24. cy.get('[data-cy-user-list-input-displayname]').clear()
  25. cy.get('[data-cy-user-list-input-displayname]').type('John Doe')
  26. cy.get('[data-cy-user-list-input-displayname]').should('have.value', 'John Doe')
  27. cy.get('[data-cy-user-list-input-displayname] ~ button').click()
  28. // Make sure no confirmation modal is shown
  29. handlePasswordConfirmation(admin.password)
  30. // see that the display name cell is done loading
  31. waitLoading('[data-cy-user-list-input-displayname]')
  32. })
  33. // Success message is shown
  34. cy.get('.toastify.toast-success').contains(/Display.+name.+was.+successfully.+changed/i).should('exist')
  35. })
  36. it('Can change the password', function() {
  37. // open the User settings as admin
  38. cy.visit('/settings/users')
  39. // toggle edit button into edit mode
  40. toggleEditButton(user, true)
  41. getUserListRow(user.userId).within(() => {
  42. // see that the password of user is ""
  43. cy.get('[data-cy-user-list-input-password]').should('exist').and('have.value', '')
  44. // set the password for user to 123456
  45. cy.get('[data-cy-user-list-input-password]').type('123456')
  46. // When I set the password for user to 123456
  47. cy.get('[data-cy-user-list-input-password]').should('have.value', '123456')
  48. cy.get('[data-cy-user-list-input-password] ~ button').click()
  49. // Make sure no confirmation modal is shown
  50. handlePasswordConfirmation(admin.password)
  51. // see that the password cell for user is done loading
  52. waitLoading('[data-cy-user-list-input-password]')
  53. // password input is emptied on change
  54. cy.get('[data-cy-user-list-input-password]').should('have.value', '')
  55. })
  56. // Success message is shown
  57. cy.get('.toastify.toast-success').contains(/Password.+successfully.+changed/i).should('exist')
  58. })
  59. it('Can change the email address', function() {
  60. // open the User settings as admin
  61. cy.visit('/settings/users')
  62. // toggle edit button into edit mode
  63. toggleEditButton(user, true)
  64. getUserListRow(user.userId).find('[data-cy-user-list-cell-email]').within(() => {
  65. // see that the email of user is ""
  66. cy.get('input').should('exist').and('have.value', '')
  67. // set the email for user to mymail@example.com
  68. cy.get('input').type('mymail@example.com')
  69. // When I set the password for user to mymail@example.com
  70. cy.get('input').should('have.value', 'mymail@example.com')
  71. cy.get('input ~ button').click()
  72. // Make sure no confirmation modal is shown
  73. handlePasswordConfirmation(admin.password)
  74. // see that the password cell for user is done loading
  75. waitLoading('[data-cy-user-list-input-email]')
  76. })
  77. // Success message is shown
  78. cy.get('.toastify.toast-success').contains(/Email.+successfully.+changed/i).should('exist')
  79. })
  80. it('Can change the user quota to a predefined one', function() {
  81. // open the User settings as admin
  82. cy.visit('/settings/users')
  83. // toggle edit button into edit mode
  84. toggleEditButton(user, true)
  85. getUserListRow(user.userId).find('[data-cy-user-list-cell-quota]').scrollIntoView()
  86. getUserListRow(user.userId).find('[data-cy-user-list-cell-quota] [data-cy-user-list-input-quota]').within(() => {
  87. // see that the quota of user is unlimited
  88. cy.get('.vs__selected').should('exist').and('contain.text', 'Unlimited')
  89. // Open the quota selector
  90. cy.get('[role="combobox"]').click({ force: true })
  91. // see that there are default options for the quota
  92. cy.get('li').then(($options) => {
  93. expect($options).to.have.length(5)
  94. cy.wrap($options).contains('Default quota')
  95. cy.wrap($options).contains('Unlimited')
  96. cy.wrap($options).contains('1 GB')
  97. cy.wrap($options).contains('10 GB')
  98. // select 5 GB
  99. cy.wrap($options).contains('5 GB').click({ force: true })
  100. // Make sure no confirmation modal is shown
  101. handlePasswordConfirmation(admin.password)
  102. })
  103. // see that the quota of user is 5 GB
  104. cy.get('.vs__selected').should('exist').and('contain.text', '5 GB')
  105. })
  106. // see that the changes are loading
  107. waitLoading('[data-cy-user-list-input-quota]')
  108. // finish editing the user
  109. toggleEditButton(user, false)
  110. // I see that the quota was set on the backend
  111. cy.runOccCommand(`user:info --output=json '${user.userId}'`).then(($result) => {
  112. expect($result.code).to.equal(0)
  113. const info = JSON.parse($result.stdout)
  114. expect(info?.quota).to.equal('5 GB')
  115. })
  116. })
  117. it('Can change the user quota to a custom value', function() {
  118. // open the User settings as admin
  119. cy.visit('/settings/users')
  120. // toggle edit button into edit mode
  121. toggleEditButton(user, true)
  122. getUserListRow(user.userId).find('[data-cy-user-list-cell-quota]').scrollIntoView()
  123. getUserListRow(user.userId).find('[data-cy-user-list-cell-quota]').within(() => {
  124. // see that the quota of user is unlimited
  125. cy.get('.vs__selected').should('exist').and('contain.text', 'Unlimited')
  126. // set the quota to 4 MB
  127. cy.get('[data-cy-user-list-input-quota] input').type('4 MB{enter}')
  128. // Make sure no confirmation modal is shown
  129. handlePasswordConfirmation(admin.password)
  130. // see that the quota of user is 4 MB
  131. // TODO: Enable this after the file size handling is fixed
  132. // cy.get('.vs__selected').should('exist').and('contain.text', '4 MB')
  133. // see that the changes are loading
  134. waitLoading('[data-cy-user-list-input-quota]')
  135. })
  136. // finish editing the user
  137. toggleEditButton(user, false)
  138. // I see that the quota was set on the backend
  139. cy.runOccCommand(`user:info --output=json '${user.userId}'`).then(($result) => {
  140. expect($result.code).to.equal(0)
  141. // TODO: Enable this after the file size handling is fixed!!!!!!
  142. // const info = JSON.parse($result.stdout)
  143. // expect(info?.quota).to.equal('4 MB')
  144. })
  145. })
  146. it('Can set manager of a user', function() {
  147. // create the manager
  148. let manager: User
  149. cy.createRandomUser().then(($user) => { manager = $user })
  150. // open the User settings as admin
  151. cy.login(admin)
  152. cy.visit('/settings/users')
  153. // toggle edit button into edit mode
  154. toggleEditButton(user, true)
  155. getUserListRow(user.userId)
  156. .find('[data-cy-user-list-cell-manager]')
  157. .scrollIntoView()
  158. getUserListRow(user.userId).find('[data-cy-user-list-cell-manager]').within(() => {
  159. // see that the user has no manager
  160. cy.get('.vs__selected').should('not.exist')
  161. // Open the dropdown menu
  162. cy.get('[role="combobox"]').click({ force: true })
  163. // select the manager
  164. cy.contains('li', manager.userId).click({ force: true })
  165. // Handle password confirmation on time out
  166. handlePasswordConfirmation(admin.password)
  167. // see that the user has a manager set
  168. cy.get('.vs__selected').should('exist').and('contain.text', manager.userId)
  169. })
  170. // see that the changes are loading
  171. waitLoading('[data-cy-user-list-input-manager]')
  172. // finish editing the user
  173. toggleEditButton(user, false)
  174. // validate the manager is set
  175. cy.getUserData(user).then(($result) => expect($result.body).to.contain(`<manager>${manager.userId}</manager>`))
  176. })
  177. it('Can make user a subadmin of a group', function() {
  178. // create a group
  179. const groupName = 'userstestgroup'
  180. cy.runOccCommand(`group:add '${groupName}'`)
  181. // open the User settings as admin
  182. cy.visit('/settings/users')
  183. // toggle edit button into edit mode
  184. toggleEditButton(user, true)
  185. getUserListRow(user.userId).find('[data-cy-user-list-cell-subadmins]').scrollIntoView()
  186. getUserListRow(user.userId).find('[data-cy-user-list-cell-subadmins]').within(() => {
  187. // see that the user is no subadmin
  188. cy.get('.vs__selected').should('not.exist')
  189. // Open the dropdown menu
  190. cy.get('[role="combobox"]').click({ force: true })
  191. // select the group
  192. cy.contains('li', groupName).click({ force: true })
  193. // handle password confirmation on time out
  194. handlePasswordConfirmation(admin.password)
  195. // see that the user is subadmin of the group
  196. cy.get('.vs__selected').should('exist').and('contain.text', groupName)
  197. })
  198. waitLoading('[data-cy-user-list-input-subadmins]')
  199. // finish editing the user
  200. toggleEditButton(user, false)
  201. // I see that the quota was set on the backend
  202. cy.getUserData(user).then(($response) => {
  203. expect($response.status).to.equal(200)
  204. const dom = (new DOMParser()).parseFromString($response.body, 'text/xml')
  205. expect(dom.querySelector('subadmin element')?.textContent).to.contain(groupName)
  206. })
  207. })
  208. })