trigger_spec.rb 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'system/examples/pagination_examples'
  4. RSpec.describe 'Manage > Trigger', type: :system do
  5. context 'when ajax pagination' do
  6. include_examples 'pagination', model: :trigger, klass: Trigger, path: 'manage/trigger'
  7. end
  8. def open_new_trigger_dialog
  9. visit '/#manage/trigger'
  10. click_on 'New Trigger'
  11. end
  12. context 'Selector' do
  13. context 'custom attribute', db_strategy: :reset do
  14. it 'enables selection of multiple values for select attribute' do
  15. attribute = create_attribute :object_manager_attribute_select,
  16. data_option: {
  17. options: {
  18. 'name 1': 'name 1',
  19. 'name 2': 'name 2',
  20. },
  21. default: '',
  22. null: false,
  23. relation: '',
  24. maxlength: 255,
  25. nulloption: true,
  26. }
  27. open_new_trigger_dialog
  28. in_modal do
  29. within '.ticket_selector' do
  30. find('.js-attributeSelector select').select(attribute.display)
  31. expect(find('.js-value select')).to be_multiple
  32. end
  33. end
  34. end
  35. it 'enables selection of multiple values for multiselect attribute' do
  36. attribute = create_attribute :object_manager_attribute_multiselect,
  37. data_option: {
  38. options: {
  39. 'name 1': 'name 1',
  40. 'name 2': 'name 2',
  41. },
  42. default: '',
  43. null: false,
  44. relation: '',
  45. maxlength: 255,
  46. nulloption: true,
  47. }
  48. open_new_trigger_dialog
  49. in_modal do
  50. within '.ticket_selector' do
  51. find('.js-attributeSelector select').select(attribute.display)
  52. expect(find('.js-value select')).to be_multiple
  53. end
  54. end
  55. end
  56. end
  57. it 'sets a customer email address with no @ character' do
  58. open_new_trigger_dialog
  59. in_modal do
  60. find(".js-attributeSelector select option[value='customer.email']").select_option
  61. set_tokens_field_value('{json}condition::customer.email::value', 'zammad.com')
  62. fill_in 'Name', with: 'trigger 1'
  63. click '.js-submit'
  64. end
  65. end
  66. end
  67. context 'Perform' do
  68. context 'Tags' do
  69. it 'shows tag selection list in foreground' do
  70. tag_item = create(:tag_item)
  71. open_new_trigger_dialog
  72. in_modal disappears: false do
  73. within '.ticket_perform_action' do
  74. find('.js-attributeSelector select').select('Tags')
  75. input = find('.js-value .token-input')
  76. input.fill_in with: tag_item.name.slice(0, 3)
  77. end
  78. end
  79. # widget is shown within modal, but placed outside of modal in DOM tree.
  80. expect(page).to have_css('.ui-autocomplete.ui-widget-content') { |elem| !elem.obscured? }
  81. end
  82. end
  83. end
  84. context "with elements which do not support 'has changed' operator" do
  85. it "check 'created_at' element" do
  86. open_new_trigger_dialog
  87. in_modal do
  88. within '.ticket_selector' do
  89. find(".js-attributeSelector select option[value='ticket.created_at']").select_option
  90. expect(page).to have_no_css('select[name="condition::ticket.created_at::operator"] option[value="has changed"]')
  91. end
  92. end
  93. end
  94. it "check 'updated_at' element" do
  95. open_new_trigger_dialog
  96. in_modal do
  97. within '.ticket_selector' do
  98. find(".js-attributeSelector select option[value='ticket.updated_at']").select_option
  99. expect(page).to have_no_css('select[name="condition::ticket.updated_at::operator"] option[value="has changed"]')
  100. end
  101. end
  102. end
  103. end
  104. context 'when ticket is updated with a multiselect trigger condition', authenticated_as: :owner, db_strategy: :reset do
  105. let(:options) do
  106. {
  107. a: 'a',
  108. b: 'b',
  109. c: 'c',
  110. d: 'd',
  111. e: 'e',
  112. }
  113. end
  114. let(:trigger_values) { %w[a b c] }
  115. let!(:attribute) do
  116. create_attribute :object_manager_attribute_multiselect, :required_screen,
  117. data_option: {
  118. options: options,
  119. default: '',
  120. null: false,
  121. relation: '',
  122. maxlength: 255,
  123. nulloption: true,
  124. },
  125. name: 'multiselect'
  126. end
  127. let(:group) { create(:group) }
  128. let(:owner) { create(:admin, group_ids: [group.id]) }
  129. let!(:ticket) { create(:ticket, group: group,) }
  130. before do
  131. open_new_trigger_dialog
  132. in_modal do
  133. fill_in 'Name', with: 'Test Trigger'
  134. within '.ticket_selector' do
  135. find('.js-attributeSelector select').select attribute.display
  136. find('.js-operator select').select operator
  137. trigger_values.each { |value| find('.js-value select').select value }
  138. end
  139. within '.ticket_perform_action' do
  140. find('.js-attributeSelector select').select 'Note'
  141. within '.js-setArticle' do
  142. fill_in 'Subject', with: 'Test subject note'
  143. find('[data-name="perform::article.note::body"]').set 'Test body note'
  144. end
  145. end
  146. click_on 'Submit'
  147. end
  148. visit "#ticket/zoom/#{ticket.id}"
  149. ticket_multiselect_values.each do |value|
  150. within '.sidebar-content .multiselect select' do
  151. select value
  152. end
  153. end
  154. click_on 'Update'
  155. end
  156. shared_examples 'updating the ticket with the trigger condition' do
  157. it 'updates the ticket with the trigger condition' do
  158. wait.until { ticket.multiselect_previously_changed? && ticket.articles.present? }
  159. expect(ticket.articles).not_to be_empty
  160. expect(page).to have_text 'Test body note'
  161. end
  162. end
  163. context "with 'contains all' used" do
  164. let(:operator) { 'contains all' }
  165. context 'when updated value is the same with trigger value' do
  166. let(:ticket_multiselect_values) { trigger_values }
  167. it_behaves_like 'updating the ticket with the trigger condition'
  168. end
  169. context 'when all value is selected' do
  170. let(:ticket_multiselect_values) { options.values }
  171. it_behaves_like 'updating the ticket with the trigger condition'
  172. end
  173. end
  174. context "with 'contains one' used" do
  175. let(:operator) { 'contains one' }
  176. context 'when updated value is the same with trigger value' do
  177. let(:ticket_multiselect_values) { trigger_values }
  178. it_behaves_like 'updating the ticket with the trigger condition'
  179. end
  180. context 'when all value is selected' do
  181. let(:ticket_multiselect_values) { options.values }
  182. it_behaves_like 'updating the ticket with the trigger condition'
  183. end
  184. context 'when updated value contains only one of the trigger value' do
  185. let(:ticket_multiselect_values) { [trigger_values.first] }
  186. it_behaves_like 'updating the ticket with the trigger condition'
  187. end
  188. context 'when updated value does not contain one of the trigger value' do
  189. let(:ticket_multiselect_values) { options.values - [trigger_values.first] }
  190. it_behaves_like 'updating the ticket with the trigger condition'
  191. end
  192. end
  193. context "with 'contains all not' used" do
  194. let(:operator) { 'contains all not' }
  195. context 'when updated value is different from the trigger value' do
  196. let(:ticket_multiselect_values) { options.values - trigger_values }
  197. it_behaves_like 'updating the ticket with the trigger condition'
  198. end
  199. context 'when updated value contains only one of the trigger value' do
  200. let(:ticket_multiselect_values) { [trigger_values.first] }
  201. it_behaves_like 'updating the ticket with the trigger condition'
  202. end
  203. context 'when updated value does not contain one of the trigger value' do
  204. let(:ticket_multiselect_values) { options.values - [trigger_values.first] }
  205. it_behaves_like 'updating the ticket with the trigger condition'
  206. end
  207. end
  208. context "with 'contains one not' used" do
  209. let(:operator) { 'contains one not' }
  210. context 'when updated value is different from the trigger value' do
  211. let(:ticket_multiselect_values) { options.values - trigger_values }
  212. it_behaves_like 'updating the ticket with the trigger condition'
  213. end
  214. end
  215. end
  216. context 'when switching a trigger to time events' do
  217. shared_examples 'adding reached operator to attribute' do |attribute, operator|
  218. let(:attribute) { attribute }
  219. let(:operator) { operator }
  220. it "adds '#{operator}' operator to '#{attribute}' attribute" do
  221. open_new_trigger_dialog
  222. in_modal do
  223. find_field('activator').select 'Time event'
  224. within '.ticket_selector' do
  225. find('.js-filterElement .js-attributeSelector select').select attribute
  226. find('.js-filterElement .js-operator select').select operator
  227. end
  228. find_field('activator').select 'Action'
  229. within '.ticket_selector' do
  230. expect(find('.js-filterElement .js-operator select')).to have_no_selector('option', text: operator)
  231. end
  232. end
  233. end
  234. end
  235. it_behaves_like 'adding reached operator to attribute', 'Pending till', 'has reached'
  236. it_behaves_like 'adding reached operator to attribute', 'Escalation at', 'has reached'
  237. it_behaves_like 'adding reached operator to attribute', 'Escalation at', 'has reached warning'
  238. it "removes 'action' attribute" do
  239. open_new_trigger_dialog
  240. in_modal do
  241. expect(page).to have_select('activator', selected: 'Action')
  242. within '.ticket_selector' do
  243. find('.js-filterElement .js-attributeSelector select option[value="ticket.action"]').select_option
  244. end
  245. find_field('activator').select 'Time event'
  246. within '.ticket_selector' do
  247. expect(find('.js-filterElement .js-attributeSelector select')).to have_no_selector('option', text: 'Action')
  248. end
  249. end
  250. end
  251. it 'hides execution condition mode control' do
  252. open_new_trigger_dialog
  253. in_modal do
  254. expect(page).to have_select('activator', selected: 'Action')
  255. expect(page).to have_field('execution_condition_mode', visible: :all)
  256. find_field('activator').select 'Time event'
  257. expect(page).to have_no_field('execution_condition_mode')
  258. end
  259. end
  260. end
  261. end