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

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