useStickyHeader.cy.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { mountComponent } from '#cy/utils.ts'
  3. import { defineComponent, h, Fragment } from 'vue'
  4. import { useStickyHeader } from '#shared/composables/useStickyHeader.ts'
  5. const Component = defineComponent({
  6. setup() {
  7. const { headerElement, stickyStyles } = useStickyHeader()
  8. return () => {
  9. return h(Fragment, [
  10. h(
  11. 'header',
  12. {
  13. ref: headerElement,
  14. class: 'bg-red',
  15. style: ['height: 30px;', stickyStyles.value.header],
  16. },
  17. 'Header',
  18. ),
  19. h(
  20. 'main',
  21. { style: ['height: 2000px;', stickyStyles.value.body] },
  22. 'Content',
  23. ),
  24. ])
  25. }
  26. },
  27. })
  28. it('shows header when scroll is less than header height, and hides it afterwards', () => {
  29. mountComponent(Component)
  30. cy.findByRole('banner').should('be.visible')
  31. cy.scrollTo(0, 20)
  32. cy.findByRole('banner').should('be.visible')
  33. cy.scrollTo(0, 60)
  34. cy.findByRole('banner').should('not.be.visible')
  35. })
  36. it('shows header when scrolling up', () => {
  37. mountComponent(Component)
  38. cy.findByRole('banner').should('be.visible')
  39. cy.scrollTo(0, 60)
  40. cy.findByRole('banner').should('not.be.visible')
  41. cy.scrollTo(0, 20)
  42. cy.findByRole('banner').should('be.visible')
  43. })