LayoutHeader.spec.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { i18n } from '#shared/i18n.ts'
  3. import { renderComponent } from '#tests/support/components/index.ts'
  4. import LayoutHeader from '../LayoutHeader.vue'
  5. describe('mobile app header', () => {
  6. it("doesn't render, if not specified", () => {
  7. const view = renderComponent(LayoutHeader, { router: true })
  8. expect(view.queryByTestId('appHeader')).not.toBeInTheDocument()
  9. })
  10. it('renders title, if specified', async () => {
  11. const view = renderComponent(LayoutHeader, {
  12. props: { title: 'Test' },
  13. router: true,
  14. })
  15. expect(view.getByTestId('appHeader')).toBeInTheDocument()
  16. expect(view.getByText('Test')).toBeInTheDocument()
  17. i18n.setTranslationMap(new Map([['Test2', 'Translated']]))
  18. await view.rerender({ title: 'Test2' })
  19. expect(view.getByText('Translated')).toBeInTheDocument()
  20. })
  21. it('can add custom class to title', () => {
  22. const view = renderComponent(LayoutHeader, {
  23. props: {
  24. title: 'Test',
  25. titleClass: 'test-class',
  26. },
  27. router: true,
  28. })
  29. expect(view.getByText('Test')).toHaveClass('test-class')
  30. })
  31. it('renders back button, if specified', async () => {
  32. const view = renderComponent(LayoutHeader, {
  33. props: {
  34. backUrl: '/foo',
  35. backTitle: 'Back',
  36. },
  37. router: true,
  38. })
  39. const backButton = view.getByText('Back')
  40. expect(backButton).toBeInTheDocument()
  41. i18n.setTranslationMap(new Map([['Test2', 'Translated']]))
  42. await view.rerender({ backTitle: 'Test2', backUrl: '/bar' })
  43. expect(view.getByText('Translated')).toBeInTheDocument()
  44. })
  45. it('renders action, if specified', async () => {
  46. const onAction = vi.fn()
  47. const view = renderComponent(LayoutHeader, {
  48. props: {
  49. onAction,
  50. actionTitle: 'Action',
  51. },
  52. router: true,
  53. })
  54. const actionButton = view.getByText('Action')
  55. expect(actionButton).toBeInTheDocument()
  56. await view.events.click(actionButton)
  57. expect(onAction).toHaveBeenCalled()
  58. i18n.setTranslationMap(new Map([['Test2', 'Translated']]))
  59. await view.rerender({ actionTitle: 'Test2', onAction })
  60. expect(view.getByText('Translated')).toBeInTheDocument()
  61. })
  62. it('hides action, if specified', async () => {
  63. const onAction = vi.fn()
  64. const view = renderComponent(LayoutHeader, {
  65. props: {
  66. onAction,
  67. actionTitle: 'Action',
  68. actionHidden: true,
  69. },
  70. router: true,
  71. })
  72. expect(view.queryByText('Action')).not.toBeInTheDocument()
  73. })
  74. })