CommonTranslateRenderer.spec.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { renderComponent } from '#tests/support/components/index.ts'
  3. import { i18n } from '#shared/i18n.ts'
  4. import CommonlTranslateRenderer from '../CommonTranslateRenderer.vue'
  5. const populateTranslationMap = () => {
  6. const map = new Map([
  7. [
  8. 'A example with an %s which can be inside a %s.',
  9. 'Ein Beispiel mit einem %s, das in einer %s enthalten sein kann.',
  10. ],
  11. ['translation', 'Übersetzung'],
  12. ['FORMAT_DATE', 'dd/mm/yyyy'],
  13. ['FORMAT_DATETIME', 'dd/mm/yyyy HH:MM:SS'],
  14. ])
  15. i18n.setTranslationMap(map)
  16. }
  17. describe('CommonlTranslateRenderer.vue', () => {
  18. beforeEach(() => {
  19. populateTranslationMap()
  20. })
  21. it('renders link in given source string', () => {
  22. const view = renderComponent(CommonlTranslateRenderer, {
  23. props: {
  24. source: 'A example with an %s which can be inside a %s.',
  25. placeholders: [
  26. {
  27. type: 'link',
  28. props: {
  29. link: 'https://www.zammad.org',
  30. class: 'custom-class',
  31. },
  32. content: 'Link',
  33. },
  34. i18n.t('translation'),
  35. ],
  36. },
  37. router: true,
  38. })
  39. const link = view.getByTestId('common-link')
  40. expect(link).toHaveTextContent('Link')
  41. expect(link).toHaveClass('custom-class')
  42. expect(link).toHaveAttribute('href', 'https://www.zammad.org')
  43. })
  44. it('renders a common label in given source string', () => {
  45. const view = renderComponent(CommonlTranslateRenderer, {
  46. props: {
  47. source: 'A example with an %s which can be inside a %s.',
  48. placeholders: [
  49. {
  50. type: 'label',
  51. props: {
  52. class: 'custom-class',
  53. },
  54. content: 'Label',
  55. },
  56. i18n.t('translation'),
  57. ],
  58. },
  59. router: true,
  60. })
  61. console.log('view:', view.html())
  62. const label = view.getByTestId('common-label')
  63. expect(label).toHaveTextContent('Label')
  64. expect(label).toHaveClass('custom-class')
  65. })
  66. })