ticket-create-github.spec.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 GitHub links', () => {
  17. beforeEach(() => {
  18. mockApplicationConfig({
  19. github_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 github links', async () => {
  26. handleMockFormUpdaterQuery({
  27. pending_time: {
  28. show: false,
  29. },
  30. })
  31. 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: 'GitHub' }))
  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: 'GitHub: Link issue',
  66. })
  67. await view.events.type(
  68. within(flyout).getByLabelText('Issue URL'),
  69. 'https://github.com/zammad/zammad/issues/123',
  70. )
  71. mockTicketExternalReferencesIssueTrackerItemAddMutation({
  72. ticketExternalReferencesIssueTrackerItemAdd: {
  73. issueTrackerItem: {
  74. issueId: 123,
  75. url: 'https://github.com/zammad/zammad/issues/123',
  76. title: 'Issue 1',
  77. state: EnumTicketExternalReferencesIssueTrackerItemState.Open,
  78. },
  79. errors: null,
  80. },
  81. })
  82. await view.events.click(
  83. within(flyout).getByRole('button', { name: 'Link Issue' }),
  84. )
  85. expect(await within(sidebar).findByText('#123 Issue 1')).toBeInTheDocument()
  86. await view.events.click(view.getByRole('button', { name: 'Create' }))
  87. const calls = await waitForTicketCreateMutationCalls()
  88. expect(calls.at(-1)?.variables.input).toEqual(
  89. expect.objectContaining({
  90. externalReferences: {
  91. github: ['https://github.com/zammad/zammad/issues/123'],
  92. },
  93. }),
  94. )
  95. })
  96. })