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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. },
  33. apps: [
  34. {
  35. name: EnumTaskbarApp.Desktop,
  36. editing: false,
  37. lastInteraction: '2024-09-19T09:00:00Z',
  38. },
  39. ],
  40. },
  41. ],
  42. },
  43. })
  44. const customerAvatar = await view.findByRole('img', {
  45. name: 'Avatar (Nicole Braun) (VIP)',
  46. })
  47. expect(customerAvatar.parentElement!).toHaveClasses([
  48. 'opacity-50',
  49. 'grayscale',
  50. ])
  51. await getTicketLiveUserUpdatesSubscriptionHandler().trigger({
  52. ticketLiveUserUpdates: {
  53. liveUsers: [
  54. {
  55. user: {
  56. id: convertToGraphQLId('User', 3),
  57. firstname: 'Nicole',
  58. lastname: 'Braun',
  59. fullname: 'Nicole Braun',
  60. vip: true,
  61. },
  62. apps: [
  63. {
  64. name: EnumTaskbarApp.Desktop,
  65. editing: false,
  66. lastInteraction: '2024-09-19T09:05:00Z',
  67. },
  68. ],
  69. },
  70. ],
  71. },
  72. })
  73. expect(customerAvatar.parentElement!).not.toHaveClasses([
  74. 'opacity-50',
  75. 'grayscale',
  76. ])
  77. })
  78. it('displays icon on user avatar if they are editing', async () => {
  79. const view = await visitView('/tickets/1')
  80. await getTicketLiveUserUpdatesSubscriptionHandler().trigger({
  81. ticketLiveUserUpdates: {
  82. liveUsers: [
  83. {
  84. user: {
  85. id: convertToGraphQLId('User', 3),
  86. firstname: 'Nicole',
  87. lastname: 'Braun',
  88. fullname: 'Nicole Braun',
  89. vip: true,
  90. },
  91. apps: [
  92. {
  93. name: EnumTaskbarApp.Desktop,
  94. editing: false,
  95. lastInteraction: '2024-09-19T09:00:00Z',
  96. },
  97. ],
  98. },
  99. ],
  100. },
  101. })
  102. const customerAvatar = await view.findByRole('img', {
  103. name: 'Avatar (Nicole Braun) (VIP)',
  104. })
  105. expect(
  106. queryByIconName(customerAvatar.parentElement!, 'pencil'),
  107. ).not.toBeInTheDocument()
  108. await getTicketLiveUserUpdatesSubscriptionHandler().trigger({
  109. ticketLiveUserUpdates: {
  110. liveUsers: [
  111. {
  112. user: {
  113. id: convertToGraphQLId('User', 3),
  114. firstname: 'Nicole',
  115. lastname: 'Braun',
  116. fullname: 'Nicole Braun',
  117. vip: true,
  118. },
  119. apps: [
  120. {
  121. name: EnumTaskbarApp.Desktop,
  122. editing: true,
  123. lastInteraction: '2024-09-19T09:05:00Z',
  124. },
  125. ],
  126. },
  127. ],
  128. },
  129. })
  130. expect(
  131. getByIconName(customerAvatar.parentElement!, 'pencil'),
  132. ).toBeInTheDocument()
  133. })
  134. it('displays icon on user avatar if they are on mobile', async () => {
  135. const view = await visitView('/tickets/1')
  136. await getTicketLiveUserUpdatesSubscriptionHandler().trigger({
  137. ticketLiveUserUpdates: {
  138. liveUsers: [
  139. {
  140. user: {
  141. id: convertToGraphQLId('User', 3),
  142. firstname: 'Nicole',
  143. lastname: 'Braun',
  144. fullname: 'Nicole Braun',
  145. vip: true,
  146. },
  147. apps: [
  148. {
  149. name: EnumTaskbarApp.Desktop,
  150. editing: false,
  151. lastInteraction: '2024-09-19T09:00:00Z',
  152. },
  153. ],
  154. },
  155. ],
  156. },
  157. })
  158. const customerAvatar = await view.findByRole('img', {
  159. name: 'Avatar (Nicole Braun) (VIP)',
  160. })
  161. expect(
  162. queryByIconName(customerAvatar.parentElement!, 'phone'),
  163. ).not.toBeInTheDocument()
  164. await getTicketLiveUserUpdatesSubscriptionHandler().trigger({
  165. ticketLiveUserUpdates: {
  166. liveUsers: [
  167. {
  168. user: {
  169. id: convertToGraphQLId('User', 3),
  170. firstname: 'Nicole',
  171. lastname: 'Braun',
  172. fullname: 'Nicole Braun',
  173. vip: true,
  174. },
  175. apps: [
  176. {
  177. name: EnumTaskbarApp.Mobile,
  178. editing: false,
  179. lastInteraction: '2024-09-19T09:05:00Z',
  180. },
  181. ],
  182. },
  183. ],
  184. },
  185. })
  186. expect(
  187. getByIconName(customerAvatar.parentElement!, 'phone'),
  188. ).toBeInTheDocument()
  189. })
  190. it('hides the user avatar if they leave the ticket', async () => {
  191. const view = await visitView('/tickets/1')
  192. await getTicketLiveUserUpdatesSubscriptionHandler().trigger({
  193. ticketLiveUserUpdates: {
  194. liveUsers: [
  195. {
  196. user: {
  197. id: convertToGraphQLId('User', 3),
  198. firstname: 'Nicole',
  199. lastname: 'Braun',
  200. fullname: 'Nicole Braun',
  201. vip: true,
  202. },
  203. apps: [
  204. {
  205. name: EnumTaskbarApp.Desktop,
  206. editing: false,
  207. lastInteraction: '2024-09-19T09:00:00Z',
  208. },
  209. ],
  210. },
  211. ],
  212. },
  213. })
  214. expect(
  215. await view.findByRole('img', {
  216. name: 'Avatar (Nicole Braun) (VIP)',
  217. }),
  218. ).toBeInTheDocument()
  219. await getTicketLiveUserUpdatesSubscriptionHandler().trigger({
  220. ticketLiveUserUpdates: {
  221. liveUsers: [],
  222. },
  223. })
  224. expect(
  225. view.queryByRole('img', { name: 'Avatar (Nicole Braun) (VIP)' }),
  226. ).not.toBeInTheDocument()
  227. })
  228. })