users.cy.ts 4.4 KB

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