sipgate_spec.rb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Caller log', authenticated_as: :authenticate, type: :system 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. visit '/'
  32. within '#navigation .menu' do
  33. expect(page).to have_link('Phone', href: '#cti')
  34. end
  35. end
  36. end
  37. context 'when sipgate integration is not on' do
  38. let(:sipgate_on) { false }
  39. it 'does not show the phone menu in nav bar' do
  40. visit '/'
  41. within '#navigation .menu' do
  42. expect(page).to have_no_link('Phone', href: '#cti')
  43. end
  44. end
  45. end
  46. context 'with incoming call' do
  47. before do
  48. visit 'cti'
  49. place_call
  50. end
  51. it 'increments the call counter notification badge' do
  52. within '[href="#cti"].js-phoneMenuItem' do
  53. counter = find('.counter')
  54. expect(counter).to have_content 1
  55. end
  56. end
  57. end
  58. context 'when incoming call is checked' do
  59. before do
  60. visit 'cti'
  61. place_call
  62. end
  63. it 'clears the call counter notification badge' do
  64. within :active_content do
  65. find('.table-checkbox input.js-check', visible: :all).check allow_label_click: true
  66. end
  67. within '[href="#cti"].js-phoneMenuItem' do
  68. expect(page).to have_no_selector('.counter')
  69. end
  70. end
  71. end
  72. end