iconQueries.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import {
  3. buildQueries,
  4. queryAllByAttribute,
  5. getQueriesForElement,
  6. type Matcher,
  7. type BoundFunctions,
  8. } from '@testing-library/vue'
  9. export const queryAllByIconName = (
  10. container: HTMLElement,
  11. matcher: Matcher,
  12. ) => {
  13. let id = matcher
  14. if (typeof matcher === 'string') {
  15. id = `#icon-${matcher}`
  16. }
  17. return queryAllByAttribute(`href`, container, id).map(
  18. (el) => el.parentElement as HTMLElement,
  19. )
  20. }
  21. export const [
  22. queryByIconName,
  23. getAllByIconName,
  24. getByIconName,
  25. findAllByIconName,
  26. findByIconName,
  27. ] = buildQueries(
  28. queryAllByIconName,
  29. (_, matcher) => `Several icons with the "${matcher}" matcher were found`,
  30. (_, matcher) => `No icons with the "${matcher}" search were found`,
  31. )
  32. export default function buildIconsQueries(container: HTMLElement) {
  33. const queryFns = {
  34. queryByIconName,
  35. getAllByIconName,
  36. getByIconName,
  37. findAllByIconName,
  38. findByIconName,
  39. queryAllByIconName,
  40. } as const
  41. return getQueriesForElement(container, queryFns as any) as BoundFunctions<
  42. typeof queryFns
  43. >
  44. }