access-levels.cy.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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('Settings: Ensure only administrator can see the administration settings section', { testIsolation: true }, () => {
  9. beforeEach(() => {
  10. clearState()
  11. })
  12. it('Regular users cannot see admin-level items on the Settings page', () => {
  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. // I navigate to the settings panel
  21. getNextcloudUserMenu()
  22. .findByRole('link', { name: /settings/i })
  23. .click()
  24. cy.url().should('match', /\/settings\/user$/)
  25. cy.get('#app-navigation').should('be.visible').within(() => {
  26. // I see the personal section is NOT shown
  27. cy.get('#app-navigation-caption-personal').should('not.exist')
  28. // I see the admin section is NOT shown
  29. cy.get('#app-navigation-caption-administration').should('not.exist')
  30. // I see that the "Personal info" entry in the settings panel is shown
  31. cy.get('[data-section-id="personal-info"]').should('exist').and('be.visible')
  32. })
  33. })
  34. it('Admin users can see admin-level items on the Settings page', () => {
  35. // Given I am logged in
  36. cy.login(admin)
  37. cy.visit('/')
  38. // I open the settings menu
  39. getNextcloudUserMenuToggle().click()
  40. // I navigate to the settings panel
  41. getNextcloudUserMenu()
  42. .findByRole('link', { name: /Personal settings/i })
  43. .click()
  44. cy.url().should('match', /\/settings\/user$/)
  45. cy.get('#app-navigation').should('be.visible').within(() => {
  46. // I see the personal section is shown
  47. cy.get('#app-navigation-caption-personal').should('be.visible')
  48. // I see the admin section is shown
  49. cy.get('#app-navigation-caption-administration').should('be.visible')
  50. // I see that the "Personal info" entry in the settings panel is shown
  51. cy.get('[data-section-id="personal-info"]').should('exist').and('be.visible')
  52. })
  53. })
  54. })