create_spec.rb 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Desktop > Ticket > Create', app: :desktop_view, authenticated_as: :agent, type: :system do
  4. let(:agent) { create(:agent, groups: [group]) }
  5. let(:group) { create(:group) }
  6. context 'when creating a ticket from a template', authenticated_as: :authenticate, db_strategy: :reset do
  7. let(:ticket_type) { create(:ticket_type) }
  8. let(:customer) { create(:customer, :with_org) }
  9. let(:template) do
  10. create(
  11. :template,
  12. :dummy_data,
  13. title: 'Template Ticket Title',
  14. body: 'Template Ticket Body',
  15. tags: %w[foo bar],
  16. customer:,
  17. group:,
  18. ).tap do |template|
  19. template['options']['ticket.type'] = { 'value' => 'Problem' }
  20. template.save!
  21. end
  22. end
  23. def authenticate
  24. # NB: Just trying to prove that previous tests are leaving some inconsistent records in the database & cache.
  25. Taskbar.destroy_all
  26. Rails.cache.clear
  27. # Activate ticket type field.
  28. ObjectManager::Attribute.get(object: 'Ticket', name: 'type').tap do |oa|
  29. oa.active = true
  30. oa.save!
  31. end
  32. ObjectManager::Attribute.migration_execute
  33. template
  34. agent
  35. end
  36. before do
  37. visit '/ticket/create'
  38. wait_for_subscription_start('userCurrentTaskbarItemStateUpdates')
  39. end
  40. it 'applies the template correctly' do
  41. skip 'Pending fix for https://github.com/zammad/coordination-technical-debt/issues/524'
  42. click_on 'Apply Template'
  43. click_on template.name
  44. wait_for_form_updater(3)
  45. wait_for_gql('shared/entities/user/graphql/queries/user.graphql')
  46. expect(page).to have_text(customer.fullname)
  47. click_on 'Create'
  48. wait_for_gql('shared/entities/ticket/graphql/mutations/create.graphql')
  49. expect(page).to have_text('Ticket has been created successfully')
  50. expect(Ticket.last).to have_attributes(
  51. title: 'Template Ticket Title',
  52. customer: customer,
  53. type: 'Problem',
  54. )
  55. expect(Ticket.last.articles.first.body).to include('Template Ticket Body')
  56. expect(Tag.tag_list(object: 'Ticket', o_id: Ticket.last.id)).to eq(%w[foo bar])
  57. end
  58. end
  59. end