header_access-levels.cy.ts 4.0 KB

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