commonUtils.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: AGPL-3.0-or-later
  4. */
  5. /**
  6. * Get the header navigation bar
  7. */
  8. export function getNextcloudHeader() {
  9. return cy.get('#header')
  10. }
  11. /**
  12. * Get user menu in the header navigation bar
  13. */
  14. export function getNextcloudUserMenu() {
  15. return getNextcloudHeader().find('#user-menu')
  16. }
  17. /**
  18. * Get the user menu toggle in the header navigation bar
  19. */
  20. export function getNextcloudUserMenuToggle() {
  21. return getNextcloudUserMenu().find('.header-menu__trigger').should('have.length', 1)
  22. }
  23. /**
  24. * Helper function ensure users and groups in this tests have a clean state
  25. * Deletes all users (except admin) and groups
  26. */
  27. export function clearState() {
  28. // cleanup ignoring any failures
  29. cy.runOccCommand('group:list --output=json').then(($result) => {
  30. const groups = Object.keys(JSON.parse($result.stdout)).filter((name) => name !== 'admin')
  31. groups.forEach((groupID) => cy.runOccCommand(`group:delete '${groupID}'`))
  32. })
  33. cy.runOccCommand('user:list --output=json').then(($result) => {
  34. const users = Object.keys(JSON.parse($result.stdout)).filter((name) => name !== 'admin')
  35. users.forEach((userID) => cy.runOccCommand(`user:delete '${userID}'`))
  36. })
  37. }
  38. /**
  39. * Install the test app
  40. */
  41. export function installTestApp() {
  42. const testAppPath = 'cypress/fixtures/testapp'
  43. cy.runOccCommand('-V').then((output) => {
  44. const version = output.stdout.match(/(\d\d+)\.\d+\.\d+/)?.[1]
  45. cy.wrap(version).should('not.be.undefined')
  46. cy.exec(`docker cp '${testAppPath}' nextcloud-cypress-tests-server:/var/www/html/apps`, { log: true })
  47. cy.exec(`docker exec nextcloud-cypress-tests-server sed -i -e 's|-version="[0-9]\\+|-version="${version}|g' apps/testapp/appinfo/info.xml`)
  48. cy.runOccCommand('app:enable --force testapp')
  49. })
  50. }
  51. /**
  52. * Remove the test app
  53. */
  54. export function uninstallTestApp() {
  55. cy.runOccCommand('app:remove testapp', { failOnNonZeroExit: false })
  56. cy.exec('docker exec nextcloud-cypress-tests-server rm -fr apps/testapp/appinfo/info.xml')
  57. }