useElementScroll.spec.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { ref } from 'vue'
  3. import { useElementScroll } from '#desktop/composables/useElementScroll.ts'
  4. describe('useElementScroll', () => {
  5. let container: HTMLDivElement
  6. beforeEach(() => {
  7. container = document.createElement('div')
  8. container.style.height = '2000px'
  9. container.style.overflow = 'auto'
  10. document.body.appendChild(container)
  11. const content = document.createElement('div')
  12. content.style.height = '500px'
  13. container.appendChild(content)
  14. })
  15. afterEach(() => {
  16. document.body.removeChild(container)
  17. })
  18. it.todo('detects scrolling down', async () => {
  19. const { isScrollingDown } = useElementScroll(ref(container))
  20. container.scrollTop = 100 // Scroll down
  21. container.dispatchEvent(new Event('scroll'))
  22. expect(isScrollingDown.value).toBe(true)
  23. })
  24. it.todo('detects scrolling up', async () => {
  25. const { isScrollingDown } = useElementScroll(ref(container))
  26. container.scrollTop = 100 // Scroll down
  27. container.dispatchEvent(new Event('scroll'))
  28. expect(isScrollingDown.value).toBe(true)
  29. })
  30. it.todo('detects scrolling after start threshold', async () => {})
  31. it('detects reaching top', async () => {
  32. const { reachedTop } = useElementScroll(ref(container))
  33. container.scrollTop = 500
  34. container.scrollTop = 0
  35. container.dispatchEvent(new Event('scroll'))
  36. expect(reachedTop.value).toBe(true)
  37. })
  38. it('detects reaching bottom', async () => {
  39. const { reachedBottom } = useElementScroll(ref(container))
  40. container.scrollTop = container.clientHeight
  41. container.dispatchEvent(new Event('scroll'))
  42. expect(reachedBottom.value).toBe(true)
  43. })
  44. })