|
| 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 | + |
| 23 | +import { User } from '@nextcloud/cypress' |
| 24 | +import { clearState } from './usersUtils' |
| 25 | +import { getNextcloudUserMenu, getNextcloudUserMenuToggle } from '../../support/commonUtils' |
| 26 | + |
| 27 | +const admin = new User('admin', 'admin') |
| 28 | + |
| 29 | +describe('Settings: Access levels', { testIsolation: true }, () => { |
| 30 | + beforeEach(() => { |
| 31 | + clearState() |
| 32 | + }) |
| 33 | + |
| 34 | + it('Regular users cannot see admin-level items in the Settings menu', () => { |
| 35 | + // Given I am logged in |
| 36 | + cy.createRandomUser().then(($user) => { |
| 37 | + cy.login($user) |
| 38 | + cy.visit('/') |
| 39 | + }) |
| 40 | + // I open the settings menu |
| 41 | + getNextcloudUserMenuToggle().click() |
| 42 | + |
| 43 | + getNextcloudUserMenu().find('ul').within(($el) => { |
| 44 | + // I see the settings menu is open |
| 45 | + cy.wrap($el).should('be.visible') |
| 46 | + |
| 47 | + // I see that the "Settings" item in the Settings menu is shown |
| 48 | + cy.contains('li', 'Settings').should('be.visible') |
| 49 | + // I see that the "Help" item in the Settings menu is shown |
| 50 | + cy.contains('li', 'Help').should('be.visible') |
| 51 | + // I see that the "Log out" item in the Settings menu is shown |
| 52 | + cy.contains('li', 'Log out').should('be.visible') |
| 53 | + |
| 54 | + // I see that the "Users" item in the Settings menu is NOT shown |
| 55 | + cy.contains('li', 'Users').should('not.exist') |
| 56 | + // I see that the "Administration settings" item in the Settings menu is NOT shown |
| 57 | + cy.contains('li', 'Administration settings').should('not.exist') |
| 58 | + cy.get('#admin_settings').should('not.exist') |
| 59 | + }) |
| 60 | + }) |
| 61 | + |
| 62 | + it('Regular users cannot see admin-level items on the Settings page', () => { |
| 63 | + // Given I am logged in |
| 64 | + cy.createRandomUser().then(($user) => { |
| 65 | + cy.login($user) |
| 66 | + cy.visit('/') |
| 67 | + }) |
| 68 | + |
| 69 | + // I open the settings menu |
| 70 | + getNextcloudUserMenuToggle().click() |
| 71 | + // I navigate to the settings panel |
| 72 | + getNextcloudUserMenu().find('#settings a').click() |
| 73 | + cy.url().should('match', /\/settings\/user$/) |
| 74 | + |
| 75 | + cy.get('#app-navigation').should('be.visible').within(() => { |
| 76 | + // I see the personal section is NOT shown |
| 77 | + cy.get('#app-navigation-caption-personal').should('not.exist') |
| 78 | + // I see the admin section is NOT shown |
| 79 | + cy.get('#app-navigation-caption-administration').should('not.exist') |
| 80 | + |
| 81 | + // I see that the "Personal info" entry in the settings panel is shown |
| 82 | + cy.get('[data-section-id="personal-info"]').should('exist').and('be.visible') |
| 83 | + }) |
| 84 | + }) |
| 85 | + |
| 86 | + it('Admin users can see admin-level items in the Settings menu', () => { |
| 87 | + // Given I am logged in |
| 88 | + cy.login(admin) |
| 89 | + cy.visit('/') |
| 90 | + |
| 91 | + // I open the settings menu |
| 92 | + getNextcloudUserMenuToggle().click() |
| 93 | + |
| 94 | + getNextcloudUserMenu().find('ul').within(($el) => { |
| 95 | + // I see the settings menu is open |
| 96 | + cy.wrap($el).should('be.visible') |
| 97 | + |
| 98 | + // I see that the "Personal Settings" item in the Settings menu is shown |
| 99 | + cy.contains('li', 'Personal settings').should('be.visible') |
| 100 | + // I see that the "Administration settings" item in the Settings menu is shown |
| 101 | + cy.contains('li', 'Administration settings').should('be.visible') |
| 102 | + // I see that the "Help" item in the Settings menu is shown |
| 103 | + cy.contains('li', 'Help').should('be.visible') |
| 104 | + // I see that the "Users" item in the Settings menu is shown |
| 105 | + cy.contains('li', 'Users').should('be.visible') |
| 106 | + // I see that the "Log out" item in the Settings menu is shown |
| 107 | + cy.contains('li', 'Log out').should('be.visible') |
| 108 | + }) |
| 109 | + }) |
| 110 | + |
| 111 | + it('Admin users can see admin-level items on the Settings page', () => { |
| 112 | + // Given I am logged in |
| 113 | + cy.login(admin) |
| 114 | + cy.visit('/') |
| 115 | + |
| 116 | + // I open the settings menu |
| 117 | + getNextcloudUserMenuToggle().click() |
| 118 | + // I navigate to the settings panel |
| 119 | + getNextcloudUserMenu().find('#settings a').click() |
| 120 | + cy.url().should('match', /\/settings\/user$/) |
| 121 | + |
| 122 | + cy.get('#app-navigation').should('be.visible').within(() => { |
| 123 | + // I see the personal section is shown |
| 124 | + cy.get('#app-navigation-caption-personal').should('be.visible') |
| 125 | + // I see the admin section is shown |
| 126 | + cy.get('#app-navigation-caption-administration').should('be.visible') |
| 127 | + |
| 128 | + // I see that the "Personal info" entry in the settings panel is shown |
| 129 | + cy.get('[data-section-id="personal-info"]').should('exist').and('be.visible') |
| 130 | + }) |
| 131 | + }) |
| 132 | +}) |
0 commit comments