overviews_spec.rb 13 KB

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