ticket-detail-view-links.spec.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { within } from '@testing-library/vue'
  3. import { visitView } from '#tests/support/components/visitView.ts'
  4. import { mockPermissions } from '#tests/support/mock-permissions.ts'
  5. import { waitForNextTick } from '#tests/support/utils.ts'
  6. import { mockTicketQuery } from '#shared/entities/ticket/graphql/queries/ticket.mocks.ts'
  7. import { createDummyTicket } from '#shared/entities/ticket-article/__tests__/mocks/ticket.ts'
  8. import { EnumLinkType } from '#shared/graphql/types.ts'
  9. import { convertToGraphQLId } from '#shared/graphql/utils.ts'
  10. import { mockTicketRelationAndRecentTicketListsQuery } from '#desktop/pages/ticket/graphql/queries/ticketRelationAndRecentTicketLists.mocks.ts'
  11. import {
  12. mockLinkAddMutation,
  13. waitForLinkAddMutationCalls,
  14. } from '../graphql/mutations/linkAdd.mocks.ts'
  15. import { mockLinkListQuery } from '../graphql/queries/linkList.mocks.ts'
  16. describe('Ticket detail view links', () => {
  17. it('opens the links flyout and adds a link', async () => {
  18. mockPermissions(['ticket.agent'])
  19. mockTicketRelationAndRecentTicketListsQuery({
  20. ticketsRecentlyViewed: [createDummyTicket()],
  21. ticketsRecentByCustomer: [
  22. createDummyTicket({
  23. title: 'Foo Car',
  24. ticketId: '1111',
  25. }),
  26. ],
  27. })
  28. const ticket = createDummyTicket()
  29. mockTicketQuery({
  30. ticket,
  31. })
  32. mockLinkListQuery({
  33. linkList: [],
  34. })
  35. const view = await visitView('/tickets/1')
  36. const ticketMetaSidebar = within(view.getByLabelText('Content sidebar'))
  37. expect(ticketMetaSidebar.getByText('Links')).toBeInTheDocument()
  38. expect(
  39. ticketMetaSidebar.getByText('No links added yet.'),
  40. ).toBeInTheDocument()
  41. await view.events.click(
  42. await view.findByRole('button', { name: 'Add link' }),
  43. )
  44. expect(
  45. await view.findByRole('heading', { name: 'Link Tickets', level: 2 }),
  46. ).toBeInTheDocument()
  47. expect(await view.findByText('Recent Customer Tickets')).toBeInTheDocument()
  48. expect(view.getByText('Recently Viewed Tickets')).toBeInTheDocument()
  49. expect(view.getByText('Foo Car')).toBeInTheDocument()
  50. const rows = view.getAllByLabelText('Select table row')
  51. mockLinkAddMutation({
  52. linkAdd: {
  53. __typename: 'LinkAddPayload',
  54. link: {
  55. __typename: 'Link',
  56. item: {
  57. __typename: 'Ticket',
  58. id: convertToGraphQLId('Ticket', '1111'),
  59. title: 'Foo Car',
  60. },
  61. type: EnumLinkType.Parent,
  62. },
  63. },
  64. })
  65. await view.events.click(rows[0])
  66. await view.events.click(view.getByRole('button', { name: 'Link' }))
  67. await waitForLinkAddMutationCalls()
  68. mockLinkListQuery({
  69. linkList: [
  70. {
  71. __typename: 'Link',
  72. item: {
  73. __typename: 'Ticket',
  74. id: convertToGraphQLId('Ticket', '1111'),
  75. title: 'Foo Car',
  76. },
  77. type: EnumLinkType.Parent,
  78. },
  79. ],
  80. })
  81. await waitForNextTick()
  82. expect(
  83. ticketMetaSidebar.queryByText('No links added yet.'),
  84. ).not.toBeInTheDocument()
  85. expect(view.getByText('Parent')).toBeInTheDocument()
  86. expect(view.getByText('Foo Car')).toBeInTheDocument()
  87. })
  88. })