CommonSectionMenuLink.spec.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { renderComponent } from '#tests/support/components/index.ts'
  3. import CommonSectionMenuLink from '../CommonSectionMenuLink.vue'
  4. const renderMenuItem = (props: any = {}, slots: any = {}) => {
  5. return renderComponent(CommonSectionMenuLink, {
  6. props,
  7. slots,
  8. shallow: false,
  9. router: true,
  10. store: true,
  11. })
  12. }
  13. describe('rendering item for section', () => {
  14. it('renders a link, if link is provided', () => {
  15. const view = renderMenuItem({
  16. link: '/',
  17. label: 'Test Title',
  18. })
  19. expect(view.getByTestId('section-menu-link').tagName).toBe('A')
  20. expect(view.getByText('Test Title')).toBeInTheDocument()
  21. expect(view.getByIconName('chevron-right')).toBeInTheDocument()
  22. })
  23. it('has an icon, if provided', () => {
  24. const view = renderMenuItem({
  25. link: '/',
  26. icon: 'home',
  27. })
  28. expect(view.getByIconName('home')).toBeInTheDocument()
  29. })
  30. it('has an icon with a background', () => {
  31. const view = renderMenuItem({
  32. link: '/',
  33. iconBg: 'bg-red',
  34. icon: 'home',
  35. })
  36. const icon = view.getByTestId('wrapper-icon')
  37. expect(icon).toHaveClass('bg-red')
  38. expect(icon).toHaveClass('rounded-lg')
  39. })
  40. it('accepts icon as object', () => {
  41. const view = renderMenuItem({
  42. link: '/',
  43. icon: { name: 'home', fixedSize: { width: 40, height: 40 } },
  44. })
  45. const icon = view.getByIconName('home')
  46. expect(icon).toBeInTheDocument()
  47. expect(icon).toHaveAttribute('width', '40')
  48. expect(icon).toHaveAttribute('height', '40')
  49. })
  50. it("draws information, if it's provided", () => {
  51. const view = renderMenuItem({
  52. link: '/',
  53. information: 'Test Information',
  54. })
  55. expect(view.getByText('Test Information')).toBeInTheDocument()
  56. })
  57. it('draws right slot, if provided', () => {
  58. const view = renderMenuItem(
  59. {
  60. link: '/',
  61. },
  62. {
  63. right: 'Test Information',
  64. },
  65. )
  66. expect(view.getByText('Test Information')).toBeInTheDocument()
  67. })
  68. it('draws default slot, if provided', () => {
  69. const view = renderMenuItem(
  70. { label: 'Some Title', link: '/' },
  71. {
  72. default: 'Slot Title',
  73. },
  74. )
  75. // slor overrides prop
  76. expect(view.queryByText('Some Title')).not.toBeInTheDocument()
  77. expect(view.getByText('Slot Title')).toBeInTheDocument()
  78. })
  79. })