trigger_spec.rb 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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, :required_screen,
  118. data_option: {
  119. options: options,
  120. default: '',
  121. null: false,
  122. relation: '',
  123. maxlength: 255,
  124. nulloption: true,
  125. },
  126. name: 'multiselect'
  127. end
  128. let(:group) { create(:group) }
  129. let(:owner) { create(:admin, group_ids: [group.id]) }
  130. let!(:ticket) { create(:ticket, group: group,) }
  131. before do
  132. visit '/#manage/trigger'
  133. click_on 'New Trigger'
  134. in_modal do
  135. fill_in 'Name', with: 'Test Trigger'
  136. within '.ticket_selector' do
  137. find('.js-attributeSelector select').select attribute.display
  138. find('.js-operator select').select operator
  139. trigger_values.each { |value| find('.js-value select').select value }
  140. end
  141. within '.ticket_perform_action' do
  142. find('.js-attributeSelector select').select 'Note'
  143. within '.js-setArticle' do
  144. fill_in 'Subject', with: 'Test subject note'
  145. find('[data-name="perform::article.note::body"]').set 'Test body note'
  146. end
  147. end
  148. click_button
  149. end
  150. visit "#ticket/zoom/#{ticket.id}"
  151. ticket_multiselect_values.each do |value|
  152. within '.sidebar-content .multiselect select' do
  153. select value
  154. end
  155. end
  156. click_button 'Update'
  157. end
  158. shared_examples 'updating the ticket with the trigger condition' do
  159. it 'updates the ticket with the trigger condition' do
  160. wait.until { ticket.multiselect_previously_changed? && ticket.articles.present? }
  161. expect(ticket.articles).not_to be_empty
  162. expect(page).to have_text 'Test body note'
  163. end
  164. end
  165. context "with 'contains all' used" do
  166. let(:operator) { 'contains all' }
  167. context 'when updated value is the same with trigger value' do
  168. let(:ticket_multiselect_values) { trigger_values }
  169. it_behaves_like 'updating the ticket with the trigger condition'
  170. end
  171. context 'when all value is selected' do
  172. let(:ticket_multiselect_values) { options.values }
  173. it_behaves_like 'updating the ticket with the trigger condition'
  174. end
  175. end
  176. context "with 'contains one' used" do
  177. let(:operator) { 'contains one' }
  178. context 'when updated value is the same with trigger value' do
  179. let(:ticket_multiselect_values) { trigger_values }
  180. it_behaves_like 'updating the ticket with the trigger condition'
  181. end
  182. context 'when all value is selected' do
  183. let(:ticket_multiselect_values) { options.values }
  184. it_behaves_like 'updating the ticket with the trigger condition'
  185. end
  186. context 'when updated value contains only one of the trigger value' do
  187. let(:ticket_multiselect_values) { [trigger_values.first] }
  188. it_behaves_like 'updating the ticket with the trigger condition'
  189. end
  190. context 'when updated value does not contain one of the trigger value' do
  191. let(:ticket_multiselect_values) { options.values - [trigger_values.first] }
  192. it_behaves_like 'updating the ticket with the trigger condition'
  193. end
  194. end
  195. context "with 'contains all not' used" do
  196. let(:operator) { 'contains all not' }
  197. context 'when updated value is different from the trigger value' do
  198. let(:ticket_multiselect_values) { options.values - trigger_values }
  199. it_behaves_like 'updating the ticket with the trigger condition'
  200. end
  201. context 'when updated value contains only one of the trigger value' do
  202. let(:ticket_multiselect_values) { [trigger_values.first] }
  203. it_behaves_like 'updating the ticket with the trigger condition'
  204. end
  205. context 'when updated value does not contain one of the trigger value' do
  206. let(:ticket_multiselect_values) { options.values - [trigger_values.first] }
  207. it_behaves_like 'updating the ticket with the trigger condition'
  208. end
  209. end
  210. context "with 'contains one not' used" do
  211. let(:operator) { 'contains one not' }
  212. context 'when updated value is different from the trigger value' do
  213. let(:ticket_multiselect_values) { options.values - trigger_values }
  214. it_behaves_like 'updating the ticket with the trigger condition'
  215. end
  216. end
  217. end
  218. end