CommonSectionMenu.spec.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { renderComponent } from '#tests/support/components/index.ts'
  3. import CommonSectionMenu from '../CommonSectionMenu.vue'
  4. import type { MenuItem } from '../types.ts'
  5. describe('rendering section', () => {
  6. it('no output without default slot and items', () => {
  7. const view = renderComponent(CommonSectionMenu, {
  8. props: {
  9. headerLabel: 'Test Header',
  10. },
  11. router: true,
  12. })
  13. expect(view.queryByText('Test Header')).not.toBeInTheDocument()
  14. })
  15. it('if have header prop, renders header', () => {
  16. const view = renderComponent(CommonSectionMenu, {
  17. props: {
  18. headerLabel: 'Test Header',
  19. items: [
  20. {
  21. label: 'Example',
  22. },
  23. ],
  24. },
  25. router: true,
  26. store: true,
  27. })
  28. expect(view.getByText('Test Header')).toBeInTheDocument()
  29. })
  30. it('if have header slot, renders header', () => {
  31. const view = renderComponent(CommonSectionMenu, {
  32. slots: {
  33. header: '<div>Test Header</div>',
  34. default: 'Example',
  35. },
  36. router: true,
  37. })
  38. expect(view.getByText('Test Header')).toBeInTheDocument()
  39. })
  40. it('if have action prop, renders action and emits an event on click', async () => {
  41. const view = renderComponent(CommonSectionMenu, {
  42. props: {
  43. actionLabel: 'Edit',
  44. },
  45. slots: {
  46. default: 'Example',
  47. },
  48. router: true,
  49. })
  50. expect(view.getByText('Edit')).toBeInTheDocument()
  51. await view.events.click(view.getByText('Edit'))
  52. expect(view.emitted()['action-click']).toBeTruthy()
  53. })
  54. it('rendering items', () => {
  55. const items: MenuItem[] = [
  56. { type: 'link', link: '/login', label: 'Login' },
  57. { type: 'link', link: '/', label: 'Link' },
  58. ]
  59. const view = renderComponent(CommonSectionMenu, {
  60. shallow: false,
  61. props: {
  62. items,
  63. },
  64. router: true,
  65. })
  66. expect(view.getByText('Login')).toBeInTheDocument()
  67. expect(view.getByText('Link')).toBeInTheDocument()
  68. })
  69. it('rendering only items with permission', () => {
  70. const items: MenuItem[] = [
  71. { type: 'link', link: '/login', label: 'Login' },
  72. { type: 'link', link: '/', label: 'Link', permission: ['example'] },
  73. ]
  74. const view = renderComponent(CommonSectionMenu, {
  75. shallow: false,
  76. props: {
  77. items,
  78. },
  79. router: true,
  80. })
  81. expect(view.getByText('Login')).toBeInTheDocument()
  82. expect(view.queryByText('Link')).not.toBeInTheDocument()
  83. })
  84. })