ticket_spec.rb 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Manage > Settings > Ticket', type: :system do
  4. before { visit 'settings/ticket' }
  5. shared_examples 'switching setting on and off' do |section_name, setting_name|
  6. it "switches #{setting_name} setting on and off" do
  7. within(:active_content) do
  8. click(:href, "##{section_name}")
  9. expect(page).to have_field(setting_name, checked: false, visible: :hidden)
  10. click "label[for=\"#{setting_name}\"]"
  11. expect(page).to have_field(setting_name, checked: true, visible: :hidden)
  12. end
  13. refresh
  14. within(:active_content) do
  15. click(:href, "##{section_name}")
  16. expect(page).to have_field(setting_name, checked: true, visible: :hidden)
  17. click "label[for=\"#{setting_name}\"]"
  18. expect(page).to have_field(setting_name, checked: false, visible: :hidden)
  19. end
  20. end
  21. end
  22. describe 'Auto Assignment' do
  23. it_behaves_like 'switching setting on and off', 'auto_assignment', 'ticket_auto_assignment'
  24. end
  25. describe 'Duplicate Detection' do
  26. it_behaves_like 'switching setting on and off', 'duplicate_detection', 'ticket_duplicate_detection'
  27. end
  28. describe 'default agent notifications' do
  29. it 'check if default agent notifications are set' do
  30. within(:active_content) do
  31. click(:href, '#notification')
  32. default_agent_notifications = Setting.get('ticket_agent_default_notifications')
  33. default_agent_notifications.each do |key, value|
  34. expect(page).to have_field("matrix.#{key}.criteria.owned_by_me", checked: value[:criteria][:owned_by_me], visible: :all)
  35. expect(page).to have_field("matrix.#{key}.criteria.owned_by_nobody", checked: value[:criteria][:owned_by_nobody], visible: :all)
  36. expect(page).to have_field("matrix.#{key}.criteria.subscribed", checked: value[:criteria][:subscribed], visible: :all)
  37. expect(page).to have_field("matrix.#{key}.criteria.no", checked: value[:criteria][:no], visible: :all)
  38. expect(page).to have_field("matrix.#{key}.channel", checked: value[:channel][:email], visible: :all)
  39. end
  40. end
  41. end
  42. it 'updates default agent notifications' do
  43. within(:active_content) do
  44. click(:href, '#notification')
  45. expect(page).to have_field('matrix.escalation.criteria.owned_by_me', checked: true, visible: :all)
  46. find('input[name="matrix.escalation.criteria.owned_by_me"]', visible: :all).click
  47. find('input[name="matrix.escalation.channel"]', visible: :all).click
  48. find('.js-ticketDefaultNotifications').click
  49. await_empty_ajax_queue
  50. expect(Setting.get('ticket_agent_default_notifications')).to include(
  51. escalation: include(
  52. criteria: include(owned_by_me: false),
  53. channel: include(email: false, online: true)
  54. ),
  55. update: include(
  56. criteria: include(owned_by_me: true),
  57. channel: include(email: true, online: true)
  58. )
  59. )
  60. end
  61. end
  62. context 'with already changed default agent notifications setting', authenticated_as: :setup_and_authenticate do
  63. let(:admin) { create(:admin) }
  64. def setup_and_authenticate
  65. Setting.set('ticket_agent_default_notifications', {
  66. create: {
  67. criteria: {
  68. owned_by_me: true,
  69. owned_by_nobody: false,
  70. subscribed: false,
  71. no: false,
  72. },
  73. channel: {
  74. email: true,
  75. online: true,
  76. }
  77. },
  78. update: {
  79. criteria: {
  80. owned_by_me: true,
  81. owned_by_nobody: false,
  82. subscribed: false,
  83. no: false,
  84. },
  85. channel: {
  86. email: true,
  87. online: true,
  88. }
  89. },
  90. reminder_reached: {
  91. criteria: {
  92. owned_by_me: true,
  93. owned_by_nobody: false,
  94. subscribed: false,
  95. no: false,
  96. },
  97. channel: {
  98. email: true,
  99. online: true,
  100. }
  101. },
  102. escalation: {
  103. criteria: {
  104. owned_by_me: true,
  105. owned_by_nobody: false,
  106. subscribed: false,
  107. no: false,
  108. },
  109. channel: {
  110. email: true,
  111. online: true,
  112. }
  113. }
  114. })
  115. admin
  116. end
  117. it 'reset to initial default agent notifications' do
  118. within(:active_content) do
  119. click(:href, '#notification')
  120. current_agent_notifications = Setting.get('ticket_agent_default_notifications')
  121. current_agent_notifications.each do |key, value|
  122. expect(page).to have_field("matrix.#{key}.criteria.owned_by_me", checked: value[:criteria][:owned_by_me], visible: :all)
  123. expect(page).to have_field("matrix.#{key}.criteria.owned_by_nobody", checked: value[:criteria][:owned_by_nobody], visible: :all)
  124. expect(page).to have_field("matrix.#{key}.criteria.subscribed", checked: value[:criteria][:subscribed], visible: :all)
  125. expect(page).to have_field("matrix.#{key}.criteria.no", checked: value[:criteria][:no], visible: :all)
  126. expect(page).to have_field("matrix.#{key}.channel", checked: value[:channel][:email], visible: :all)
  127. end
  128. find('.js-ticketDefaultNotificationsReset').click
  129. in_modal do
  130. click_on 'Yes'
  131. end
  132. await_empty_ajax_queue
  133. reseted_agent_notifications = Setting.find_by(name: 'ticket_agent_default_notifications').state_initial[:value]
  134. reseted_agent_notifications.each do |key, value|
  135. expect(page).to have_field("matrix.#{key}.criteria.owned_by_me", checked: value[:criteria][:owned_by_me], visible: :all)
  136. expect(page).to have_field("matrix.#{key}.criteria.owned_by_nobody", checked: value[:criteria][:owned_by_nobody], visible: :all)
  137. expect(page).to have_field("matrix.#{key}.criteria.subscribed", checked: value[:criteria][:subscribed], visible: :all)
  138. expect(page).to have_field("matrix.#{key}.criteria.no", checked: value[:criteria][:no], visible: :all)
  139. expect(page).to have_field("matrix.#{key}.channel", checked: value[:channel][:email], visible: :all)
  140. end
  141. end
  142. end
  143. end
  144. end
  145. describe 'apply default agent notifications to all agents', performs_jobs: true do
  146. it 'schedules the background job which then closes modal' do
  147. within(:active_content) do
  148. click(:href, '#notification')
  149. click '.js-ticketDefaultNotificationsApplyToAll'
  150. end
  151. in_modal disappears: false do
  152. find('[name="sure"]').fill_in with: 'CONFIRM'
  153. click_on 'Yes'
  154. end
  155. perform_enqueued_jobs only: ResetNotificationsPreferencesJob
  156. expect(page).to have_no_css('.modal')
  157. end
  158. end
  159. end