cti_spec.rb 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Caller log', type: :system, authenticated_as: :agent do
  4. let(:agent_phone) { '0190111' }
  5. let(:customer_phone) { '0190333' }
  6. let(:cti_token) { 'token1234' }
  7. let(:agent) { create(:agent, phone: agent_phone) }
  8. let(:customer) { create(:customer, phone: customer_phone) }
  9. let(:cti_on) { true }
  10. let(:params) do
  11. {
  12. direction: 'in',
  13. from: customer.phone,
  14. to: agent_phone,
  15. callId: '111',
  16. cause: 'busy',
  17. }
  18. end
  19. let(:first_params) { params.merge(event: 'newCall') }
  20. let(:second_params) { params.merge(event: 'hangup') }
  21. let(:place_call) do
  22. post "#{Capybara.app_host}/api/v1/cti/#{cti_token}", params: first_params
  23. post "#{Capybara.app_host}/api/v1/cti/#{cti_token}", params: second_params
  24. end
  25. let(:prepare) do
  26. Setting.set('cti_integration', cti_on)
  27. Setting.set('cti_token', cti_token)
  28. end
  29. before { prepare }
  30. context 'when cti integration is on' do
  31. it 'shows the phone menu in nav bar' do
  32. within '#navigation .menu' do
  33. expect(page).to have_link('Phone', href: '#cti')
  34. end
  35. end
  36. end
  37. context 'when cti integration is not on' do
  38. let(:cti_on) { false }
  39. it 'does not show the phone menu in nav bar' do
  40. within '#navigation .menu' do
  41. expect(page).to have_no_link('Phone', href: '#cti')
  42. end
  43. end
  44. end
  45. context 'when a customer call is answered' do
  46. let(:second_params) { params.merge(event: 'answer', answeringNumber: agent_phone) }
  47. context 'without active tickets' do
  48. before do
  49. travel(-2.months)
  50. create(:ticket, customer: customer)
  51. travel_back
  52. visit 'cti'
  53. place_call
  54. end
  55. it 'opens a new ticket after phone call inbound' do
  56. within(:active_content) do
  57. expect(page).to have_text('New Ticket')
  58. end
  59. end
  60. end
  61. context 'with active tickets' do
  62. before do
  63. create(:ticket, customer: customer)
  64. visit 'cti'
  65. place_call
  66. end
  67. it 'opens the customer profile screen after phone call inbound with tickets in the last month' do
  68. within(:active_content) do
  69. expect(page).to have_text(customer.fullname)
  70. end
  71. end
  72. end
  73. end
  74. context 'with incoming call' do
  75. before do
  76. visit 'cti'
  77. place_call
  78. end
  79. it 'increments the call counter notification badge' do
  80. within '[href="#cti"].js-phoneMenuItem' do
  81. counter = find('.counter')
  82. expect(counter).to have_content 1
  83. end
  84. end
  85. end
  86. context 'when incoming call is checked' do
  87. before do
  88. visit 'cti'
  89. place_call
  90. end
  91. it 'clears the call counter notification badge' do
  92. within :active_content do
  93. find('.table-checkbox input.js-check', visible: :all).check allow_label_click: true
  94. end
  95. within '[href="#cti"].js-phoneMenuItem' do
  96. expect(page).to have_no_selector('.counter')
  97. end
  98. end
  99. end
  100. # Regression test for #2018
  101. context 'phone numbers format' do
  102. before do
  103. visit 'cti'
  104. place_call
  105. end
  106. context 'with private number' do
  107. let(:customer_phone) { '007' }
  108. let(:agent_phone) { '008' }
  109. it 'appears verbatim' do
  110. within :active_content do
  111. expect(page).to have_selector('.js-callerLog', text: customer_phone)
  112. .and have_selector('.js-callerLog', text: agent_phone)
  113. end
  114. end
  115. end
  116. context 'with e164 number' do
  117. let(:customer_phone) { '4930609854180' }
  118. let(:agent_phone) { '4930609811111' }
  119. let(:prettified_customer_phone) { '+49 30 609854180' }
  120. let(:prettified_current_user_phone) { '+49 30 609811111' }
  121. it 'appears prettified' do
  122. within :active_content do
  123. expect(page).to have_selector('.js-callerLog', text: prettified_customer_phone)
  124. .and have_selector('.js-callerLog', text: prettified_current_user_phone)
  125. end
  126. end
  127. it 'done not appear verbatim' do
  128. within :active_content do
  129. expect(page).to have_no_selector('.js-callerLog', text: customer_phone)
  130. end
  131. end
  132. end
  133. end
  134. # Regression test for #2096
  135. context 'with inactive user' do
  136. before do
  137. visit 'cti'
  138. place_call
  139. end
  140. let(:customer) do
  141. create(:customer,
  142. phone: customer_phone,
  143. active: false,
  144. firstname: 'John',
  145. lastname: 'Doe')
  146. end
  147. it 'appears inactive' do
  148. within :active_content do
  149. expect(page).to have_selector('span.avatar--inactive', text: 'JD')
  150. end
  151. end
  152. end
  153. # Regression test for #2075
  154. context 'when user is with organization name' do
  155. before do
  156. visit 'cti'
  157. place_call
  158. end
  159. let(:firstname) { 'John' }
  160. let(:lastname) { 'Doe' }
  161. let(:organization_name) { 'Test Organization' }
  162. let(:organization) { create(:organization, name: organization_name) }
  163. let(:full_name) { "#{firstname} #{lastname}" }
  164. let(:customer) do
  165. create(:customer,
  166. phone: customer_phone,
  167. firstname: firstname,
  168. lastname: lastname,
  169. organization: organization)
  170. end
  171. shared_examples 'showing user with thier organization name' do
  172. it 'shows user with thier organization name' do
  173. within :active_content do
  174. expect(page).to have_selector(
  175. '.js-callerLog tr div.user-popover',
  176. text: "#{full_name} (#{organization_name})"
  177. )
  178. end
  179. end
  180. end
  181. context 'with call direction out' do
  182. let(:first_params) { params.merge(event: 'newCall', direction: 'out', from: agent_phone, to: customer.phone) }
  183. let(:second_params) { params.merge(event: 'hangup', direction: 'out', from: agent_phone, to: customer.phone) }
  184. it_behaves_like 'showing user with thier organization name'
  185. end
  186. context 'with call direction in' do
  187. let(:first_params) { params.merge(event: 'newCall', direction: 'in') }
  188. let(:second_params) { params.merge(event: 'hangup', direction: 'in') }
  189. it_behaves_like 'showing user with thier organization name'
  190. end
  191. end
  192. end