ticket-detail-view-subscribers.spec.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { within } from '@testing-library/vue'
  3. import { visitView } from '#tests/support/components/visitView.ts'
  4. import { mockPermissions } from '#tests/support/mock-permissions.ts'
  5. import { mockUserCurrent } from '#tests/support/mock-userCurrent.ts'
  6. import { waitForNextTick } from '#tests/support/utils.ts'
  7. import { mockFormUpdaterQuery } from '#shared/components/Form/graphql/queries/formUpdater.mocks.ts'
  8. import { waitForMentionSubscribeMutationCalls } from '#shared/entities/ticket/graphql/mutations/subscribe.mocks.ts'
  9. import { mockTicketQuery } from '#shared/entities/ticket/graphql/queries/ticket.mocks.ts'
  10. import { getTicketUpdatesSubscriptionHandler } from '#shared/entities/ticket/graphql/subscriptions/ticketUpdates.mocks.ts'
  11. import { createDummyTicket } from '#shared/entities/ticket-article/__tests__/mocks/ticket.ts'
  12. import { convertToGraphQLId } from '#shared/graphql/utils.ts'
  13. import { mockLinkListQuery } from '../graphql/queries/linkList.mocks.ts'
  14. describe('Ticket detail view', () => {
  15. beforeEach(() => {
  16. mockUserCurrent({
  17. firstname: 'Adam',
  18. lastname: 'Doe',
  19. })
  20. mockPermissions(['ticket.agent'])
  21. })
  22. describe('Subscribers', () => {
  23. it('shows subscriber information', async () => {
  24. const ticket = createDummyTicket({
  25. mentions: {
  26. __typename: 'MentionConnection',
  27. totalCount: 3,
  28. edges: [
  29. {
  30. cursor: 'AA',
  31. node: {
  32. __typename: 'Mention',
  33. user: {
  34. __typename: 'User',
  35. id: convertToGraphQLId('User', 1),
  36. internalId: 1,
  37. firstname: 'John',
  38. lastname: 'Doe',
  39. fullname: 'John Doe',
  40. active: true,
  41. },
  42. userTicketAccess: {
  43. agentReadAccess: true,
  44. },
  45. },
  46. },
  47. {
  48. cursor: 'AB',
  49. node: {
  50. __typename: 'Mention',
  51. user: {
  52. __typename: 'User',
  53. id: convertToGraphQLId('User', 2),
  54. internalId: 2,
  55. firstname: 'Jane',
  56. lastname: 'Doe',
  57. fullname: 'Jane Doe',
  58. active: true,
  59. },
  60. userTicketAccess: {
  61. agentReadAccess: true,
  62. },
  63. },
  64. },
  65. {
  66. cursor: 'AC',
  67. node: {
  68. __typename: 'Mention',
  69. user: {
  70. __typename: 'User',
  71. id: convertToGraphQLId('User', 3),
  72. internalId: 3,
  73. firstname: 'Jim',
  74. lastname: 'Doe',
  75. fullname: 'Jim Doe',
  76. active: false,
  77. },
  78. userTicketAccess: {
  79. agentReadAccess: true,
  80. },
  81. },
  82. },
  83. ],
  84. },
  85. })
  86. mockTicketQuery({
  87. ticket,
  88. })
  89. mockLinkListQuery({
  90. linkList: [],
  91. })
  92. mockFormUpdaterQuery({
  93. formUpdater: {
  94. fields: {
  95. group_id: {
  96. options: [
  97. {
  98. value: 1,
  99. label: 'Users',
  100. },
  101. {
  102. value: 2,
  103. label: 'test group',
  104. },
  105. ],
  106. },
  107. owner_id: {
  108. options: [
  109. {
  110. value: 3,
  111. label: 'Test Admin Agent',
  112. },
  113. ],
  114. },
  115. state_id: {
  116. options: [
  117. {
  118. value: 4,
  119. label: 'closed',
  120. },
  121. {
  122. value: 2,
  123. label: 'open',
  124. },
  125. {
  126. value: 6,
  127. label: 'pending close',
  128. },
  129. {
  130. value: 3,
  131. label: 'pending reminder',
  132. },
  133. ],
  134. },
  135. pending_time: {
  136. show: false,
  137. },
  138. priority_id: {
  139. options: [
  140. {
  141. value: 1,
  142. label: '1 low',
  143. },
  144. {
  145. value: 2,
  146. label: '2 normal',
  147. },
  148. {
  149. value: 3,
  150. label: '3 high',
  151. },
  152. ],
  153. },
  154. },
  155. flags: {
  156. newArticlePresent: false,
  157. },
  158. },
  159. })
  160. const view = await visitView('/tickets/1')
  161. const ticketMetaSidebar = within(view.getByLabelText('Content sidebar'))
  162. const subscribers = ticketMetaSidebar.getByText('Subscribers')
  163. expect(subscribers).toBeInTheDocument()
  164. expect(
  165. ticketMetaSidebar.queryByLabelText('Avatar (Adam Doe)'),
  166. ).not.toBeInTheDocument()
  167. const toggle = view.getByLabelText('Subscribe me')
  168. expect(toggle).toBeInTheDocument()
  169. await view.events.click(toggle)
  170. await waitForMentionSubscribeMutationCalls()
  171. await getTicketUpdatesSubscriptionHandler().trigger({
  172. ticketUpdates: {
  173. ticket: {
  174. ...ticket,
  175. mentions: {
  176. ...ticket.mentions,
  177. edges: [
  178. ...ticket.mentions!.edges,
  179. {
  180. cursor: 'AD',
  181. node: {
  182. __typename: 'Mention',
  183. user: {
  184. __typename: 'User',
  185. id: convertToGraphQLId('User', 4),
  186. internalId: 4,
  187. firstname: 'Adam',
  188. lastname: 'Doe',
  189. fullname: 'Adam Doe',
  190. active: true,
  191. },
  192. userTicketAccess: {
  193. agentReadAccess: true,
  194. },
  195. },
  196. },
  197. ],
  198. },
  199. },
  200. },
  201. })
  202. await waitForNextTick()
  203. expect(
  204. ticketMetaSidebar.getByLabelText('Avatar (Adam Doe)'),
  205. ).toBeInTheDocument()
  206. })
  207. })
  208. })