CommonBreadcrumb.spec.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { renderComponent } from '#tests/support/components/index.ts'
  3. import CommonBreadcrumb from '../CommonBreadcrumb.vue'
  4. describe('breadcrumb', () => {
  5. it('renders the breadcrumb', async () => {
  6. const view = renderComponent(CommonBreadcrumb, {
  7. props: {
  8. items: [
  9. {
  10. label: 'Dashboard',
  11. route: '/',
  12. },
  13. {
  14. label: 'Settings',
  15. },
  16. ],
  17. },
  18. slots: {
  19. trailing: 'trailing slot',
  20. },
  21. router: true,
  22. })
  23. const link = view.getByRole('link')
  24. expect(link).toHaveTextContent('Dashboard')
  25. expect(link).toHaveAttribute('href', '/desktop/')
  26. expect(view.getByText('Settings')).toBeInTheDocument()
  27. expect(view.getByText('trailing slot')).toBeInTheDocument()
  28. })
  29. it('renders icons', async () => {
  30. const view = renderComponent(CommonBreadcrumb, {
  31. props: {
  32. items: [
  33. {
  34. label: 'Dashboard',
  35. route: '/',
  36. icon: 'eye',
  37. },
  38. {
  39. label: 'Settings',
  40. },
  41. ],
  42. },
  43. router: true,
  44. })
  45. const icon = view.getByIconName('eye')
  46. expect(icon).toBeInTheDocument()
  47. })
  48. it('emphasizes the last item', async () => {
  49. const view = renderComponent(CommonBreadcrumb, {
  50. props: {
  51. items: [
  52. {
  53. label: 'Dashboard',
  54. route: '/',
  55. },
  56. {
  57. label: 'Settings',
  58. },
  59. ],
  60. emphasizeLastItem: true,
  61. },
  62. router: true,
  63. })
  64. const lastItem = view.getByText('Settings')
  65. expect(lastItem.parentElement).toHaveClass(
  66. 'last:dark:text-white last:text-black',
  67. )
  68. })
  69. it('supports different text sizes', async () => {
  70. const view = renderComponent(CommonBreadcrumb, {
  71. props: {
  72. items: [
  73. {
  74. label: 'Dashboard',
  75. route: '/',
  76. },
  77. {
  78. label: 'Settings',
  79. },
  80. ],
  81. },
  82. router: true,
  83. })
  84. // Default size
  85. expect(view.getByLabelText('Breadcrumb navigation')).toHaveClass(
  86. 'text-base',
  87. )
  88. await view.rerender({
  89. items: [
  90. {
  91. label: 'Dashboard',
  92. route: '/',
  93. },
  94. {
  95. label: 'Settings',
  96. },
  97. ],
  98. size: 'small',
  99. })
  100. expect(view.getByLabelText('Breadcrumb navigation')).toHaveClass('text-xs')
  101. })
  102. it('support trailing slot', async () => {
  103. const view = renderComponent(CommonBreadcrumb, {
  104. props: {
  105. items: [
  106. {
  107. label: 'Dashboard',
  108. route: '/',
  109. },
  110. {
  111. label: 'Settings',
  112. },
  113. ],
  114. },
  115. slots: {
  116. trailing: 'trailing slot',
  117. },
  118. router: true,
  119. })
  120. expect(view.getByText('trailing slot')).toBeInTheDocument()
  121. })
  122. })