overviews_spec.rb 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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 > Overviews', type: :system do
  5. let(:group) { create(:group) }
  6. let(:owner_one) { create(:agent, groups: [group]) }
  7. let(:owner_two) { create(:agent, groups: [group]) }
  8. let(:owner_three) { create(:agent, groups: [group]) }
  9. let(:customer_one) { create(:customer, organization_id: organization_one.id, groups: [group]) }
  10. let(:customer_two) { create(:customer, organization_id: organization_two.id, groups: [group]) }
  11. let(:customer_three) { create(:customer, organization_id: organization_three.id, groups: [group]) }
  12. let(:organization_one) { create(:organization, name: 'Test Org One') }
  13. let(:organization_two) { create(:organization, name: 'Test Org Two') }
  14. let(:organization_three) { create(:organization, name: 'Test Org Three') }
  15. let!(:ticket_one) do
  16. create(:ticket,
  17. title: 'Test Ticket One',
  18. group: group,
  19. owner_id: owner_one.id,
  20. customer_id: customer_one.id)
  21. end
  22. let!(:ticket_two) do
  23. create(:ticket,
  24. title: 'Test Ticket Two',
  25. group: group,
  26. owner_id: owner_two.id,
  27. customer_id: customer_two.id)
  28. end
  29. let!(:ticket_three) do
  30. create(:ticket,
  31. title: 'Test Ticket Three',
  32. group: group,
  33. owner_id: owner_three.id,
  34. customer_id: customer_three.id)
  35. end
  36. let(:overview) { create(:overview, condition: condition) }
  37. context 'when ajax pagination' do
  38. include_examples 'pagination', model: :overview, klass: Overview, path: 'manage/overviews', sort_by: :prio
  39. end
  40. shared_examples 'previewing the correct ticket for single selected object' do
  41. before do
  42. wait.until { page.has_css?('.js-previewLoader.hide', visible: :all) }
  43. scroll_into_view('.ticket_selector')
  44. end
  45. context "with 'is' operator" do
  46. let(:operator) { 'is' }
  47. it 'shows selected customer ticket' do
  48. within '.js-preview .js-tableBody' do
  49. expect(page).to have_css('tr.item', text: ticket_one.title)
  50. end
  51. end
  52. it 'does not show customer ticket that is not selected' do
  53. within '.js-preview .js-tableBody' do
  54. expect(page).to have_no_selector('tr.item', text: ticket_two.title)
  55. expect(page).to have_no_selector('tr.item', text: ticket_three.title)
  56. end
  57. end
  58. end
  59. context "with 'is not' operator" do
  60. let(:operator) { 'is not' }
  61. it 'does not show selected customer ticket' do
  62. within '.js-preview .js-tableBody' do
  63. expect(page).to have_no_selector('tr.item', text: ticket_one.title)
  64. end
  65. end
  66. it 'does not show customer ticket that is not selected' do
  67. within '.js-preview .js-tableBody' do
  68. expect(page).to have_css('tr.item', text: ticket_two.title)
  69. expect(page).to have_css('tr.item', text: ticket_three.title)
  70. end
  71. end
  72. end
  73. end
  74. shared_examples 'previewing the correct ticket for multiple selected objects' do
  75. before do
  76. wait.until { page.has_css?('.js-previewLoader.hide', visible: :all) }
  77. scroll_into_view('.ticket_selector')
  78. end
  79. context "with 'is' operator" do
  80. let(:operator) { 'is' }
  81. it 'shows selected customer ticket' do
  82. within '.js-preview .js-tableBody' do
  83. expect(page).to have_css('tr.item', text: ticket_one.title)
  84. expect(page).to have_css('tr.item', text: ticket_two.title)
  85. end
  86. end
  87. it 'does not show customer ticket that is not selected' do
  88. within '.js-preview .js-tableBody' do
  89. expect(page).to have_no_selector('tr.item', text: ticket_three.title)
  90. end
  91. end
  92. end
  93. context "with 'is not' operator" do
  94. let(:operator) { 'is not' }
  95. it 'does not show selected customer ticket' do
  96. within '.js-preview .js-tableBody' do
  97. expect(page).to have_no_selector('tr.item', text: ticket_one.title)
  98. expect(page).to have_no_selector('tr.item', text: ticket_two.title)
  99. end
  100. end
  101. it 'does not show customer ticket that is not selected' do
  102. within '.js-preview .js-tableBody' do
  103. expect(page).to have_css('tr.item', text: ticket_three.title)
  104. end
  105. end
  106. end
  107. end
  108. context 'conditions for shown tickets' do
  109. context 'for customer' do
  110. context 'for new overview' do
  111. before do
  112. visit '/#manage/overviews'
  113. click_on 'New Overview'
  114. modal_ready
  115. within '.ticket_selector' do
  116. ticket_select = find('.js-attributeSelector select .js-ticket')
  117. ticket_select.select 'Customer'
  118. select operator, from: 'condition::ticket.customer_id::operator'
  119. select 'specific', from: 'condition::ticket.customer_id::pre_condition'
  120. end
  121. end
  122. context 'when single customer is selected' do
  123. before do
  124. within '.ticket_selector' do
  125. fill_in 'condition::ticket.customer_id::value_completion', with: customer_one.firstname
  126. find("[data-object-id='#{customer_one.id}'].js-object").click
  127. end
  128. end
  129. it_behaves_like 'previewing the correct ticket for single selected object'
  130. end
  131. context 'when multiple customer is selected' do
  132. before do
  133. within '.ticket_selector' do
  134. fill_in 'condition::ticket.customer_id::value_completion', with: customer_one.firstname
  135. find("[data-object-id='#{customer_one.id}'].js-object").click
  136. fill_in 'condition::ticket.customer_id::value_completion', with: customer_two.firstname
  137. find("[data-object-id='#{customer_two.id}'].js-object").click
  138. end
  139. end
  140. it_behaves_like 'previewing the correct ticket for multiple selected objects'
  141. end
  142. end
  143. context 'for existing overview' do
  144. let(:condition) do
  145. { 'ticket.customer_id' => {
  146. operator: operator,
  147. pre_condition: 'specific',
  148. value: condition_value
  149. } }
  150. end
  151. before do
  152. overview
  153. visit '/#manage/overviews'
  154. within '.table-overview .js-tableBody' do
  155. find("tr[data-id='#{overview.id}'] td.table-draggable").click
  156. end
  157. end
  158. context 'when single customer exists' do
  159. let(:condition_value) { customer_one.id }
  160. it_behaves_like 'previewing the correct ticket for single selected object'
  161. end
  162. context 'when multiple customer exists' do
  163. let(:condition_value) { [customer_one.id, customer_two.id] }
  164. it_behaves_like 'previewing the correct ticket for multiple selected objects'
  165. end
  166. end
  167. end
  168. context 'for owner' do
  169. context 'for new overview' do
  170. before do
  171. visit '/#manage/overviews'
  172. click_on 'New Overview'
  173. modal_ready
  174. within '.ticket_selector' do
  175. ticket_select = find('.js-attributeSelector select .js-ticket')
  176. ticket_select.select 'Owner'
  177. select operator, from: 'condition::ticket.owner_id::operator'
  178. select 'specific', from: 'condition::ticket.owner_id::pre_condition'
  179. end
  180. end
  181. context 'when single owner is selected' do
  182. before do
  183. within '.ticket_selector' do
  184. fill_in 'condition::ticket.owner_id::value_completion', with: owner_one.firstname
  185. find("[data-object-id='#{owner_one.id}'].js-object").click
  186. end
  187. end
  188. it_behaves_like 'previewing the correct ticket for single selected object'
  189. end
  190. context 'when multiple owner is selected' do
  191. before do
  192. within '.ticket_selector' do
  193. fill_in 'condition::ticket.owner_id::value_completion', with: owner_one.firstname
  194. find("[data-object-id='#{owner_one.id}'].js-object").click
  195. fill_in 'condition::ticket.owner_id::value_completion', with: owner_two.firstname
  196. find("[data-object-id='#{owner_two.id}'].js-object").click
  197. end
  198. end
  199. it_behaves_like 'previewing the correct ticket for multiple selected objects'
  200. end
  201. end
  202. context 'for existing overview' do
  203. let(:condition) do
  204. { 'ticket.owner_id' => {
  205. operator: operator,
  206. pre_condition: 'specific',
  207. value: condition_value
  208. } }
  209. end
  210. before do
  211. overview
  212. visit '/#manage/overviews'
  213. within '.table-overview .js-tableBody' do
  214. find("tr[data-id='#{overview.id}'] td.table-draggable").click
  215. end
  216. end
  217. context 'when single owner exists' do
  218. let(:condition_value) { owner_one.id }
  219. it_behaves_like 'previewing the correct ticket for single selected object'
  220. end
  221. context 'when multiple owner exists' do
  222. let(:condition_value) { [owner_one.id, owner_two.id] }
  223. it_behaves_like 'previewing the correct ticket for multiple selected objects'
  224. end
  225. end
  226. end
  227. context 'for organization' do
  228. context 'for new overview' do
  229. before do
  230. visit '/#manage/overviews'
  231. click_on 'New Overview'
  232. modal_ready
  233. within '.ticket_selector' do
  234. ticket_select = find('.js-attributeSelector select .js-ticket')
  235. ticket_select.select 'Organization'
  236. select operator, from: 'condition::ticket.organization_id::operator'
  237. select 'specific', from: 'condition::ticket.organization_id::pre_condition'
  238. end
  239. end
  240. context 'when single organization is selected' do
  241. before do
  242. within '.ticket_selector' do
  243. fill_in 'condition::ticket.organization_id::value_completion', with: organization_one.name
  244. find('.js-optionsList span', text: organization_one.name).click
  245. end
  246. end
  247. it_behaves_like 'previewing the correct ticket for single selected object'
  248. end
  249. context 'when multiple organization is selected' do
  250. before do
  251. within '.ticket_selector' do
  252. fill_in 'condition::ticket.organization_id::value_completion', with: organization_one.name
  253. find('.js-optionsList span', text: organization_one.name).click
  254. fill_in 'condition::ticket.organization_id::value_completion', with: organization_two.name
  255. find('.js-optionsList span', text: organization_two.name).click
  256. end
  257. end
  258. it_behaves_like 'previewing the correct ticket for multiple selected objects'
  259. end
  260. end
  261. context 'for existing overview' do
  262. let(:condition) do
  263. { 'ticket.organization_id' => {
  264. operator: operator,
  265. pre_condition: 'specific',
  266. value: condition_value
  267. } }
  268. end
  269. before do
  270. overview
  271. visit '/#manage/overviews'
  272. within '.table-overview .js-tableBody' do
  273. find("tr[data-id='#{overview.id}'] td.table-draggable").click
  274. end
  275. end
  276. context 'when single organization exists' do
  277. let(:condition_value) { organization_one.id }
  278. it_behaves_like 'previewing the correct ticket for single selected object'
  279. end
  280. context 'when multiple organization exists' do
  281. let(:condition_value) { [organization_one.id, organization_two.id] }
  282. it_behaves_like 'previewing the correct ticket for multiple selected objects'
  283. end
  284. end
  285. end
  286. end
  287. # https://github.com/zammad/zammad/issues/4140
  288. context 'checking form validation' do
  289. shared_examples 'showing the error message if roles are empty' do
  290. it 'shows an error message if roles are empty' do
  291. in_modal disappears: false do
  292. wait.until do
  293. page.has_css?('.has-error')
  294. find('.has-error').has_content?('is required')
  295. end
  296. end
  297. end
  298. end
  299. context 'when new overview is created' do
  300. before do
  301. visit '/#manage/overviews'
  302. click_on 'New Overview'
  303. in_modal disappears: false do
  304. fill_in 'name', with: 'dummy'
  305. click_on 'Submit'
  306. end
  307. end
  308. include_examples 'showing the error message if roles are empty'
  309. end
  310. context 'when existing overview is edited' do
  311. let(:overview) { create(:overview, role_ids: [role_id]) }
  312. let(:role_id) { Role.find_by(name: 'Agent').id }
  313. before do
  314. overview
  315. visit '/#manage/overviews'
  316. within '.table-overview .js-tableBody' do
  317. find("tr[data-id='#{overview.id}'] td.table-draggable").click
  318. end
  319. in_modal disappears: false do
  320. # delete the role and wait for the help message to appear
  321. find("div[data-attribute-name='role_ids'] div.js-selected div[data-value='#{role_id}']").click
  322. find("div[data-attribute-name='role_ids'] div.u-placeholder").has_content?('Nothing selected')
  323. click_on 'Submit'
  324. end
  325. end
  326. include_examples 'showing the error message if roles are empty'
  327. end
  328. end
  329. end