useStickyHeader.spec.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { flushPromises } from '@vue/test-utils'
  3. import type { Ref } from 'vue'
  4. import { ref } from 'vue'
  5. import { useStickyHeader } from '../useStickyHeader.ts'
  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 element', () => {
  15. const element = ref()
  16. const { headerElement } = useStickyHeader([], element)
  17. expect(headerElement).toBe(element)
  18. })
  19. test('reevaluates styles when dependencies change', async () => {
  20. const div = document.createElement('div')
  21. Object.defineProperty(div, 'clientHeight', { value: 100 })
  22. const element = ref(div) as Ref<HTMLElement>
  23. const dependency = ref(0)
  24. const { stickyStyles } = useStickyHeader([dependency], element)
  25. expect(stickyStyles.value).toEqual({})
  26. dependency.value = 1
  27. await flushPromises()
  28. expect(stickyStyles.value).toEqual({
  29. body: {
  30. marginTop: '100px',
  31. },
  32. header: {
  33. ...fixedHeaderStyle,
  34. transform: 'translateY(0px)',
  35. },
  36. })
  37. })