useStickyHeader.spec.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { flushPromises } from '@vue/test-utils'
  3. import { ref } from 'vue'
  4. import { useStickyHeader } from '../useStickyHeader.ts'
  5. import type { Ref } from 'vue'
  6. const fixedHeaderStyle = {
  7. left: '0',
  8. position: 'fixed',
  9. right: '0',
  10. top: '0',
  11. transition: 'transform 0.3s ease-in-out',
  12. zIndex: 9,
  13. }
  14. test('can pass down custom html element', () => {
  15. const header = document.createElement('header')
  16. const element = ref(header)
  17. const { headerElement } = useStickyHeader([], element)
  18. expect(headerElement.value).toBe(header)
  19. })
  20. test('reevaluates styles when dependencies change', async () => {
  21. const div = document.createElement('div')
  22. Object.defineProperty(div, 'clientHeight', { value: 100 })
  23. const element = ref(div) as Ref<HTMLElement>
  24. const dependency = ref(0)
  25. const { stickyStyles } = useStickyHeader([dependency], element)
  26. expect(stickyStyles.value).toEqual({})
  27. dependency.value = 1
  28. await flushPromises()
  29. expect(stickyStyles.value).toEqual({
  30. body: {
  31. marginTop: '100px',
  32. },
  33. header: {
  34. ...fixedHeaderStyle,
  35. transform: 'translateY(0px)',
  36. },
  37. })
  38. })