CommonBackButton.spec.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. import { i18n } from '@shared/i18n'
  3. import { renderComponent } from '@tests/support/components'
  4. import { flushPromises } from '@vue/test-utils'
  5. import CommonBackButton from '../CommonBackButton.vue'
  6. // $walker.back not tested because there is a unit test for it
  7. describe('rendering common back button', () => {
  8. it('renders label', async () => {
  9. const view = renderComponent(CommonBackButton, {
  10. router: true,
  11. props: {
  12. fallback: '/back-url',
  13. },
  14. })
  15. expect(view.getByRole('button', { name: 'Go back' })).toBeInTheDocument()
  16. await view.rerender({
  17. label: 'Back',
  18. })
  19. expect(view.container).toHaveTextContent('Back')
  20. i18n.setTranslationMap(new Map([['Back', 'Zurück']]))
  21. await flushPromises()
  22. expect(view.container).toHaveTextContent('Zurück')
  23. expect(view.getByRole('button', { name: 'Go back' })).toBeInTheDocument()
  24. i18n.setTranslationMap(new Map([]))
  25. })
  26. it('renders home button, if no history is present', async () => {
  27. window.history.replaceState({}, '')
  28. const view = renderComponent(CommonBackButton, {
  29. router: true,
  30. props: {
  31. fallback: '/',
  32. },
  33. })
  34. expect(view.getByRole('button', { name: 'Go home' })).toBeInTheDocument()
  35. await view.rerender({
  36. label: 'Back',
  37. })
  38. expect(view.container).toHaveTextContent('Home')
  39. })
  40. it('renders back button, if history is present', async () => {
  41. window.history.replaceState(
  42. { back: '/tickets/1/information/customer' },
  43. '/tickets/1/information/organization',
  44. )
  45. const view = renderComponent(CommonBackButton, {
  46. router: true,
  47. props: {
  48. fallback: '/',
  49. },
  50. })
  51. expect(view.getByRole('button', { name: 'Go back' })).toBeInTheDocument()
  52. await view.rerender({
  53. label: 'Back',
  54. })
  55. expect(view.container).toHaveTextContent('Back')
  56. })
  57. })