sipgate_spec.rb 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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(:agent) { create(:agent, phone: agent_phone) }
  7. let(:customer) { create(:customer, phone: customer_phone) }
  8. let(:sipgate_on) { true }
  9. let(:params) do
  10. {
  11. direction: 'in',
  12. from: customer.phone,
  13. to: agent_phone,
  14. callId: '111',
  15. cause: 'busy',
  16. }
  17. end
  18. let(:first_params) { params.merge(event: 'newCall') }
  19. let(:second_params) { params.merge(event: 'hangup') }
  20. let(:place_call) do
  21. token = Setting.get('sipgate_token')
  22. post "#{Capybara.app_host}/api/v1/sipgate/#{token}/in", params: first_params
  23. post "#{Capybara.app_host}/api/v1/sipgate/#{token}/in", params: second_params
  24. end
  25. def authenticate
  26. Setting.set('sipgate_integration', sipgate_on)
  27. agent
  28. end
  29. context 'when sipgate integration is on' do
  30. it 'shows the phone menu in nav bar' do
  31. within '#navigation .menu' do
  32. expect(page).to have_link('Phone', href: '#cti')
  33. end
  34. end
  35. end
  36. context 'when sipgate integration is not on' do
  37. let(:sipgate_on) { false }
  38. it 'does not show the phone menu in nav bar' do
  39. within '#navigation .menu' do
  40. expect(page).to have_no_link('Phone', href: '#cti')
  41. end
  42. end
  43. end
  44. context 'with incoming call' do
  45. before do
  46. visit 'cti'
  47. place_call
  48. end
  49. it 'increments the call counter notification badge' do
  50. within '[href="#cti"].js-phoneMenuItem' do
  51. counter = find('.counter')
  52. expect(counter).to have_content 1
  53. end
  54. end
  55. end
  56. context 'when incoming call is checked' do
  57. before do
  58. visit 'cti'
  59. place_call
  60. end
  61. it 'clears the call counter notification badge' do
  62. within :active_content do
  63. find('.table-checkbox input.js-check', visible: :all).check allow_label_click: true
  64. end
  65. within '[href="#cti"].js-phoneMenuItem' do
  66. expect(page).to have_no_selector('.counter')
  67. end
  68. end
  69. end
  70. end