CommonLoader.spec.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { getByIconName } from '#tests/support/components/iconQueries.ts'
  3. import { renderComponent } from '#tests/support/components/index.ts'
  4. import CommonLoader from '../CommonLoader.vue'
  5. describe('CommonLoader.vue', () => {
  6. it('does not render with default prop values', async () => {
  7. const view = renderComponent(CommonLoader)
  8. expect(view.queryByRole('status')).not.toBeInTheDocument()
  9. })
  10. it('renders loading animation with loading prop set', async () => {
  11. const view = renderComponent(CommonLoader, {
  12. props: {
  13. loading: true,
  14. },
  15. })
  16. const loader = view.getByRole('status')
  17. expect(getByIconName(loader, 'spinner')).toBeInTheDocument()
  18. })
  19. it('hides loading animation when loading prop is unset', async () => {
  20. const view = renderComponent(CommonLoader, {
  21. props: {
  22. loading: true,
  23. },
  24. })
  25. const loader = view.getByRole('status')
  26. expect(loader).toBeInTheDocument()
  27. await view.rerender({
  28. loading: false,
  29. })
  30. expect(loader).not.toBeInTheDocument()
  31. })
  32. it('renders alert if error prop is supplied', async () => {
  33. const view = renderComponent(CommonLoader, {
  34. props: {
  35. error: 'foobar',
  36. },
  37. })
  38. const alert = view.getByRole('alert')
  39. expect(alert).toHaveTextContent('foobar')
  40. expect(getByIconName(alert, 'x-circle')).toBeInTheDocument()
  41. })
  42. it('provides default slot', async () => {
  43. const view = renderComponent(CommonLoader, {
  44. slots: {
  45. default: 'foobar',
  46. },
  47. })
  48. expect(view.baseElement).toHaveTextContent('foobar')
  49. expect(view.queryByRole('status')).not.toBeInTheDocument()
  50. expect(view.queryByRole('alert')).not.toBeInTheDocument()
  51. })
  52. })