CommonUserAvatar.spec.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. import { renderComponent } from '@tests/support/components'
  3. import CommonUserAvatar, { type Props } from '../CommonUserAvatar.vue'
  4. describe('CommonUserAvatar', () => {
  5. it('renders user avatar', async () => {
  6. const view = renderComponent(CommonUserAvatar, {
  7. props: <Props>{
  8. entity: {
  9. id: '123',
  10. firstname: 'John',
  11. lastname: 'Doe',
  12. },
  13. },
  14. })
  15. const avatar = view.getByTestId('common-avatar')
  16. expect(avatar).toHaveTextContent('JD')
  17. expect(avatar).toHaveClass('bg-blue')
  18. await view.rerender(<Props>{
  19. entity: {
  20. id: '123',
  21. image: '100.png',
  22. firstname: 'John',
  23. lastname: 'Doe',
  24. },
  25. })
  26. expect(avatar).toHaveStyle(
  27. 'background-image: url(/api/users/image/100.png)',
  28. )
  29. expect(avatar).not.toHaveTextContent('JD')
  30. })
  31. it('renders system user', () => {
  32. const view = renderComponent(CommonUserAvatar, {
  33. props: <Props>{
  34. entity: {
  35. id: '1',
  36. },
  37. },
  38. })
  39. const avatar = view.getByTestId('common-avatar')
  40. expect(avatar).toHaveStyle({
  41. backgroundImage:
  42. 'url(/app/frontend/shared/components/CommonUserAvatar/assets/logo.svg)',
  43. })
  44. })
  45. it('renders icon by source', async () => {
  46. const view = renderComponent(CommonUserAvatar, {
  47. props: <Props>{
  48. entity: {
  49. id: '123',
  50. source: 'twitter',
  51. },
  52. },
  53. })
  54. expect(view.getByIconName('mobile-twitter')).toBeInTheDocument()
  55. await view.rerender(<Props>{
  56. entity: {
  57. id: '123',
  58. source: 'facebook',
  59. },
  60. })
  61. expect(view.getByIconName('mobile-facebook')).toBeInTheDocument()
  62. await view.rerender(<Props>{
  63. entity: {
  64. id: '123',
  65. source: 'some-unknown-source',
  66. },
  67. })
  68. expect(
  69. view.queryByIconName('mobile-some-unknown-source'),
  70. ).not.toBeInTheDocument()
  71. })
  72. it('renders active and outOfOffice', async () => {
  73. const view = renderComponent(CommonUserAvatar, {
  74. props: <Props>{
  75. entity: {
  76. id: '123',
  77. active: true,
  78. },
  79. },
  80. })
  81. const avatar = view.getByTestId('common-avatar')
  82. expect(avatar).not.toHaveClass('grayscale')
  83. expect(avatar).not.toHaveClass('grayscale-[70%]')
  84. await view.rerender(<Props>{
  85. entity: {
  86. id: '123',
  87. active: false,
  88. outOfOffice: true,
  89. },
  90. })
  91. expect(avatar).toHaveClass('grayscale-[70%]')
  92. await view.rerender(<Props>{
  93. entity: {
  94. id: '123',
  95. active: false,
  96. outOfOffice: false,
  97. },
  98. })
  99. expect(avatar).toHaveClass('grayscale')
  100. })
  101. it('renders crown for vip', async () => {
  102. const view = renderComponent(CommonUserAvatar, {
  103. props: <Props>{
  104. entity: {
  105. id: '123',
  106. vip: true,
  107. },
  108. },
  109. })
  110. expect(view.getByIconName('mobile-crown')).toBeInTheDocument()
  111. await view.rerender(<Props>{
  112. entity: {
  113. id: '123',
  114. vip: true,
  115. },
  116. personal: true,
  117. })
  118. expect(view.queryByIconName('mobile-crown')).not.toBeInTheDocument()
  119. })
  120. })