CommonSectionMenuLink.spec.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. import { renderComponent } from '@tests/support/components'
  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('mobile-chevron-right')).toBeInTheDocument()
  22. })
  23. it('has an icon, if provided', () => {
  24. const view = renderMenuItem({
  25. link: '/',
  26. icon: 'mobile-home',
  27. })
  28. expect(view.getByIconName('mobile-home')).toBeInTheDocument()
  29. })
  30. it('has an icon with a background', () => {
  31. const view = renderMenuItem({
  32. link: '/',
  33. iconBg: 'bg-red',
  34. icon: 'mobile-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: 'mobile-home', fixedSize: { width: 40, height: 40 } },
  44. })
  45. const icon = view.getByIconName('mobile-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. })