users_disable.cy.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 } from './usersUtils'
  24. import { clearState } from '../../support/commonUtils'
  25. const admin = new User('admin', 'admin')
  26. describe('Settings: Disable and enable users', function() {
  27. let testUser: User
  28. beforeEach(function() {
  29. clearState()
  30. cy.createRandomUser().then(($user) => {
  31. testUser = $user
  32. })
  33. cy.login(admin)
  34. // open the User settings
  35. cy.visit('/settings/users')
  36. })
  37. // Not guranteed to run but would be nice to cleanup
  38. after(() => {
  39. cy.deleteUser(testUser)
  40. })
  41. it('Can disable the user', function() {
  42. // ensure user is enabled
  43. cy.enableUser(testUser)
  44. // see that the user is in the list of active users
  45. getUserListRow(testUser.userId).within(() => {
  46. // see that the list of users contains the user testUser
  47. cy.contains(testUser.userId).should('exist')
  48. // open the actions menu for the user
  49. cy.get('[data-cy-user-list-cell-actions] button.action-item__menutoggle').click({ scrollBehavior: 'center' })
  50. })
  51. // The "Disable user" action in the actions menu is shown and clicked
  52. cy.get('.action-item__popper .action').contains('Disable user').should('exist').click()
  53. // When clicked the section is not shown anymore
  54. getUserListRow(testUser.userId).should('not.exist')
  55. // But the disabled user section now exists
  56. cy.get('#disabled').should('exist')
  57. // Open disabled users section
  58. cy.get('#disabled a').click()
  59. cy.url().should('match', /\/disabled/)
  60. // The list of disabled users should now contain the user
  61. getUserListRow(testUser.userId).should('exist')
  62. })
  63. it('Can enable the user', function() {
  64. // ensure user is disabled
  65. cy.enableUser(testUser, false).reload()
  66. // Open disabled users section
  67. cy.get('#disabled a').click()
  68. cy.url().should('match', /\/disabled/)
  69. // see that the user is in the list of active users
  70. getUserListRow(testUser.userId).within(() => {
  71. // see that the list of disabled users contains the user testUser
  72. cy.contains(testUser.userId).should('exist')
  73. // open the actions menu for the user
  74. cy.get('[data-cy-user-list-cell-actions] button.action-item__menutoggle').click({ scrollBehavior: 'center' })
  75. })
  76. // The "Enable user" action in the actions menu is shown and clicked
  77. cy.get('.action-item__popper .action').contains('Enable user').should('exist').click()
  78. // When clicked the section is not shown anymore
  79. cy.get('#disabled').should('not.exist')
  80. // Make sure it is still gone after the reload reload
  81. cy.reload().login(admin)
  82. cy.get('#disabled').should('not.exist')
  83. })
  84. })