CommonIcon.spec.ts 2.0 KB

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