view_spec.rb 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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_group1) { create :macro, groups: [group1] }
  8. let!(:macro_group2) { create :macro, groups: [group2] }
  9. it 'supports group-dependent macros' do
  10. ticket1 = create :ticket, group: group1
  11. ticket2 = create :ticket, group: group2
  12. # give user access to all groups including those created
  13. # by using FactoryBot outside of the example
  14. group_names_access_map = Group.all.pluck(:name).each_with_object({}) do |group_name, result|
  15. result[group_name] = 'full'.freeze
  16. end
  17. current_user do |user|
  18. user.group_names_access_map = group_names_access_map
  19. user.save!
  20. end
  21. # refresh browser to get macro accessable
  22. refresh
  23. visit '#ticket/view/all_open'
  24. within(:active_content) do
  25. ticket = page.find(:table_row, 1).native
  26. # click and hold first ticket in table
  27. click_and_hold(ticket)
  28. # move ticket to y -ticket.location.y
  29. move_mouse_by(0, -ticket.location.y + 5)
  30. # move a bit to the left to display macro batches
  31. move_mouse_by(-250, 0)
  32. expect(page).to have_selector(:macro_batch, macro_without_group.id, visible: :visible)
  33. expect(page).to have_no_selector(:macro_batch, macro_group1.id)
  34. expect(page).to have_no_selector(:macro_batch, macro_group2.id)
  35. release_mouse
  36. refresh
  37. ticket = page.find(:table_row, ticket1.id).native
  38. # click and hold first ticket in table
  39. click_and_hold(ticket)
  40. # move ticket to y -ticket.location.y
  41. move_mouse_by(0, -ticket.location.y + 5)
  42. # move a bit to the left to display macro batches
  43. move_mouse_by(-250, 0)
  44. expect(page).to have_selector(:macro_batch, macro_without_group.id, visible: :visible)
  45. expect(page).to have_selector(:macro_batch, macro_group1.id)
  46. expect(page).to have_no_selector(:macro_batch, macro_group2.id)
  47. release_mouse
  48. refresh
  49. ticket = page.find(:table_row, ticket2.id).native
  50. # click and hold first ticket in table
  51. click_and_hold(ticket)
  52. # move ticket to y -ticket.location.y
  53. move_mouse_by(0, -ticket.location.y + 5)
  54. # move a bit to the left to display macro batches
  55. move_mouse_by(-250, 0)
  56. expect(page).to have_selector(:macro_batch, macro_without_group.id, visible: :visible)
  57. expect(page).to have_no_selector(:macro_batch, macro_group1.id)
  58. expect(page).to have_selector(:macro_batch, macro_group2.id)
  59. end
  60. end
  61. end
  62. context 'bulk note', authenticated: -> { user } do
  63. let(:group) { create :group }
  64. let(:user) { create :admin, groups: [group] }
  65. let!(:ticket1) { create(:ticket, state_name: 'open', owner: user, group: group) }
  66. let!(:ticket2) { create(:ticket, state_name: 'open', owner: user, group: group) }
  67. let(:note) { Faker::Lorem.sentence }
  68. it 'adds note to all selected tickets' do
  69. visit 'ticket/view/my_assigned'
  70. within :active_content do
  71. all('.js-checkbox-field', count: 2).each(&:click)
  72. click '.js-confirm'
  73. find('.js-confirm-step textarea').fill_in with: note
  74. click '.js-submit'
  75. end
  76. await_empty_ajax_queue
  77. expect([
  78. ticket1.articles.last&.body,
  79. ticket2.articles.last&.body
  80. ]).to be_all note
  81. end
  82. end
  83. end