ticket-detail-view-macros.spec.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { waitFor, within } from '@testing-library/vue'
  3. import { expect } from 'vitest'
  4. import { getTestRouter } from '#tests/support/components/renderComponent.ts'
  5. import { visitView } from '#tests/support/components/visitView.ts'
  6. import { mockPermissions } from '#tests/support/mock-permissions.ts'
  7. import { mockFormUpdaterQuery } from '#shared/components/Form/graphql/queries/formUpdater.mocks.ts'
  8. import { mockTicketQuery } from '#shared/entities/ticket/graphql/queries/ticket.mocks.ts'
  9. import { createDummyTicket } from '#shared/entities/ticket-article/__tests__/mocks/ticket.ts'
  10. import { mockMacrosQuery } from '#shared/graphql/queries/macros.mocks.ts'
  11. import { convertToGraphQLId } from '#shared/graphql/utils.ts'
  12. import { getUserCurrentTaskbarItemUpdatesSubscriptionHandler } from '#desktop/entities/user/current/graphql/subscriptions/userCurrentTaskbarItemUpdates.mocks.ts'
  13. import { mockLinkListQuery } from '../graphql/queries/linkList.mocks.ts'
  14. describe('Ticket detail view macros', () => {
  15. it('executes example macro which closes current tab', async () => {
  16. mockPermissions(['ticket.agent'])
  17. const ticket = createDummyTicket()
  18. mockTicketQuery({ ticket })
  19. mockLinkListQuery({
  20. linkList: [],
  21. })
  22. mockFormUpdaterQuery({
  23. formUpdater: {
  24. fields: {
  25. group_id: {
  26. options: [
  27. {
  28. value: 1,
  29. label: 'Users',
  30. },
  31. {
  32. value: 2,
  33. label: 'test group',
  34. },
  35. ],
  36. },
  37. owner_id: {
  38. options: [
  39. {
  40. value: 3,
  41. label: 'Test Admin Agent',
  42. },
  43. ],
  44. },
  45. state_id: {
  46. options: [
  47. {
  48. value: 4,
  49. label: 'closed',
  50. },
  51. {
  52. value: 2,
  53. label: 'open',
  54. },
  55. {
  56. value: 6,
  57. label: 'pending close',
  58. },
  59. {
  60. value: 3,
  61. label: 'pending reminder',
  62. },
  63. ],
  64. },
  65. pending_time: {
  66. show: false,
  67. },
  68. priority_id: {
  69. options: [
  70. {
  71. value: 1,
  72. label: '1 low',
  73. },
  74. {
  75. value: 2,
  76. label: '2 normal',
  77. },
  78. {
  79. value: 3,
  80. label: '3 high',
  81. },
  82. ],
  83. },
  84. },
  85. flags: {
  86. newArticlePresent: false,
  87. },
  88. },
  89. })
  90. mockMacrosQuery({
  91. macros: [
  92. {
  93. __typename: 'Macro',
  94. id: convertToGraphQLId('Macro', 1),
  95. active: true,
  96. name: 'Macro Foo',
  97. uxFlowNextUp: 'next_task',
  98. },
  99. {
  100. __typename: 'Macro',
  101. id: convertToGraphQLId('Macro', 2),
  102. active: true,
  103. name: 'Macro 2',
  104. uxFlowNextUp: 'next_task',
  105. },
  106. ],
  107. })
  108. const view = await visitView('/tickets/1')
  109. const actionMenu = await view.findByLabelText(
  110. 'Additional ticket edit actions',
  111. )
  112. await view.events.click(actionMenu)
  113. const menu = await view.findByRole('menu')
  114. await getUserCurrentTaskbarItemUpdatesSubscriptionHandler().trigger({
  115. userCurrentTaskbarItemUpdates: {
  116. updateItem: null,
  117. addItem: null,
  118. removeItem: convertToGraphQLId('Taskbar', 1),
  119. },
  120. })
  121. await view.events.click(within(menu).getByText('Macro Foo'))
  122. const router = getTestRouter()
  123. // :TODO add this real redirect once the overview is implemented
  124. await waitFor(() =>
  125. expect(router.currentRoute.value.path).not.toEqual('/tickets/1'),
  126. )
  127. })
  128. })