overview_spec.rb 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Overview', type: :system do
  4. context 'when logged in as customer', authenticated_as: :customer do
  5. let!(:customer) { create(:customer) }
  6. let!(:main_overview) { create(:overview) }
  7. let!(:other_overview) do
  8. create(:overview, condition: {
  9. 'ticket.state_id' => {
  10. operator: 'is',
  11. value: Ticket::State.where(name: %w[merged]).pluck(:id),
  12. },
  13. })
  14. end
  15. it 'shows create button when customer has no tickets' do
  16. visit "ticket/view/#{main_overview.link}"
  17. within :active_content do
  18. expect(page).to have_text 'Create your first ticket'
  19. end
  20. end
  21. def authenticate
  22. Setting.set('customer_ticket_create', false)
  23. customer
  24. end
  25. it 'does not show create button when ticket creation via web is disabled', authenticated_as: :authenticate do
  26. visit "ticket/view/#{main_overview.link}"
  27. within :active_content do
  28. expect(page).to have_text 'You currently don\'t have any tickets.'
  29. end
  30. end
  31. it 'shows overview-specific message if customer has tickets in other overview', performs_jobs: true do
  32. perform_enqueued_jobs only: TicketUserTicketCounterJob do
  33. create(:ticket, customer: customer)
  34. end
  35. visit "ticket/view/#{other_overview.link}"
  36. within :active_content do
  37. expect(page).to have_text 'You have no tickets'
  38. end
  39. end
  40. it 'replaces button with overview-specific message when customer creates a ticket', performs_jobs: true do
  41. visit "ticket/view/#{other_overview.link}"
  42. visit 'customer_ticket_new'
  43. find('[name=title]').fill_in with: 'Title'
  44. find(:richtext).send_keys 'content'
  45. find('[name=group_id]').select Group.first.name
  46. click '.js-submit'
  47. perform_enqueued_jobs only: TicketUserTicketCounterJob
  48. visit "ticket/view/#{other_overview.link}"
  49. within :active_content do
  50. expect(page).to have_text 'You have no tickets'
  51. end
  52. end
  53. end
  54. context 'sorting when group by is set', authenticated_as: :user do
  55. let(:user) { create(:agent, groups: [group_c, group_a, group_b]) }
  56. let(:group_a) { create(:group, name: 'aaa') }
  57. let(:group_b) { create(:group, name: 'bbb') }
  58. let(:group_c) { create(:group, name: 'ccc') }
  59. let(:ticket1) { create(:ticket, group: group_a, priority_id: 1, customer: user) }
  60. let(:ticket2) { create(:ticket, group: group_c, priority_id: 2, customer: user) }
  61. let(:ticket3) { create(:ticket, group: group_b, priority_id: 3, customer: user) }
  62. let(:overview) do
  63. create(:overview, group_by: group_key, group_direction: group_direction, condition: {
  64. 'ticket.customer_id' => {
  65. operator: 'is',
  66. value: user.id
  67. }
  68. })
  69. end
  70. before do
  71. ticket1 && ticket2 && ticket3
  72. visit "ticket/view/#{overview.link}"
  73. end
  74. context 'when grouping by priority' do
  75. let(:group_key) { 'priority' }
  76. context 'when group direction is default' do
  77. let(:group_direction) { nil }
  78. it 'sorts groups 1 > 3' do
  79. within :active_content do
  80. expect(all('.table-overview table b').map(&:text)).to eq ['1 low', '2 normal', '3 high']
  81. end
  82. end
  83. it 'does not show duplicates when any ticket attribute is updated using bulk update' do
  84. find("tr[data-id='#{ticket3.id}']").check('bulk', allow_label_click: true)
  85. select '2 normal', from: 'priority_id'
  86. click '.js-confirm'
  87. find('.js-confirm-step textarea').fill_in with: 'test tickets ordering'
  88. click '.js-submit'
  89. within :active_content do
  90. expect(page).to have_css("tr[data-id='#{ticket3.id}']", count: 1)
  91. end
  92. end
  93. end
  94. context 'when group direction is ASC' do
  95. let(:group_direction) { 'ASC' }
  96. it 'sorts groups 1 > 3' do
  97. within :active_content do
  98. expect(all('.table-overview table b').map(&:text)).to eq ['1 low', '2 normal', '3 high']
  99. end
  100. end
  101. end
  102. context 'when group direction is DESC' do
  103. let(:group_direction) { 'DESC' }
  104. it 'sorts groups 3 > 1' do
  105. within :active_content do
  106. expect(all('.table-overview table b').map(&:text)).to eq ['3 high', '2 normal', '1 low']
  107. end
  108. end
  109. end
  110. end
  111. context 'when grouping by groups' do
  112. let(:group_key) { 'group' }
  113. let(:group_direction) { 'ASC' }
  114. it 'sorts groups a > b > c' do
  115. within :active_content do
  116. expect(all('.table-overview table b').map(&:text)).to eq %w[aaa bbb ccc]
  117. end
  118. end
  119. end
  120. context 'when grouping by tree_selects', authenticated_as: :authenticate, db_strategy: :reset do
  121. def authenticate
  122. create(:object_manager_attribute_tree_select, name: 'tree_select_field', display: 'Tree Select Field', data_option: data_option)
  123. ObjectManager::Attribute.migration_execute
  124. user
  125. end
  126. let(:data_option) do
  127. {
  128. 'options' => [
  129. {
  130. 'name' => 'a',
  131. 'value' => 'a',
  132. 'children' => [
  133. {
  134. 'name' => '1',
  135. 'value' => 'a::1',
  136. }
  137. ]
  138. },
  139. {
  140. 'name' => 'b',
  141. 'value' => 'b',
  142. 'children' => [
  143. {
  144. 'name' => '1',
  145. 'value' => 'b::1',
  146. },
  147. {
  148. 'name' => '2',
  149. 'value' => 'b::2',
  150. }
  151. ]
  152. },
  153. {
  154. 'name' => 'c',
  155. 'value' => 'c',
  156. 'children' => [
  157. {
  158. 'name' => '1',
  159. 'value' => 'c::1',
  160. },
  161. {
  162. 'name' => '2',
  163. 'value' => 'c::2',
  164. },
  165. {
  166. 'name' => '3',
  167. 'value' => 'c::3',
  168. },
  169. ]
  170. },
  171. ],
  172. 'default' => '',
  173. 'null' => true,
  174. 'relation' => '',
  175. 'maxlength' => 255,
  176. 'nulloption' => true,
  177. }
  178. end
  179. let(:ticket1) { create(:ticket, group: group_a, priority_id: 1, customer: user, tree_select_field: 'a::1') }
  180. let(:ticket2) { create(:ticket, group: group_c, priority_id: 2, customer: user, tree_select_field: 'b::2') }
  181. let(:ticket3) { create(:ticket, group: group_b, priority_id: 3, customer: user, tree_select_field: 'c::3') }
  182. let(:group_key) { 'tree_select_field' }
  183. context 'when group direction is default' do
  184. let(:group_direction) { nil }
  185. it 'sorts groups a::1 > b::2 > c::3' do
  186. within :active_content do
  187. expect(all('.table-overview table b').map(&:text)).to eq %w[a::1 b::2 c::3]
  188. end
  189. end
  190. end
  191. context 'when group direction is ASC' do
  192. let(:group_direction) { 'ASC' }
  193. it 'sorts groups a::1 > b::2 > c::3' do
  194. within :active_content do
  195. expect(all('.table-overview table b').map(&:text)).to eq %w[a::1 b::2 c::3]
  196. end
  197. end
  198. end
  199. context 'when group direction is DESC' do
  200. let(:group_direction) { 'DESC' }
  201. it 'sorts groups c::3 > b::2 > a::1' do
  202. within :active_content do
  203. expect(all('.table-overview table b').map(&:text)).to eq %w[c::3 b::2 a::1]
  204. end
  205. end
  206. end
  207. end
  208. end
  209. context 'when multiselect is choosen as column', authenticated_as: :authenticate, db_strategy: :reset, mariadb: true do
  210. def authenticate
  211. create :object_manager_attribute_multiselect, data_option: data_option, name: attribute_name
  212. ObjectManager::Attribute.migration_execute
  213. user
  214. end
  215. let(:user) { create(:agent, groups: [group]) }
  216. let(:attribute_name) { 'multiselect' }
  217. let(:options_hash) do
  218. {
  219. 'key_1' => 'display_value_1',
  220. 'key_2' => 'display_value_2',
  221. 'key_3' => 'display_value_3',
  222. 'key_4' => 'display_value_4',
  223. 'key_5' => 'display_value_5'
  224. }
  225. end
  226. let(:data_option) { { options: options_hash, default: '' } }
  227. let(:group) { create(:group, name: 'aaa') }
  228. let(:ticket) { create(:ticket, group: group, customer: user, multiselect: multiselect_value) }
  229. let(:view) { { 's'=>%w[number title multiselect] } }
  230. let(:condition) do
  231. {
  232. 'ticket.customer_id' => {
  233. operator: 'is',
  234. value: user.id
  235. }
  236. }
  237. end
  238. let(:overview) { create(:overview, condition: condition, view: view) }
  239. let(:overview_table_selector) { '.table-overview .js-tableBody' }
  240. before do
  241. ticket
  242. visit "ticket/view/#{overview.link}"
  243. end
  244. context 'with nil multiselect value' do
  245. let(:multiselect_value) { nil }
  246. let(:expected_text) { '-' }
  247. it "shows dash '-' for tickets" do
  248. within :active_content, overview_table_selector do
  249. expect(page).to have_selector 'tr.item td', text: expected_text
  250. end
  251. end
  252. end
  253. context 'with a single multiselect value' do
  254. let(:multiselect_value) { ['key_4'] }
  255. let(:expected_text) { 'display_value_4' }
  256. it 'shows the display value for tickets' do
  257. within :active_content, overview_table_selector do
  258. expect(page).to have_selector 'tr.item td', text: expected_text
  259. end
  260. end
  261. end
  262. context 'with multiple multiselect values' do
  263. let(:multiselect_value) { %w[key_2 key_3 key_5] }
  264. let(:expected_text) { 'display_value_2, display_value_3, display_value_5' }
  265. it 'shows comma seperated diaplay value for tickets' do
  266. within :active_content, overview_table_selector do
  267. expect(page).to have_selector 'tr.item td', text: expected_text
  268. end
  269. end
  270. end
  271. end
  272. context 'when only one attribute is visible', authenticated_as: :user do
  273. let(:user) { create(:agent, groups: [group]) }
  274. let(:group) { create(:group, name: 'aaa') }
  275. let(:ticket) { create(:ticket, group: group, customer: user) }
  276. let(:view) { { 's' => %w[title] } }
  277. let(:condition) do
  278. {
  279. 'ticket.customer_id' => {
  280. operator: 'is',
  281. value: user.id
  282. }
  283. }
  284. end
  285. let(:overview) { create(:overview, condition: condition, view: view) }
  286. let(:overview_table_head_selector) { 'div.table-overview table.table thead' }
  287. let(:expected_header_text) { 'TITLE' }
  288. before do
  289. ticket
  290. visit "ticket/view/#{overview.link}"
  291. end
  292. it 'shows only the title column' do
  293. within :active_content, overview_table_head_selector do
  294. expect(page).to have_css('th.js-tableHead[data-column-key="title"]', text: expected_header_text)
  295. end
  296. end
  297. end
  298. end