ticket-detail-view.spec.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { within } from '@testing-library/vue'
  3. import { expect } from 'vitest'
  4. import createArticle from '#tests/graphql/factories/TicketArticle.ts'
  5. import { getTestRouter } from '#tests/support/components/renderComponent.ts'
  6. import { visitView } from '#tests/support/components/visitView.ts'
  7. import { mockPermissions } from '#tests/support/mock-permissions.ts'
  8. import { mockTicketArticlesQuery } from '#shared/entities/ticket/graphql/queries/ticket/articles.mocks.ts'
  9. import { mockTicketQuery } from '#shared/entities/ticket/graphql/queries/ticket.mocks.ts'
  10. import { createDummyArticle } from '#shared/entities/ticket-article/__tests__/mocks/ticket-articles.ts'
  11. import { createDummyTicket } from '#shared/entities/ticket-article/__tests__/mocks/ticket.ts'
  12. import { type TicketArticleEdge } from '#shared/graphql/types.ts'
  13. describe('Ticket detail view', () => {
  14. beforeEach(() => {
  15. mockPermissions(['ticket.agent'])
  16. })
  17. describe('Error handling', () => {
  18. it.todo('redirects if ticket id is not found', async () => {
  19. // :TODO Test as soon as the bug for the Query has complexity of 19726, has been resolved,
  20. // and specific ticket error handling is in place.
  21. mockTicketQuery({
  22. ticket: null,
  23. })
  24. await visitView('/tickets/232')
  25. const router = getTestRouter()
  26. expect(router.currentRoute.value.name).toEqual('Error')
  27. })
  28. })
  29. describe('Article list', () => {
  30. it('shows see more button', async () => {
  31. mockTicketQuery({
  32. ticket: createDummyTicket(),
  33. })
  34. const firstArticleEdges: TicketArticleEdge[] = []
  35. const articlesEdges: TicketArticleEdge[] = []
  36. let count = 27
  37. while (count > 0) {
  38. const first = createArticle()
  39. const article = createArticle()
  40. if (count <= 5)
  41. firstArticleEdges.push(<TicketArticleEdge>{
  42. cursor: Buffer.from(count.toString()).toString('base64'),
  43. node: { ...first, internalId: count, sender: { name: 'Agent' } },
  44. })
  45. if (count > 5)
  46. articlesEdges.push(<TicketArticleEdge>{
  47. cursor: Buffer.from(count.toString()).toString('base64'),
  48. node: {
  49. ...article,
  50. internalId: 50 - count,
  51. sender: { name: 'Customer' },
  52. },
  53. })
  54. // eslint-disable-next-line no-plusplus
  55. count--
  56. }
  57. mockTicketArticlesQuery({
  58. articles: {
  59. totalCount: 50,
  60. edges: articlesEdges,
  61. pageInfo: {
  62. hasPreviousPage: articlesEdges.length > 0,
  63. startCursor:
  64. articlesEdges.length > 0 ? articlesEdges[0].cursor : null,
  65. endCursor: btoa('50'),
  66. },
  67. },
  68. firstArticles: {
  69. edges: firstArticleEdges,
  70. },
  71. })
  72. const view = await visitView('/tickets/1')
  73. const feed = view.getByRole('feed')
  74. const articles = within(feed).getAllByRole('article')
  75. expect(articles).toHaveLength(26) // 20 articles from end && 5 articles from the beginning 1 more button
  76. expect(
  77. within(articles.at(6) as HTMLElement).getByRole('button', {
  78. name: 'See more',
  79. }),
  80. ).toBeInTheDocument()
  81. })
  82. it('shows meta information if article is clicked', async () => {
  83. mockTicketQuery({
  84. ticket: createDummyTicket(),
  85. })
  86. const testArticle = createDummyArticle({
  87. bodyWithUrls: 'foobar',
  88. })
  89. mockTicketArticlesQuery({
  90. articles: {
  91. totalCount: 1,
  92. edges: [{ node: testArticle }],
  93. },
  94. firstArticles: {
  95. edges: [{ node: testArticle }],
  96. },
  97. })
  98. const view = await visitView('/tickets/1')
  99. expect(
  100. view.getByRole('heading', { name: 'Test Ticket', level: 2 }),
  101. ).toBeInTheDocument()
  102. expect(view.getByLabelText('Breadcrumb navigation')).toBeInTheDocument()
  103. expect(view.getByTestId('article-content')).toHaveTextContent('foobar')
  104. await view.events.click(view.getByTestId('article-bubble-body-1'))
  105. expect(
  106. await view.findByLabelText('Article meta information'),
  107. ).toBeInTheDocument()
  108. await view.events.click(view.getByTestId('article-bubble-body-1'))
  109. expect(
  110. view.queryByLabelText('Article meta information'),
  111. ).not.toBeInTheDocument()
  112. })
  113. })
  114. })