header_access-levels.cy.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 { clearState, getNextcloudUserMenu, getNextcloudUserMenuToggle } from '../../support/commonUtils'
  24. const admin = new User('admin', 'admin')
  25. describe('Header: Ensure regular users do not have admin settings in the Settings menu', { testIsolation: true }, () => {
  26. beforeEach(() => {
  27. clearState()
  28. })
  29. it('Regular users can see basic items in the Settings menu', () => {
  30. // Given I am logged in
  31. cy.createRandomUser().then(($user) => {
  32. cy.login($user)
  33. cy.visit('/')
  34. })
  35. // I open the settings menu
  36. getNextcloudUserMenuToggle().click()
  37. getNextcloudUserMenu().find('ul').within(($el) => {
  38. // I see the settings menu is open
  39. cy.wrap($el).should('be.visible')
  40. // I see that the Settings menu has only 6 items
  41. cy.get('li').should('have.length', 6)
  42. // I see that the "View profile" item in the Settings menu is shown
  43. cy.contains('li', 'View profile').should('be.visible')
  44. // I see that the "Set status" item in the Settings menu is shown
  45. cy.contains('li', 'Set status').should('be.visible')
  46. // I see that the "Appearance and accessibility" item in the Settings menu is shown
  47. cy.contains('li', 'Appearance and accessibility').should('be.visible')
  48. // I see that the "Settings" item in the Settings menu is shown
  49. cy.contains('li', 'Settings').should('be.visible')
  50. // I see that the "Help" item in the Settings menu is shown
  51. cy.contains('li', 'Help').should('be.visible')
  52. // I see that the "Log out" item in the Settings menu is shown
  53. cy.contains('li', 'Log out').should('be.visible')
  54. })
  55. })
  56. it('Regular users cannot see admin-level items in the Settings menu', () => {
  57. // Given I am logged in
  58. cy.createRandomUser().then(($user) => {
  59. cy.login($user)
  60. cy.visit('/')
  61. })
  62. // I open the settings menu
  63. getNextcloudUserMenuToggle().click()
  64. getNextcloudUserMenu().find('ul').within(($el) => {
  65. // I see the settings menu is open
  66. cy.wrap($el).should('be.visible')
  67. // I see that the "Users" item in the Settings menu is NOT shown
  68. cy.contains('li', 'Users').should('not.exist')
  69. // I see that the "Administration settings" item in the Settings menu is NOT shown
  70. cy.contains('li', 'Administration settings').should('not.exist')
  71. cy.get('#admin_settings').should('not.exist')
  72. })
  73. })
  74. it('Admin users can see admin-level items in the Settings menu', () => {
  75. // Given I am logged in
  76. cy.login(admin)
  77. cy.visit('/')
  78. // I open the settings menu
  79. getNextcloudUserMenuToggle().click()
  80. getNextcloudUserMenu().find('ul').within(($el) => {
  81. // I see the settings menu is open
  82. cy.wrap($el).should('be.visible')
  83. // I see that the Settings menu has only 9 items
  84. cy.get('li').should('have.length', 9)
  85. // I see that the "Set status" item in the Settings menu is shown
  86. cy.contains('li', 'View profile').should('be.visible')
  87. // I see that the "Set status" item in the Settings menu is shown
  88. cy.contains('li', 'Set status').should('be.visible')
  89. // I see that the "Appearance and accessibility" item in the Settings menu is shown
  90. cy.contains('li', 'Appearance and accessibility').should('be.visible')
  91. // I see that the "Personal Settings" item in the Settings menu is shown
  92. cy.contains('li', 'Personal settings').should('be.visible')
  93. // I see that the "Administration settings" item in the Settings menu is shown
  94. cy.contains('li', 'Administration settings').should('be.visible')
  95. // I see that the "Apps" item in the Settings menu is shown
  96. cy.contains('li', 'Apps').should('be.visible')
  97. // I see that the "Users" item in the Settings menu is shown
  98. cy.contains('li', 'Users').should('be.visible')
  99. // I see that the "Help" item in the Settings menu is shown
  100. cy.contains('li', 'Help').should('be.visible')
  101. // I see that the "Log out" item in the Settings menu is shown
  102. cy.contains('li', 'Log out').should('be.visible')
  103. })
  104. })
  105. })