You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

users_modify.cy.ts 9.8KB

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