Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cypress): Migrate header contacts menu tests from Behat to Cypress #41190

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 0 additions & 30 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1561,36 +1561,6 @@ trigger:
- pull_request
- push

---
kind: pipeline
name: acceptance-header

steps:
- name: submodules
image: ghcr.io/nextcloud/continuous-integration-alpine-git:latest
commands:
- git submodule update --init
- name: acceptance-header
image: ghcr.io/nextcloud/continuous-integration-acceptance-php8.0:latest
commands:
- tests/acceptance/run-local.sh --timeout-multiplier 10 --nextcloud-server-domain acceptance-header --selenium-server selenium:4444 allow-git-repository-modifications features/header.feature

services:
- name: selenium
image: ghcr.io/nextcloud/continuous-integration-selenium:3.141.59
environment:
# Reduce default log level for Selenium server (INFO) as it is too
# verbose.
JAVA_OPTS: -Dselenium.LOGGER.level=WARNING

trigger:
branch:
- master
- stable*
event:
- pull_request
- push

---
kind: pipeline
name: acceptance-apps
Expand Down
154 changes: 154 additions & 0 deletions cypress/e2e/core/header_contacts-menu.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/**
* @copyright Copyright (c) 2023 Ferdinand Thiessen <opensource@fthiessen.de>
*
* @author Ferdinand Thiessen <opensource@fthiessen.de>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import { User } from '@nextcloud/cypress'
import { clearState, getNextcloudHeader } from '../../support/commonUtils'

// eslint-disable-next-line n/no-extraneous-import
import randomString from 'crypto-random-string'

const admin = new User('admin', 'admin')

const getContactsMenu = () => getNextcloudHeader().find('#header-menu-contactsmenu')
const getContactsMenuToggle = () => getNextcloudHeader().find('#contactsmenu .header-menu__trigger')
const getContactsSearch = () => getContactsMenu().find('#contactsmenu__menu__search')

describe('Header: Contacts menu', { testIsolation: true }, () => {
let user: User

beforeEach(() => {
// clear user and group state
clearState()
// ensure the contacts menu is not restricted
cy.runOccCommand('config:app:set --value no core shareapi_restrict_user_enumeration_to_group')
// create a new user for testing the contacts
cy.createRandomUser().then(($user) => {
user = $user
})

// Given I am logged in as the admin
cy.login(admin)
cy.visit('/')
})

it('Other users are seen in the contacts menu', () => {
// When I open the Contacts menu
getContactsMenuToggle().click()
// I see that the Contacts menu is shown
getContactsMenu().should('exist')
// I see that the contact user in the Contacts menu is shown
getContactsMenu().contains('li.contact', user.userId).should('be.visible')
// I see that the contact "admin" in the Contacts menu is not shown
getContactsMenu().contains('li.contact', admin.userId).should('not.exist')
})

it('Just added users are seen in the contacts menu', () => {
// I create a new user
const newUserName = randomString(7)
// we can not use createRandomUser as it will invalidate the session
cy.runOccCommand(`user:add --password-from-env '${newUserName}'`, { env: { OC_PASS: '1234567' } })
// I open the Contacts menu
getContactsMenuToggle().click()
// I see that the Contacts menu is shown
getContactsMenu().should('exist')
// I see that the contact user in the Contacts menu is shown
getContactsMenu().contains('li.contact', user.userId).should('be.visible')
// I see that the contact of the new user in the Contacts menu is shown
getContactsMenu().contains('li.contact', newUserName).should('be.visible')
// I see that the contact "admin" in the Contacts menu is not shown
getContactsMenu().contains('li.contact', admin.userId).should('not.exist')
})

it('Search for other users in the contacts menu', () => {
cy.createRandomUser().then((otherUser) => {
// Given I am logged in as the admin
cy.login(admin)
cy.visit('/')

// I open the Contacts menu
getContactsMenuToggle().click()
// I see that the Contacts menu is shown
getContactsMenu().should('exist')
// I see that the contact user in the Contacts menu is shown
getContactsMenu().contains('li.contact', user.userId).should('be.visible')
// I see that the contact of the new user in the Contacts menu is shown
getContactsMenu().contains('li.contact', otherUser.userId).should('be.visible')

// I see that the Contacts menu search input is shown
getContactsSearch().should('exist')
// I search for the otherUser
getContactsSearch().type(otherUser.userId)
// I see that the contact otherUser in the Contacts menu is shown
getContactsMenu().contains('li.contact', otherUser.userId).should('be.visible')
// I see that the contact user in the Contacts menu is not shown
getContactsMenu().contains('li.contact', user.userId).should('not.exist')
// I see that the contact "admin" in the Contacts menu is not shown
getContactsMenu().contains('li.contact', admin.userId).should('not.exist')
})
})

it('Search for unknown users in the contacts menu', () => {
// I open the Contacts menu
getContactsMenuToggle().click()
// I see that the Contacts menu is shown
getContactsMenu().should('exist')
// I see that the contact user in the Contacts menu is shown
getContactsMenu().contains('li.contact', user.userId).should('be.visible')

// I see that the Contacts menu search input is shown
getContactsSearch().should('exist')
// I search for an unknown user
getContactsSearch().type('surely-unknown-user')
// I see that the no results message in the Contacts menu is shown
getContactsMenu().find('ul li').should('have.length', 0)
// I see that the contact user in the Contacts menu is not shown
getContactsMenu().contains('li.contact', user.userId).should('not.exist')
// I see that the contact "admin" in the Contacts menu is not shown
getContactsMenu().contains('li.contact', admin.userId).should('not.exist')
})

it('Users from other groups are not seen in the contacts menu when autocompletion is restricted within the same group', () => {
// I enable restricting username autocompletion to groups
cy.runOccCommand('config:app:set --value yes core shareapi_restrict_user_enumeration_to_group')
// I open the Contacts menu
getContactsMenuToggle().click()
// I see that the Contacts menu is shown
getContactsMenu().should('exist')
// I see that the contact user in the Contacts menu is not shown
getContactsMenu().contains('li.contact', user.userId).should('not.exist')
// I see that the contact "admin" in the Contacts menu is not shown
getContactsMenu().contains('li.contact', admin.userId).should('not.exist')

// I close the Contacts menu
getContactsMenuToggle().click()
// I disable restricting username autocompletion to groups
cy.runOccCommand('config:app:set --value no core shareapi_restrict_user_enumeration_to_group')
// I open the Contacts menu
getContactsMenuToggle().click()
// I see that the Contacts menu is shown
getContactsMenu().should('exist')
// I see that the contact user in the Contacts menu is shown
getContactsMenu().contains('li.contact', user.userId).should('be.visible')
// I see that the contact "admin" in the Contacts menu is not shown
getContactsMenu().contains('li.contact', admin.userId).should('not.exist')
})
})
3 changes: 2 additions & 1 deletion cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,6 @@ Cypress.Commands.add('resetUserTheming', (user?: User) => {
})

Cypress.Commands.add('runOccCommand', (command: string, options?: Partial<Cypress.ExecOptions>) => {
return cy.exec(`docker exec --user www-data nextcloud-cypress-tests-server php ./occ ${command}`, options)
const env = Object.entries(options?.env ?? {}).map(([name, value]) => `-e '${name}=${value}'`).join(' ')
return cy.exec(`docker exec --user www-data ${env} nextcloud-cypress-tests-server php ./occ ${command}`, options)
})
2 changes: 0 additions & 2 deletions tests/acceptance/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ default:
- SearchContext
- SettingsContext
- SettingsMenuContext
- ThemingAppContext
- ToastContext
filters:
tags: "~@apache"
Expand All @@ -49,7 +48,6 @@ default:
- SearchContext
- SettingsContext
- SettingsMenuContext
- ThemingAppContext
- ToastContext
filters:
tags: "@apache"
Expand Down