trigger_spec.rb 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. def open_new_trigger_dialog
  6. visit '/#manage/trigger'
  7. click_on 'New Trigger'
  8. end
  9. context 'Selector' do
  10. context 'custom attribute', db_strategy: :reset do
  11. it 'enables selection of multiple values for select attribute' do
  12. attribute = create_attribute :object_manager_attribute_select,
  13. data_option: {
  14. options: {
  15. 'name 1': 'name 1',
  16. 'name 2': 'name 2',
  17. },
  18. default: '',
  19. null: false,
  20. relation: '',
  21. maxlength: 255,
  22. nulloption: true,
  23. }
  24. open_new_trigger_dialog
  25. in_modal do
  26. within '.ticket_selector' do
  27. find('.js-attributeSelector select').select(attribute.display)
  28. expect(find('.js-value select')).to be_multiple
  29. end
  30. end
  31. end
  32. it 'enables selection of multiple values for multiselect attribute' do
  33. attribute = create_attribute :object_manager_attribute_multiselect,
  34. data_option: {
  35. options: {
  36. 'name 1': 'name 1',
  37. 'name 2': 'name 2',
  38. },
  39. default: '',
  40. null: false,
  41. relation: '',
  42. maxlength: 255,
  43. nulloption: true,
  44. }
  45. open_new_trigger_dialog
  46. in_modal do
  47. within '.ticket_selector' do
  48. find('.js-attributeSelector select').select(attribute.display)
  49. expect(find('.js-value select')).to be_multiple
  50. end
  51. end
  52. end
  53. end
  54. it 'sets a customer email address with no @ character' do
  55. open_new_trigger_dialog
  56. in_modal do
  57. find(".js-attributeSelector select option[value='customer.email']").select_option
  58. set_tokens_field_value('{json}condition::customer.email::value', 'zammad.com')
  59. fill_in 'Name', with: 'trigger 1'
  60. click '.js-submit'
  61. end
  62. end
  63. end
  64. context 'Perform' do
  65. context 'Tags' do
  66. it 'shows tag selection list in foreground' do
  67. tag_item = create(:tag_item)
  68. open_new_trigger_dialog
  69. in_modal disappears: false do
  70. within '.ticket_perform_action' do
  71. find('.js-attributeSelector select').select('Tags')
  72. input = find('.js-value .token-input')
  73. input.fill_in with: tag_item.name.slice(0, 3)
  74. end
  75. end
  76. # widget is shown within modal, but placed outside of modal in DOM tree.
  77. expect(page).to have_css('.ui-autocomplete.ui-widget-content') { |elem| !elem.obscured? }
  78. end
  79. end
  80. end
  81. context 'ajax pagination' do
  82. include_examples 'pagination', model: :trigger, klass: Trigger, path: 'manage/trigger'
  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