ticket-detail-view-live-users.spec.ts 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { expect } from 'vitest'
  3. import {
  4. getByIconName,
  5. queryByIconName,
  6. } from '#tests/support/components/iconQueries.ts'
  7. import { visitView } from '#tests/support/components/visitView.ts'
  8. import { mockTicketQuery } from '#shared/entities/ticket/graphql/queries/ticket.mocks.ts'
  9. import { getTicketLiveUserUpdatesSubscriptionHandler } from '#shared/entities/ticket/graphql/subscriptions/ticketLiveUserUpdates.mocks.ts'
  10. import { createDummyTicket } from '#shared/entities/ticket-article/__tests__/mocks/ticket.ts'
  11. import { EnumTaskbarApp } from '#shared/graphql/types.ts'
  12. import { convertToGraphQLId } from '#shared/graphql/utils.ts'
  13. vi.hoisted(() => {
  14. vi.setSystemTime(new Date('2024-09-19T09:06:00Z'))
  15. })
  16. describe('Ticket detail view live users handling', () => {
  17. beforeEach(() => {
  18. mockTicketQuery({ ticket: createDummyTicket() })
  19. })
  20. it('displays idle state of the user avatar', async () => {
  21. const view = await visitView('/tickets/1')
  22. await getTicketLiveUserUpdatesSubscriptionHandler().trigger({
  23. ticketLiveUserUpdates: {
  24. liveUsers: [
  25. {
  26. user: {
  27. id: convertToGraphQLId('User', 3),
  28. firstname: 'Nicole',
  29. lastname: 'Braun',
  30. fullname: 'Nicole Braun',
  31. vip: true,
  32. active: true,
  33. },
  34. apps: [
  35. {
  36. name: EnumTaskbarApp.Desktop,
  37. editing: false,
  38. lastInteraction: '2024-09-19T09:00:00Z',
  39. },
  40. ],
  41. },
  42. ],
  43. },
  44. })
  45. const customerAvatar = await view.findByRole('img', {
  46. name: 'Avatar (Nicole Braun) (VIP)',
  47. })
  48. expect(customerAvatar).toHaveClass('opacity-60')
  49. expect(
  50. getByIconName(customerAvatar.parentElement!, 'user-idle-2'),
  51. ).toHaveClasses(['fill-stone-200', 'dark:fill-neutral-500'])
  52. await getTicketLiveUserUpdatesSubscriptionHandler().trigger({
  53. ticketLiveUserUpdates: {
  54. liveUsers: [
  55. {
  56. user: {
  57. id: convertToGraphQLId('User', 3),
  58. firstname: 'Nicole',
  59. lastname: 'Braun',
  60. fullname: 'Nicole Braun',
  61. vip: true,
  62. active: true,
  63. },
  64. apps: [
  65. {
  66. name: EnumTaskbarApp.Desktop,
  67. editing: false,
  68. lastInteraction: '2024-09-19T09:05:00Z',
  69. },
  70. ],
  71. },
  72. ],
  73. },
  74. })
  75. expect(customerAvatar).not.toHaveClass('opacity-60')
  76. expect(
  77. queryByIconName(customerAvatar.parentElement!, 'user-idle'),
  78. ).not.toBeInTheDocument()
  79. })
  80. it('displays icon on user avatar if they are editing', async () => {
  81. const view = await visitView('/tickets/1')
  82. await getTicketLiveUserUpdatesSubscriptionHandler().trigger({
  83. ticketLiveUserUpdates: {
  84. liveUsers: [
  85. {
  86. user: {
  87. id: convertToGraphQLId('User', 3),
  88. firstname: 'Nicole',
  89. lastname: 'Braun',
  90. fullname: 'Nicole Braun',
  91. vip: true,
  92. active: true,
  93. },
  94. apps: [
  95. {
  96. name: EnumTaskbarApp.Desktop,
  97. editing: false,
  98. lastInteraction: '2024-09-19T09:00:00Z',
  99. },
  100. ],
  101. },
  102. ],
  103. },
  104. })
  105. const customerAvatar = await view.findByRole('img', {
  106. name: 'Avatar (Nicole Braun) (VIP)',
  107. })
  108. expect(
  109. queryByIconName(customerAvatar.parentElement!, 'pencil'),
  110. ).not.toBeInTheDocument()
  111. await getTicketLiveUserUpdatesSubscriptionHandler().trigger({
  112. ticketLiveUserUpdates: {
  113. liveUsers: [
  114. {
  115. user: {
  116. id: convertToGraphQLId('User', 3),
  117. firstname: 'Nicole',
  118. lastname: 'Braun',
  119. fullname: 'Nicole Braun',
  120. vip: true,
  121. active: true,
  122. },
  123. apps: [
  124. {
  125. name: EnumTaskbarApp.Desktop,
  126. editing: true,
  127. lastInteraction: '2024-09-19T09:05:00Z',
  128. },
  129. ],
  130. },
  131. ],
  132. },
  133. })
  134. expect(
  135. getByIconName(customerAvatar.parentElement!, 'pencil'),
  136. ).toHaveClasses(['text-black', 'dark:text-white'])
  137. })
  138. it('displays icon on user avatar if they are on mobile', async () => {
  139. const view = await visitView('/tickets/1')
  140. await getTicketLiveUserUpdatesSubscriptionHandler().trigger({
  141. ticketLiveUserUpdates: {
  142. liveUsers: [
  143. {
  144. user: {
  145. id: convertToGraphQLId('User', 3),
  146. firstname: 'Nicole',
  147. lastname: 'Braun',
  148. fullname: 'Nicole Braun',
  149. vip: true,
  150. active: true,
  151. },
  152. apps: [
  153. {
  154. name: EnumTaskbarApp.Desktop,
  155. editing: false,
  156. lastInteraction: '2024-09-19T09:00:00Z',
  157. },
  158. ],
  159. },
  160. ],
  161. },
  162. })
  163. const customerAvatar = await view.findByRole('img', {
  164. name: 'Avatar (Nicole Braun) (VIP)',
  165. })
  166. expect(
  167. queryByIconName(customerAvatar.parentElement!, 'phone'),
  168. ).not.toBeInTheDocument()
  169. await getTicketLiveUserUpdatesSubscriptionHandler().trigger({
  170. ticketLiveUserUpdates: {
  171. liveUsers: [
  172. {
  173. user: {
  174. id: convertToGraphQLId('User', 3),
  175. firstname: 'Nicole',
  176. lastname: 'Braun',
  177. fullname: 'Nicole Braun',
  178. vip: true,
  179. active: true,
  180. },
  181. apps: [
  182. {
  183. name: EnumTaskbarApp.Mobile,
  184. editing: false,
  185. lastInteraction: '2024-09-19T09:05:00Z',
  186. },
  187. ],
  188. },
  189. ],
  190. },
  191. })
  192. expect(getByIconName(customerAvatar.parentElement!, 'phone')).toHaveClasses(
  193. ['text-black', 'dark:text-white'],
  194. )
  195. })
  196. it('hides the user avatar if they leave the ticket', async () => {
  197. const view = await visitView('/tickets/1')
  198. await getTicketLiveUserUpdatesSubscriptionHandler().trigger({
  199. ticketLiveUserUpdates: {
  200. liveUsers: [
  201. {
  202. user: {
  203. id: convertToGraphQLId('User', 3),
  204. firstname: 'Nicole',
  205. lastname: 'Braun',
  206. fullname: 'Nicole Braun',
  207. vip: true,
  208. active: true,
  209. },
  210. apps: [
  211. {
  212. name: EnumTaskbarApp.Desktop,
  213. editing: false,
  214. lastInteraction: '2024-09-19T09:00:00Z',
  215. },
  216. ],
  217. },
  218. ],
  219. },
  220. })
  221. expect(
  222. await view.findByRole('img', {
  223. name: 'Avatar (Nicole Braun) (VIP)',
  224. }),
  225. ).toBeInTheDocument()
  226. await getTicketLiveUserUpdatesSubscriptionHandler().trigger({
  227. ticketLiveUserUpdates: {
  228. liveUsers: [],
  229. },
  230. })
  231. expect(
  232. view.queryByRole('img', { name: 'Avatar (Nicole Braun) (VIP)' }),
  233. ).not.toBeInTheDocument()
  234. })
  235. })