cti_spec.rb 6.3 KB

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