create_spec.rb 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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, another_group]) }
  5. let(:group) { create(:group) }
  6. let(:another_group) { create(:group) }
  7. let(:ticket_type) { create(:ticket_type) }
  8. let(:customer) { create(:customer, :with_org) }
  9. context 'when creating a ticket' do
  10. before do
  11. visit '/ticket/create'
  12. wait_for_form_to_settle('ticket-create')
  13. end
  14. it 'creates a new ticket' do
  15. find('[role="tab"]', text: 'Send Email').click
  16. within_form(form_updater_gql_number: 2) do
  17. expect(page).to have_css('h1', text: 'New Ticket')
  18. find_input('Title').type('Example Ticket Title')
  19. expect(page).to have_css('h1', text: 'Example Ticket Title')
  20. find_autocomplete('Customer').search_for_option(customer.email, label: customer.fullname)
  21. find_autocomplete('CC').search_for_option(Faker::Internet.unique.email, use_action: true)
  22. text = find_editor('Text')
  23. text.type('# ').type('Heading').type(:enter, click: false)
  24. find('button[aria-label="Format as bold"]').click
  25. text.type('Bold Text ', click: false).type(:enter, click: false)
  26. find('button[aria-label="Format as bold"]').click
  27. find('button[aria-label="Format as italic"]').click
  28. text.type('Italic Text ', click: false).type(:enter, click: false)
  29. find('button[aria-label="Add bullet list"]').click
  30. text.type('Bullet List ', click: false).type(:enter, click: false).type(:enter, click: false)
  31. find('button[aria-label="Add ordered list"]').click
  32. text.type('Ordered List ', click: false).type(:enter, click: false).type(:enter, click: false)
  33. find('button[aria-label="Add link"]').click
  34. # Has to be adjusted as soon as we update to new link implementation
  35. prompt = page.driver.browser.switch_to.alert
  36. prompt.send_keys('https://zammad.com')
  37. prompt.accept
  38. find_treeselect('Group').search_for_option(another_group.name)
  39. find_select('Priority').select_option('3 high')
  40. end
  41. click_on 'Create'
  42. expect(page).to have_text('Ticket has been created successfully')
  43. expect(Ticket.last).to have_attributes(
  44. title: 'Example Ticket Title',
  45. priority: Ticket::Priority.find_by(name: '3 high'),
  46. group: another_group,
  47. customer: customer,
  48. )
  49. expect(Ticket.last.articles.first.body).to eq('<h1>Heading</h1><p><strong>Bold Text </strong><br></p><p><em>Italic Text </em><br></p><ul><li><p>Bullet List </p></li></ul><ol><li><p>Ordered List </p></li></ol><p><a rel="nofollow noreferrer noopener" href="https://zammad.com" target="_blank">https://zammad.com</a><br></p>')
  50. end
  51. end
  52. context 'when creating from a template', authenticated_as: :agent, db_strategy: :reset do
  53. let(:template) do
  54. create(
  55. :template,
  56. :dummy_data,
  57. title: 'Template Ticket Title',
  58. body: 'Template Ticket Body',
  59. tags: %w[foo bar],
  60. customer:,
  61. group:,
  62. ).tap do |template|
  63. template['options']['ticket.type'] = { 'value' => 'Problem' }
  64. template.save!
  65. end
  66. end
  67. before do
  68. ObjectManager::Attribute.get(object: 'Ticket', name: 'type').tap do |oa|
  69. oa.active = true
  70. oa.save!
  71. end
  72. ObjectManager::Attribute.migration_execute
  73. template
  74. visit '/ticket/create'
  75. wait_for_form_to_settle('ticket-create')
  76. end
  77. it 'applies the template correctly' do
  78. click_on 'Apply Template'
  79. click_on template.name
  80. wait_for_form_updater(2)
  81. wait_for_gql('shared/entities/user/graphql/queries/user.graphql')
  82. expect(page).to have_text(customer.fullname)
  83. click_on 'Create'
  84. wait_for_gql('shared/entities/ticket/graphql/mutations/create.graphql')
  85. expect(page).to have_text('Ticket has been created successfully')
  86. expect(Ticket.last).to have_attributes(
  87. title: 'Template Ticket Title',
  88. customer: customer,
  89. type: 'Problem',
  90. )
  91. expect(Ticket.last.articles.first.body).to include('Template Ticket Body')
  92. expect(Tag.tag_list(object: 'Ticket', o_id: Ticket.last.id)).to eq(%w[foo bar])
  93. end
  94. end
  95. end