search_spec.rb 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Search', type: :system, authenticated: true, searchindex: true do
  4. let(:users_group) { Group.find_by(name: 'Users') }
  5. let(:ticket_1) { create(:ticket, title: 'Testing Ticket 1', group: users_group) }
  6. let(:ticket_2) { create(:ticket, title: 'Testing Ticket 2', group: users_group) }
  7. let(:note) { 'Test note' }
  8. before do
  9. ticket_1 && ticket_2 && configure_elasticsearch(required: true, rebuild: true)
  10. end
  11. it 'shows default widgets' do
  12. fill_in id: 'global-search', with: '"Welcome"'
  13. click_on 'Show Search Details'
  14. within '#navigation .tasks a[data-key=Search]' do
  15. expect(page).to have_content '"Welcome"'
  16. end
  17. end
  18. context 'with ticket search result' do
  19. before do
  20. fill_in id: 'global-search', with: 'Testing'
  21. click_on 'Show Search Details'
  22. find('[data-tab-content=Ticket]').click
  23. end
  24. context 'checkbox' do
  25. it 'has checkbox for each ticket records' do
  26. within '.detail-search table.table' do
  27. expect(page).to have_xpath(".//td[contains(@class, 'js-checkbox-field')]//input[@type='checkbox']", visible: :all, minimum: 2)
  28. end
  29. end
  30. it 'has select all checkbox' do
  31. within '.detail-search table.table' do
  32. expect(page).to have_xpath(".//th//input[@type='checkbox' and @name='bulk_all']", visible: :all, count: 1)
  33. end
  34. end
  35. it 'shows bulkform when checkbox is checked' do
  36. within '.detail-search table.table' do
  37. find("tr[data-id='#{ticket_1.id}']").check('bulk', allow_label_click: true)
  38. end
  39. expect(page).to have_selector('.bulkAction.no-sidebar')
  40. expect(page).to have_no_selector('.bulkAction.no-sidebar.hide', visible: :all)
  41. end
  42. it 'shows bulkform when all checkbox is checked' do
  43. within '.detail-search table.table' do
  44. find('th.table-checkbox').check('bulk_all', allow_label_click: true)
  45. end
  46. expect(page).to have_selector('.bulkAction.no-sidebar')
  47. expect(page).to have_no_selector('.bulkAction.no-sidebar.hide', visible: :all)
  48. end
  49. it 'hides bulkform when checkbox is unchecked' do
  50. within '.detail-search table.table' do
  51. find('th.table-checkbox').check('bulk_all', allow_label_click: true)
  52. all('.js-tableBody tr.item').each { |row| row.uncheck('bulk', allow_label_click: true) }
  53. end
  54. expect(page).to have_selector('.bulkAction.no-sidebar.hide', visible: :hide)
  55. end
  56. end
  57. context 'with bulkform activated' do
  58. before do
  59. find('th.table-checkbox').check('bulk_all', allow_label_click: true)
  60. end
  61. it 'has group label' do
  62. within '.bulkAction .bulkAction-form' do
  63. expect(page).to have_content 'GROUP'
  64. end
  65. end
  66. it 'has owner label' do
  67. within '.bulkAction .bulkAction-form' do
  68. expect(page).to have_content 'OWNER'
  69. end
  70. end
  71. it 'has state label' do
  72. within '.bulkAction .bulkAction-form' do
  73. expect(page).to have_content 'STATE'
  74. end
  75. end
  76. it 'has priority label' do
  77. within '.bulkAction .bulkAction-form' do
  78. expect(page).to have_content 'PRIORITY'
  79. end
  80. end
  81. end
  82. context 'bulk note' do
  83. it 'adds note to selected ticket' do
  84. within :active_content do
  85. find("tr[data-id='#{ticket_1.id}']").check('bulk', allow_label_click: true)
  86. click '.js-confirm'
  87. find('.js-confirm-step textarea').fill_in with: note
  88. click '.js-submit'
  89. end
  90. expect do
  91. wait.until { ticket_1.articles.last&.body == note }
  92. end.not_to raise_error
  93. end
  94. end
  95. end
  96. context 'Organization members', authenticated_as: :authenticate do
  97. let(:organization) { create(:organization) }
  98. let(:members) { organization.members.order(id: :asc) }
  99. def authenticate
  100. create_list(:customer, 50, organization: organization)
  101. true
  102. end
  103. before do
  104. fill_in id: 'global-search', with: organization.name.to_s
  105. end
  106. it 'shows only first 10 members' do
  107. expect(page).to have_text(organization.name)
  108. popover_on_hover(first('a.nav-tab.organization'))
  109. expect(page).to have_text(members[9].fullname, wait: 30)
  110. expect(page).to have_no_text(members[10].fullname)
  111. end
  112. end
  113. context 'inactive user and organizations' do
  114. before do
  115. create(:organization, name: 'Example Inc.', active: true)
  116. create(:organization, name: 'Example Inactive Inc.', active: false)
  117. create(:customer, firstname: 'Firstname', lastname: 'Active', active: true)
  118. create(:customer, firstname: 'Firstname', lastname: 'Inactive', active: false)
  119. configure_elasticsearch(rebuild: true)
  120. end
  121. it 'check that inactive organizations are marked correctly' do
  122. fill_in id: 'global-search', with: '"Example"'
  123. expect(page).to have_css('.nav-tab--search.organization', minimum: 2)
  124. expect(page).to have_css('.nav-tab--search.organization.is-inactive', count: 1)
  125. end
  126. it 'check that inactive users are marked correctly' do
  127. fill_in id: 'global-search', with: '"Firstname"'
  128. expect(page).to have_css('.nav-tab--search.user', minimum: 2)
  129. expect(page).to have_css('.nav-tab--search.user.is-inactive', count: 1)
  130. end
  131. it 'check that inactive users are also marked in the popover for the quick search result' do
  132. fill_in id: 'global-search', with: '"Firstname"'
  133. popover_on_hover(find('.nav-tab--search.user.is-inactive'))
  134. expect(page).to have_css('.popover-title .is-inactive', count: 1)
  135. end
  136. end
  137. describe 'Search is not triggered/updated if url of search is updated new search item or new search is triggered via global search #3873' do
  138. context 'when search changed via input box' do
  139. before do
  140. visit '#search'
  141. end
  142. it 'does switch search results properly' do
  143. page.find('.js-search').fill_in(with: '"Testing Ticket 1"', fill_options: { clear: :backspace })
  144. expect(page.find('.js-tableBody')).to have_text('Testing Ticket 1')
  145. expect(page.find('.js-tableBody')).to have_no_text('Testing Ticket 2')
  146. expect(current_url).to include('Testing%20Ticket%201')
  147. # switch by global search
  148. page.find('.js-search').fill_in(with: '"Testing Ticket 2"', fill_options: { clear: :backspace })
  149. expect(page.find('.js-tableBody')).to have_text('Testing Ticket 2')
  150. expect(page.find('.js-tableBody')).to have_no_text('Testing Ticket 1')
  151. expect(current_url).to include('Testing%20Ticket%202')
  152. end
  153. end
  154. context 'when search changed via global search' do
  155. before do
  156. fill_in id: 'global-search', with: '"Testing Ticket 1"'
  157. click_on 'Show Search Details'
  158. end
  159. it 'does switch search results properly' do
  160. expect(page.find('.js-tableBody')).to have_text('Testing Ticket 1')
  161. expect(page.find('.js-tableBody')).to have_no_text('Testing Ticket 2')
  162. expect(current_url).to include('Testing%20Ticket%201')
  163. # switch by global search
  164. fill_in id: 'global-search', with: '"Testing Ticket 2"'
  165. click_on 'Show Search Details'
  166. expect(page.find('.js-tableBody')).to have_text('Testing Ticket 2')
  167. expect(page.find('.js-tableBody')).to have_no_text('Testing Ticket 1')
  168. expect(current_url).to include('Testing%20Ticket%202')
  169. end
  170. end
  171. context 'when search is changed via url' do
  172. before do
  173. visit '#search/"Testing Ticket 1"'
  174. end
  175. it 'does switch search results properly' do
  176. expect(page.find('.js-tableBody')).to have_text('Testing Ticket 1')
  177. expect(page.find('.js-tableBody')).to have_no_text('Testing Ticket 2')
  178. expect(current_url).to include('Testing%20Ticket%201')
  179. # switch by url
  180. visit '#search/"Testing Ticket 2"'
  181. expect(page.find('.js-tableBody')).to have_text('Testing Ticket 2')
  182. expect(page.find('.js-tableBody')).to have_no_text('Testing Ticket 1')
  183. expect(current_url).to include('Testing%20Ticket%202')
  184. end
  185. end
  186. end
  187. end