ticket-create-apply-split-ticket-article.spec.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { visitView } from '#tests/support/components/visitView.ts'
  3. import { mockApplicationConfig } from '#tests/support/mock-applicationConfig.ts'
  4. import { mockPermissions } from '#tests/support/mock-permissions.ts'
  5. import { waitForNextTick } from '#tests/support/utils.ts'
  6. import { waitForFormUpdaterQueryCalls } from '#shared/components/Form/graphql/queries/formUpdater.mocks.ts'
  7. import { waitForTicketCreateMutationCalls } from '#shared/entities/ticket/graphql/mutations/create.mocks.ts'
  8. import { convertToGraphQLId } from '#shared/graphql/utils.ts'
  9. import { handleMockFormUpdaterQuery } from '#desktop/pages/ticket/__tests__/support/ticket-create-helpers.ts'
  10. describe('ticket create view - splitting of a ticket article', async () => {
  11. const ticketTitle = 'split title'
  12. const articleId = 666
  13. const ticketId = 123
  14. beforeEach(() => {
  15. mockApplicationConfig({
  16. ui_ticket_create_available_types: ['phone-in', 'phone-out', 'email-out'],
  17. })
  18. mockPermissions(['ticket.agent'])
  19. handleMockFormUpdaterQuery()
  20. })
  21. it('applies given ticket article', async () => {
  22. handleMockFormUpdaterQuery({
  23. title: { value: ticketTitle },
  24. split_article_id: articleId,
  25. })
  26. const view = await visitView(
  27. '/ticket/create??splitTicketArticleId=ticket_article_gid',
  28. )
  29. const formUpdaterCalls = await waitForFormUpdaterQueryCalls()
  30. expect(formUpdaterCalls.at(-1)?.variables).toEqual(
  31. expect.objectContaining({
  32. meta: expect.objectContaining({
  33. additionalData: expect.objectContaining({
  34. splitTicketArticleId: 'ticket_article_gid',
  35. }),
  36. }),
  37. }),
  38. )
  39. await waitForNextTick()
  40. expect(view.getByLabelText('Title')).toHaveValue(ticketTitle)
  41. })
  42. it('submits linking when creating', async () => {
  43. handleMockFormUpdaterQuery({
  44. title: { value: ticketTitle },
  45. body: { value: 'body' },
  46. group_id: {
  47. value: 1,
  48. options: [
  49. {
  50. value: 1,
  51. label: 'Users',
  52. },
  53. {
  54. value: 2,
  55. label: 'some group1',
  56. },
  57. ],
  58. },
  59. customer_id: { value: 1 },
  60. link_ticket_id: { value: ticketId },
  61. pending_time: { show: false },
  62. })
  63. const view = await visitView(
  64. '/ticket/create??splitTicketArticleId=ticket_article_gid',
  65. )
  66. await waitForFormUpdaterQueryCalls()
  67. await view.events.click(view.getByRole('button', { name: 'Create' }))
  68. const ticketCreateCalls = await waitForTicketCreateMutationCalls()
  69. expect(ticketCreateCalls.at(-1)?.variables).toEqual(
  70. expect.objectContaining({
  71. input: expect.objectContaining({
  72. title: ticketTitle,
  73. links: [
  74. {
  75. linkType: 'child',
  76. linkObjectId: convertToGraphQLId('Ticket', ticketId),
  77. },
  78. ],
  79. }),
  80. }),
  81. )
  82. })
  83. })