CommonAlert.spec.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. })