CommonAlert.spec.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { renderComponent } from '#tests/support/components/index.ts'
  3. import CommonAlert from '../CommonAlert.vue'
  4. describe('CommonAlert.vue', () => {
  5. it('renders when no props are passed', () => {
  6. const view = renderComponent(CommonAlert, {
  7. slots: {
  8. default: 'Dummy',
  9. },
  10. })
  11. const alert = view.getByTestId('common-alert')
  12. expect(alert).toHaveTextContent('Dummy')
  13. expect(alert).toHaveClass('common-alert-info')
  14. expect(view.getByIconName('info')).toBeInTheDocument()
  15. expect(view.queryByIconName('close')).not.toBeInTheDocument()
  16. })
  17. it('renders an alert with a specific variant', () => {
  18. const view = renderComponent(CommonAlert, {
  19. props: {
  20. variant: 'danger',
  21. },
  22. slots: {
  23. default: 'Dummy',
  24. },
  25. })
  26. const alert = view.getByTestId('common-alert')
  27. expect(alert).toHaveTextContent('Dummy')
  28. expect(alert).toHaveClass('common-alert-danger')
  29. expect(view.getByIconName('close-small')).toBeInTheDocument()
  30. expect(view.queryByIconName('close')).not.toBeInTheDocument()
  31. })
  32. it('renders an dismissible alert', () => {
  33. const view = renderComponent(CommonAlert, {
  34. props: {
  35. dismissible: true,
  36. },
  37. slots: {
  38. default: 'Dummy',
  39. },
  40. })
  41. const alert = view.getByTestId('common-alert')
  42. expect(alert).toHaveTextContent('Dummy')
  43. expect(alert).toHaveClass('common-alert-info')
  44. expect(view.getByIconName('close')).toBeInTheDocument()
  45. })
  46. it('renders an alert with a link', () => {
  47. const view = renderComponent(CommonAlert, {
  48. router: true,
  49. props: {
  50. link: 'https://zammad.com',
  51. linkText: 'Zammad',
  52. },
  53. slots: {
  54. default: 'Dummy',
  55. },
  56. })
  57. const alert = view.getByTestId('common-alert')
  58. expect(alert).toHaveTextContent('Dummy')
  59. expect(alert).toHaveClass('common-alert-info')
  60. const link = view.getByText('Zammad')
  61. expect(link).toBeInTheDocument()
  62. expect(link).toHaveAttribute('href', 'https://zammad.com')
  63. })
  64. })