Skip to content

Commit bfc8b0b

Browse files
committed
chore(cypress): Migrate access-level tests from Behat to Cypress as this are UI tests
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent fe471da commit bfc8b0b

File tree

5 files changed

+155
-55
lines changed

5 files changed

+155
-55
lines changed

.drone.yml

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,36 +1561,6 @@ trigger:
15611561
- pull_request
15621562
- push
15631563

1564-
---
1565-
kind: pipeline
1566-
name: acceptance-access-levels
1567-
1568-
steps:
1569-
- name: submodules
1570-
image: ghcr.io/nextcloud/continuous-integration-alpine-git:latest
1571-
commands:
1572-
- git submodule update --init
1573-
- name: acceptance-access-levels
1574-
image: ghcr.io/nextcloud/continuous-integration-acceptance-php8.0:latest
1575-
commands:
1576-
- tests/acceptance/run-local.sh --timeout-multiplier 10 --nextcloud-server-domain acceptance-access-levels --selenium-server selenium:4444 allow-git-repository-modifications features/access-levels.feature
1577-
1578-
services:
1579-
- name: selenium
1580-
image: ghcr.io/nextcloud/continuous-integration-selenium:3.141.59
1581-
environment:
1582-
# Reduce default log level for Selenium server (INFO) as it is too
1583-
# verbose.
1584-
JAVA_OPTS: -Dselenium.LOGGER.level=WARNING
1585-
1586-
trigger:
1587-
branch:
1588-
- master
1589-
- stable*
1590-
event:
1591-
- pull_request
1592-
- push
1593-
15941564
---
15951565
kind: pipeline
15961566
name: acceptance-header

cypress/e2e/login/login.cy.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { User } from '@nextcloud/cypress'
2+
import { getNextcloudUserMenu, getNextcloudUserMenuToggle } from '../../support/commonUtils'
23

34
describe('Login', () => {
45
let user: User
@@ -137,8 +138,8 @@ describe('Login', () => {
137138
cy.url().should('match', /apps\/dashboard(\/|$)/)
138139

139140
// When click logout
140-
cy.get('#user-menu > button').should('exist').click()
141-
cy.get('#logout a').should('contain.text', 'Log out').click()
141+
getNextcloudUserMenuToggle().should('exist').click()
142+
getNextcloudUserMenu().contains('a', 'Log out').click()
142143

143144
// Then I see that the current page is the Login page
144145
cy.url().should('match', /\/login/)
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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+
})

cypress/support/commonUtils.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Get the header navigation bar
3+
*/
4+
export function getNextcloudHeader() {
5+
return cy.get('#header')
6+
}
7+
8+
/**
9+
* Get user menu in the header navigation bar
10+
*/
11+
export function getNextcloudUserMenu() {
12+
return getNextcloudHeader().find('#user-menu')
13+
}
14+
15+
/**
16+
* Get the user menu toggle in the header navigation bar
17+
*/
18+
export function getNextcloudUserMenuToggle() {
19+
return getNextcloudUserMenu().find('.header-menu__trigger').should('have.length', 1)
20+
}

tests/acceptance/features/access-levels.feature

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)