component.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: AGPL-3.0-or-later
  4. */
  5. import 'cypress-axe'
  6. // styles
  7. import '../../apps/theming/css/default.css'
  8. import '../../core/css/server.css'
  9. /* eslint-disable */
  10. import { mount } from '@cypress/vue2'
  11. // Example use:
  12. // cy.mount(MyComponent)
  13. Cypress.Commands.add('mount', (component, optionsOrProps) => {
  14. let instance = null
  15. const oldMounted = component?.mounted || false
  16. // Override the mounted method to expose
  17. // the component instance to cypress
  18. component.mounted = function() {
  19. // eslint-disable-next-line
  20. instance = this
  21. if (oldMounted) {
  22. oldMounted.call(instance)
  23. }
  24. }
  25. // Expose the component with cy.get('@component')
  26. return mount(component, optionsOrProps).then(() => {
  27. return cy.wrap(instance).as('component')
  28. })
  29. })
  30. Cypress.Commands.add('mockInitialState', (app: string, key: string, value: any) => {
  31. cy.document().then(($document) => {
  32. const input = $document.createElement('input')
  33. input.setAttribute('type', 'hidden')
  34. input.setAttribute('id', `initial-state-${app}-${key}`)
  35. input.setAttribute('value', btoa(JSON.stringify(value)))
  36. $document.body.appendChild(input)
  37. })
  38. })
  39. Cypress.Commands.add('unmockInitialState', (app?: string, key?: string) => {
  40. cy.document().then(($document) => {
  41. $document.querySelectorAll('body > input[type="hidden"]' + (app ? `[id="initial-state-${app}-${key}"]` : ''))
  42. .forEach((node) => $document.body.removeChild(node))
  43. })
  44. })