ticket-create-gitlab.spec.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { waitFor, within } from '@testing-library/vue'
  3. import { visitView } from '#tests/support/components/visitView.ts'
  4. import { mockApplicationConfig } from '#tests/support/mock-applicationConfig.ts'
  5. import { mockPermissions } from '#tests/support/mock-permissions.ts'
  6. import { waitForTicketCreateMutationCalls } from '#shared/entities/ticket/graphql/mutations/create.mocks.ts'
  7. import { EnumTicketExternalReferencesIssueTrackerItemState } from '#shared/graphql/types.ts'
  8. import getUuid from '#shared/utils/getUuid.ts'
  9. import {
  10. handleCustomerMock,
  11. handleMockFormUpdaterQuery,
  12. handleMockUserQuery,
  13. } from '#desktop/pages/ticket/__tests__/support/ticket-create-helpers.ts'
  14. import { mockTicketExternalReferencesIssueTrackerItemAddMutation } from '../graphql/mutations/ticketExternalReferencesIssueTrackerItemAdd.mocks.ts'
  15. import { mockTicketExternalReferencesIssueTrackerItemListQuery } from '../graphql/queries/ticketExternalReferencesIssueTrackerList.mocks.ts'
  16. describe('Ticket create GitLab links', () => {
  17. beforeEach(() => {
  18. mockApplicationConfig({
  19. gitlab_integration: true,
  20. ui_task_mananger_max_task_count: 30,
  21. ui_ticket_create_available_types: ['phone-in', 'phone-out', 'email-out'],
  22. })
  23. mockPermissions(['ticket.agent'])
  24. })
  25. it('submits a new ticket with gitlab links', async () => {
  26. handleMockFormUpdaterQuery({
  27. pending_time: {
  28. show: false,
  29. },
  30. })
  31. const issueMock = mockTicketExternalReferencesIssueTrackerItemListQuery({
  32. ticketExternalReferencesIssueTrackerItemList: [],
  33. })
  34. const uid = getUuid()
  35. const view = await visitView(`/ticket/create/${uid}`)
  36. await view.events.click(view.getByRole('button', { name: 'GitLab' }))
  37. await waitFor(() =>
  38. expect(
  39. view.getByRole('heading', { level: 1, name: 'New Ticket' }),
  40. ).toBeInTheDocument(),
  41. )
  42. await view.events.type(view.getByLabelText('Title'), 'Test Ticket')
  43. await handleCustomerMock(view)
  44. handleMockUserQuery()
  45. await view.events.click(
  46. view.getByRole('option', {
  47. name: 'Avatar (Nicole Braun) Nicole Braun – Zammad Foundation',
  48. }),
  49. )
  50. await view.events.click(view.getByLabelText('Text'))
  51. await view.events.type(view.getByLabelText('Text'), 'Test ticket text')
  52. await view.events.click(view.getByLabelText('Group'))
  53. await view.events.click(view.getByRole('option', { name: 'Users' }))
  54. await view.events.click(view.getByLabelText('Priority'))
  55. await view.events.click(view.getByRole('option', { name: '2 normal' }))
  56. await view.events.click(view.getByLabelText('State'))
  57. await view.events.click(view.getByRole('option', { name: 'open' }))
  58. const sidebar = view.getByLabelText('Content sidebar')
  59. await view.events.click(
  60. await within(sidebar).findByRole('button', {
  61. name: 'Link Issue',
  62. }),
  63. )
  64. const flyout = await view.findByRole('complementary', {
  65. name: 'GitLab: Link issue',
  66. })
  67. await view.events.type(
  68. within(flyout).getByLabelText('Issue URL'),
  69. 'https://gitlab.com/gitlab-org/gitlab/-/issues/1',
  70. )
  71. issueMock.updateDefaults({
  72. ticketExternalReferencesIssueTrackerItemList: [
  73. {
  74. issueId: 123,
  75. url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/1',
  76. title: 'Issue 1',
  77. state: EnumTicketExternalReferencesIssueTrackerItemState.Open,
  78. },
  79. ],
  80. })
  81. mockTicketExternalReferencesIssueTrackerItemAddMutation({
  82. ticketExternalReferencesIssueTrackerItemAdd: {
  83. issueTrackerItem: {
  84. issueId: 123,
  85. url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/1',
  86. title: 'Issue 1',
  87. state: EnumTicketExternalReferencesIssueTrackerItemState.Open,
  88. },
  89. errors: null,
  90. },
  91. })
  92. await view.events.click(
  93. within(flyout).getByRole('button', { name: 'Link Issue' }),
  94. )
  95. expect(await within(sidebar).findByText('#123 Issue 1')).toBeInTheDocument()
  96. await view.events.click(view.getByRole('button', { name: 'Create' }))
  97. const calls = await waitForTicketCreateMutationCalls()
  98. expect(calls.at(-1)?.variables.input).toEqual(
  99. expect.objectContaining({
  100. externalReferences: {
  101. gitlab: ['https://gitlab.com/gitlab-org/gitlab/-/issues/1'],
  102. },
  103. }),
  104. )
  105. })
  106. })