view_spec.rb 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. require 'rails_helper'
  2. RSpec.describe 'Ticket views', type: :system do
  3. context 'macros' do
  4. let!(:group1) { create :group }
  5. let!(:group2) { create :group }
  6. let!(:macro_without_group) { create :macro }
  7. let!(:macro_note) { create :macro, perform: { 'article.note'=>{ 'body' => 'macro body', 'internal' => 'true', 'subject' => 'macro note' } } }
  8. let!(:macro_group1) { create :macro, groups: [group1] }
  9. let!(:macro_group2) { create :macro, groups: [group2] }
  10. it 'supports group-dependent macros' do
  11. ticket1 = create :ticket, group: group1
  12. ticket2 = create :ticket, group: group2
  13. # give user access to all groups including those created
  14. # by using FactoryBot outside of the example
  15. group_names_access_map = Group.all.pluck(:name).each_with_object({}) do |group_name, result|
  16. result[group_name] = 'full'.freeze
  17. end
  18. current_user do |user|
  19. user.group_names_access_map = group_names_access_map
  20. user.save!
  21. end
  22. # refresh browser to get macro accessable
  23. refresh
  24. visit '#ticket/view/all_open'
  25. within(:active_content) do
  26. ticket = page.find(:table_row, 1).native
  27. # click and hold first ticket in table
  28. click_and_hold(ticket)
  29. # move ticket to y -ticket.location.y
  30. move_mouse_by(0, -ticket.location.y + 5)
  31. # move a bit to the left to display macro batches
  32. move_mouse_by(-250, 0)
  33. expect(page).to have_selector(:macro_batch, macro_without_group.id, visible: :visible)
  34. expect(page).to have_no_selector(:macro_batch, macro_group1.id)
  35. expect(page).to have_no_selector(:macro_batch, macro_group2.id)
  36. release_mouse
  37. refresh
  38. ticket = page.find(:table_row, ticket1.id).native
  39. # click and hold first ticket in table
  40. click_and_hold(ticket)
  41. # move ticket to y -ticket.location.y
  42. move_mouse_by(0, -ticket.location.y + 5)
  43. # move a bit to the left to display macro batches
  44. move_mouse_by(-250, 0)
  45. expect(page).to have_selector(:macro_batch, macro_without_group.id, visible: :visible)
  46. expect(page).to have_selector(:macro_batch, macro_group1.id)
  47. expect(page).to have_no_selector(:macro_batch, macro_group2.id)
  48. release_mouse
  49. refresh
  50. ticket = page.find(:table_row, ticket2.id).native
  51. # click and hold first ticket in table
  52. click_and_hold(ticket)
  53. # move ticket to y -ticket.location.y
  54. move_mouse_by(0, -ticket.location.y + 5)
  55. # move a bit to the left to display macro batches
  56. move_mouse_by(-250, 0)
  57. expect(page).to have_selector(:macro_batch, macro_without_group.id, visible: :visible)
  58. expect(page).to have_no_selector(:macro_batch, macro_group1.id)
  59. expect(page).to have_selector(:macro_batch, macro_group2.id)
  60. end
  61. end
  62. it 'can use macro to create article', authenticated_as: true do
  63. refresh
  64. visit '#ticket/view/all_open'
  65. within(:active_content) do
  66. ticket = page.find(:table_row, Ticket.first.id).native
  67. # click and hold first ticket in table
  68. click_and_hold(ticket)
  69. # move ticket to y -ticket.location.y
  70. move_mouse_by(0, -ticket.location.y + 5)
  71. # move a bit to the left to display macro batches
  72. move_mouse_by(-250, 0)
  73. expect(page).to have_selector(:macro_batch, macro_note.id, wait: 10)
  74. macro = find(:macro_batch, macro_note.id)
  75. move_mouse_to(macro)
  76. release_mouse
  77. await_empty_ajax_queue
  78. expect(Ticket.first.articles.last.subject).to eq('macro note')
  79. end
  80. end
  81. end
  82. context 'bulk note', authenticated_as: :user do
  83. let(:group) { create :group }
  84. let(:user) { create :admin, groups: [group] }
  85. let!(:ticket1) { create(:ticket, state_name: 'open', owner: user, group: group) }
  86. let!(:ticket2) { create(:ticket, state_name: 'open', owner: user, group: group) }
  87. let(:note) { Faker::Lorem.sentence }
  88. it 'adds note to all selected tickets' do
  89. visit 'ticket/view/my_assigned'
  90. within :active_content do
  91. all('.js-checkbox-field', count: 2).each(&:click)
  92. click '.js-confirm'
  93. find('.js-confirm-step textarea').fill_in with: note
  94. click '.js-submit'
  95. end
  96. await_empty_ajax_queue
  97. expect([
  98. ticket1.articles.last&.body,
  99. ticket2.articles.last&.body
  100. ]).to be_all note
  101. end
  102. end
  103. context 'Setting "ui_table_group_by_show_count"', authenticated_as: :authenticate, db_strategy: :reset do
  104. let!(:ticket1) { create(:ticket, group: Group.find_by(name: 'Users')) }
  105. let!(:ticket2) { create(:ticket, group: Group.find_by(name: 'Users')) }
  106. let!(:ticket3) { create(:ticket, group: Group.find_by(name: 'Users')) }
  107. let!(:ticket4) { create(:ticket, group: Group.find_by(name: 'Users')) }
  108. def authenticate
  109. create :object_manager_attribute_select, name: 'grouptest'
  110. ObjectManager::Attribute.migration_execute
  111. ticket1
  112. ticket2.update(grouptest: 'key_1')
  113. ticket3.update(grouptest: 'key_2')
  114. ticket4.update(grouptest: 'key_1')
  115. Overview.find_by(name: 'Open').update(group_by: 'grouptest')
  116. Setting.set('ui_table_group_by_show_count', true)
  117. true
  118. end
  119. it 'shows correct ticket counts' do
  120. visit 'ticket/view/all_open'
  121. within(:active_content) do
  122. page.find('.js-tableBody td b', text: '(1)')
  123. page.find('.js-tableBody td b', text: 'value_1 (2)')
  124. page.find('.js-tableBody td b', text: 'value_2 (1)')
  125. end
  126. end
  127. end
  128. context 'Customer', authenticated_as: :authenticate do
  129. let(:customer) { create(:customer, :with_org) }
  130. let(:ticket) { create(:ticket, customer: customer) }
  131. def authenticate
  132. ticket
  133. customer
  134. end
  135. it 'does basic view test of tickets' do
  136. visit 'ticket/view/my_tickets'
  137. expect(page).to have_text(ticket.title)
  138. click_on 'My Organization Tickets'
  139. expect(page).to have_text(ticket.title)
  140. end
  141. end
  142. end