link_spec.rb 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Ticket zoom > Add Link action', type: :system do
  4. describe 'ticket add link action' do
  5. context 'when source ticket is linked to target ticket' do
  6. let(:source_ticket) { create(:ticket, group: Group.find_by(name: 'Users')) }
  7. let(:target_ticket) { create(:ticket, group: Group.find_by(name: 'Users')) }
  8. let(:ticket_number) { target_ticket.number }
  9. before do
  10. visit "#ticket/zoom/#{source_ticket.id}"
  11. end
  12. shared_examples 'adding link to target ticket' do
  13. it 'adds link to target ticket' do
  14. click('.js-add', text: 'Add Link')
  15. in_modal do
  16. fill_in 'ticket_number', with: ticket_number
  17. # Trigger the paste event to replace the ticket hook, if present.
  18. execute_script('$("input[name=\"ticket_number\"]").trigger("paste")')
  19. click '.js-submit'
  20. end
  21. await_empty_ajax_queue
  22. added_link = Link.list(link_object: 'Ticket', link_object_value: source_ticket.id).last
  23. expect(added_link).to eq({
  24. 'link_object' => 'Ticket',
  25. 'link_object_value' => target_ticket.id,
  26. 'link_type' => 'normal',
  27. })
  28. end
  29. end
  30. context 'when input field is used without ticket hook' do
  31. it_behaves_like 'adding link to target ticket'
  32. end
  33. context 'when input field is used with ticket hook' do
  34. let(:search_term) { Setting.get('ticket_hook') + target_ticket.number }
  35. it_behaves_like 'adding link to target ticket'
  36. end
  37. end
  38. end
  39. end