CommonIcon.spec.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. import { renderComponent } from '@tests/support/components'
  3. import CommonIcon from '../CommonIcon.vue'
  4. describe('CommonIcon.vue', () => {
  5. it('renders icon', () => {
  6. const wrapper = renderComponent(CommonIcon, {
  7. props: { name: 'mobile-chevron-left' },
  8. })
  9. expect(wrapper.getByIconName('mobile-chevron-left')).toHaveClass('icon')
  10. expect(wrapper.getByIconName('mobile-chevron-left')).toHaveAttribute(
  11. 'aria-label',
  12. 'mobile-chevron-left',
  13. )
  14. })
  15. it('renders icon with animation', () => {
  16. const wrapper = renderComponent(CommonIcon, {
  17. props: { name: 'mobile-settings', animation: 'spin' },
  18. })
  19. expect(wrapper.getByIconName('mobile-settings')).toHaveClass('animate-spin')
  20. })
  21. it('renders icon with small size', () => {
  22. const wrapper = renderComponent(CommonIcon, {
  23. props: { name: 'mobile-settings', size: 'small' },
  24. })
  25. expect(wrapper.getByIconName('mobile-settings')).toHaveAttribute(
  26. 'width',
  27. '20',
  28. )
  29. expect(wrapper.getByIconName('mobile-settings')).toHaveAttribute(
  30. 'height',
  31. '20',
  32. )
  33. })
  34. it('renders a decorative icon', () => {
  35. const wrapper = renderComponent(CommonIcon, {
  36. props: { name: 'mobile-settings', decorative: true },
  37. })
  38. expect(wrapper.getByIconName('mobile-settings')).toHaveAttribute(
  39. 'aria-hidden',
  40. 'true',
  41. )
  42. expect(wrapper.getByIconName('mobile-settings')).not.toHaveAttribute(
  43. 'aria-label',
  44. )
  45. })
  46. it('triggers click handler of icon', async () => {
  47. const wrapper = renderComponent(CommonIcon, {
  48. props: { name: 'mobile-puzzle' },
  49. })
  50. await wrapper.events.click(wrapper.getByIconName('mobile-puzzle'))
  51. expect(wrapper.emitted().click).toHaveLength(1)
  52. })
  53. it('provides a label for assistive technologies', async () => {
  54. const wrapper = renderComponent(CommonIcon, {
  55. props: { name: 'mobile-logo' },
  56. })
  57. expect(wrapper.getByIconName('mobile-logo')).toHaveAccessibleName(
  58. 'mobile-logo',
  59. )
  60. await wrapper.rerender({
  61. label: 'Product Logo',
  62. })
  63. expect(wrapper.getByIconName('mobile-logo')).toHaveAccessibleName(
  64. 'Product Logo',
  65. )
  66. })
  67. })