users_disable.cy.ts 2.7 KB

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