commonUtils.ts 1.9 KB

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