ticket-detail-view-draft.spec.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 { mockFormUpdaterQuery } from '#shared/components/Form/graphql/queries/formUpdater.mocks.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 { mockLinkListQuery } from '../graphql/queries/linkList.mocks.ts'
  9. describe('Ticket detail view - draft handling', () => {
  10. describe('when user is an agent', () => {
  11. beforeEach(() => {
  12. mockPermissions(['ticket.agent'])
  13. mockLinkListQuery({
  14. linkList: [],
  15. })
  16. })
  17. it('shows save as draft if it is enabled for group and user is agent', async () => {
  18. mockFormUpdaterQuery({
  19. formUpdater: {
  20. fields: {},
  21. flags: {
  22. hasSharedDraft: true,
  23. },
  24. },
  25. })
  26. mockTicketQuery({
  27. ticket: createDummyTicket(),
  28. })
  29. const view = await visitView('/tickets/1')
  30. const actionMenu = await view.findByLabelText(
  31. 'Additional ticket edit actions',
  32. )
  33. await view.events.click(actionMenu)
  34. const menu = await view.findByRole('menu')
  35. expect(within(menu).getByText('Save as draft')).toBeInTheDocument()
  36. })
  37. })
  38. describe('when user is an customer', () => {
  39. beforeEach(() => {
  40. mockPermissions(['ticket.customer'])
  41. })
  42. it('shows no save as draft if it an customer', async () => {
  43. mockFormUpdaterQuery({
  44. formUpdater: {
  45. fields: {},
  46. flags: {
  47. hasSharedDraft: true,
  48. },
  49. },
  50. })
  51. mockTicketQuery({
  52. ticket: createDummyTicket(),
  53. })
  54. const view = await visitView('/tickets/1')
  55. expect(
  56. view.queryByLabelText('Additional ticket edit actions'),
  57. ).not.toBeInTheDocument()
  58. })
  59. })
  60. })