trigger_spec.rb 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'system/examples/pagination_examples'
  4. RSpec.describe 'Manage > Trigger', mariadb: true, 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. visit '/#manage/trigger'
  56. click '.page-header-meta .btn--success'
  57. in_modal do
  58. find(".js-attributeSelector select option[value='customer.email']").select_option
  59. fill_in 'condition::customer.email::value', with: 'zammad.com'
  60. fill_in 'Name', with: 'trigger 1'
  61. click '.js-submit'
  62. end
  63. end
  64. end
  65. context 'Perform' do
  66. context 'Tags' do
  67. it 'shows tag selection list in foreground' do
  68. tag_item = create(:tag_item)
  69. open_new_trigger_dialog
  70. in_modal disappears: false do
  71. within '.ticket_perform_action' do
  72. find('.js-attributeSelector select').select('Tags')
  73. input = find('.js-value .token-input')
  74. input.fill_in with: tag_item.name.slice(0, 3)
  75. end
  76. end
  77. # widget is shown within modal, but placed outside of modal in DOM tree.
  78. expect(page).to have_css('.ui-autocomplete.ui-widget-content') { |elem| !elem.obscured? }
  79. end
  80. end
  81. end
  82. context 'ajax pagination' do
  83. include_examples 'pagination', model: :trigger, klass: Trigger, path: 'manage/trigger'
  84. end
  85. context "with elements which do not support 'has changed' operator" do
  86. it "check 'created_at' element" do
  87. open_new_trigger_dialog
  88. in_modal do
  89. within '.ticket_selector' do
  90. find(".js-attributeSelector select option[value='ticket.created_at']").select_option
  91. expect(page).to have_no_css('select[name="condition::ticket.created_at::operator"] option[value="has changed"]')
  92. end
  93. end
  94. end
  95. it "check 'updated_at' element" do
  96. open_new_trigger_dialog
  97. in_modal do
  98. within '.ticket_selector' do
  99. find(".js-attributeSelector select option[value='ticket.updated_at']").select_option
  100. expect(page).to have_no_css('select[name="condition::ticket.updated_at::operator"] option[value="has changed"]')
  101. end
  102. end
  103. end
  104. end
  105. context 'when ticket is updated with a multiselect trigger condition', authenticated_as: :owner, db_strategy: :reset do
  106. let(:options) do
  107. {
  108. a: 'a',
  109. b: 'b',
  110. c: 'c',
  111. d: 'd',
  112. e: 'e',
  113. }
  114. end
  115. let(:trigger_values) { %w[a b c] }
  116. let!(:attribute) do
  117. create_attribute :object_manager_attribute_multiselect,
  118. data_option: {
  119. options: options,
  120. default: '',
  121. null: false,
  122. relation: '',
  123. maxlength: 255,
  124. nulloption: true,
  125. },
  126. name: 'multiselect',
  127. screens: attributes_for(:required_screen)
  128. end
  129. let(:group) { create(:group) }
  130. let(:owner) { create(:admin, group_ids: [group.id]) }
  131. let!(:ticket) { create(:ticket, group: group,) }
  132. before do
  133. visit '/#manage/trigger'
  134. click_on 'New Trigger'
  135. in_modal do
  136. fill_in 'Name', with: 'Test Trigger'
  137. within '.ticket_selector' do
  138. find('.js-attributeSelector select').select attribute.display
  139. find('.js-operator select').select operator
  140. trigger_values.each { |value| find('.js-value select').select value }
  141. end
  142. within '.ticket_perform_action' do
  143. find('.js-attributeSelector select').select 'Note'
  144. within '.js-setArticle' do
  145. fill_in 'Subject', with: 'Test subject note'
  146. find('[data-name="perform::article.note::body"]').set 'Test body note'
  147. end
  148. end
  149. click_button
  150. end
  151. visit "#ticket/zoom/#{ticket.id}"
  152. ticket_multiselect_values.each do |value|
  153. within '.sidebar-content .multiselect select' do
  154. select value
  155. end
  156. end
  157. click_button 'Update'
  158. end
  159. shared_examples 'updating the ticket with the trigger condition' do
  160. it 'updates the ticket with the trigger condition' do
  161. wait.until { ticket.multiselect_previously_changed? && ticket.articles.present? }
  162. expect(ticket.articles).not_to be_empty
  163. expect(page).to have_text 'Test body note'
  164. end
  165. end
  166. context "with 'contains all' used" do
  167. let(:operator) { 'contains all' }
  168. context 'when updated value is the same with trigger value' do
  169. let(:ticket_multiselect_values) { trigger_values }
  170. it_behaves_like 'updating the ticket with the trigger condition'
  171. end
  172. context 'when all value is selected' do
  173. let(:ticket_multiselect_values) { options.values }
  174. it_behaves_like 'updating the ticket with the trigger condition'
  175. end
  176. end
  177. context "with 'contains one' used" do
  178. let(:operator) { 'contains one' }
  179. context 'when updated value is the same with trigger value' do
  180. let(:ticket_multiselect_values) { trigger_values }
  181. it_behaves_like 'updating the ticket with the trigger condition'
  182. end
  183. context 'when all value is selected' do
  184. let(:ticket_multiselect_values) { options.values }
  185. it_behaves_like 'updating the ticket with the trigger condition'
  186. end
  187. context 'when updated value contains only one of the trigger value' do
  188. let(:ticket_multiselect_values) { [trigger_values.first] }
  189. it_behaves_like 'updating the ticket with the trigger condition'
  190. end
  191. context 'when updated value does not contain one of the trigger value' do
  192. let(:ticket_multiselect_values) { options.values - [trigger_values.first] }
  193. it_behaves_like 'updating the ticket with the trigger condition'
  194. end
  195. end
  196. context "with 'contains all not' used" do
  197. let(:operator) { 'contains all not' }
  198. context 'when updated value is different from the trigger value' do
  199. let(:ticket_multiselect_values) { options.values - trigger_values }
  200. it_behaves_like 'updating the ticket with the trigger condition'
  201. end
  202. context 'when updated value contains only one of the trigger value' do
  203. let(:ticket_multiselect_values) { [trigger_values.first] }
  204. it_behaves_like 'updating the ticket with the trigger condition'
  205. end
  206. context 'when updated value does not contain one of the trigger value' do
  207. let(:ticket_multiselect_values) { options.values - [trigger_values.first] }
  208. it_behaves_like 'updating the ticket with the trigger condition'
  209. end
  210. end
  211. context "with 'contains one not' used" do
  212. let(:operator) { 'contains one not' }
  213. context 'when updated value is different from the trigger value' do
  214. let(:ticket_multiselect_values) { options.values - trigger_values }
  215. it_behaves_like 'updating the ticket with the trigger condition'
  216. end
  217. end
  218. end
  219. end