ticket-create-apply-template.spec.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 { waitForFormUpdaterQueryCalls } from '#shared/components/Form/graphql/queries/formUpdater.mocks.ts'
  6. import { mockTemplatesQuery } from '../graphql/queries/templates.mocks.ts'
  7. describe('ticket create view - apply template', async () => {
  8. beforeEach(() => {
  9. mockApplicationConfig({
  10. ui_ticket_create_available_types: ['phone-in', 'phone-out', 'email-out'],
  11. customer_ticket_create: true,
  12. })
  13. mockPermissions(['ticket.agent'])
  14. })
  15. it('renders no "Apply Template" button', async () => {
  16. mockTemplatesQuery({ templates: [] })
  17. const view = await visitView('/ticket/create')
  18. expect(
  19. view.queryByRole('button', { name: 'Apply Template' }),
  20. ).not.toBeInTheDocument()
  21. })
  22. it('renders the "Apply Template" button and can apply the ', async () => {
  23. mockTemplatesQuery({
  24. templates: [
  25. { id: '1', name: 'template1' },
  26. { id: '2', name: 'template2' },
  27. ],
  28. })
  29. const view = await visitView('/ticket/create')
  30. const applyTemplateButton = view.getByRole('button', {
  31. name: 'Apply Template',
  32. })
  33. expect(applyTemplateButton).toBeInTheDocument()
  34. await view.events.click(applyTemplateButton)
  35. const templateButton = view.getByRole('button', { name: 'template1' })
  36. expect(templateButton).toBeInTheDocument()
  37. await view.events.click(templateButton)
  38. const formUpdaterCalls = await waitForFormUpdaterQueryCalls()
  39. expect(formUpdaterCalls.at(-1)?.variables).toEqual(
  40. expect.objectContaining({
  41. meta: expect.objectContaining({
  42. additionalData: expect.objectContaining({
  43. templateId: 'gid://zammad/Template/1',
  44. }),
  45. }),
  46. }),
  47. )
  48. })
  49. })