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

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