integration_cti_test.rb 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. require 'browser_test_helper'
  2. class IntegrationCtiTest < TestCase
  3. setup do
  4. if !ENV['CTI_TOKEN']
  5. raise "ERROR: Need CTI_TOKEN - hint CTI_TOKEN='some_token'"
  6. end
  7. end
  8. # Regression test for #2017
  9. def test_nav_menu_notification_badge_clears
  10. id = rand(99_999_999)
  11. @browser = browser_instance
  12. login(
  13. username: 'master@example.com',
  14. password: 'test',
  15. url: browser_url,
  16. )
  17. click(css: 'a[href="#manage"]')
  18. click(css: 'a[href="#system/integration"]')
  19. click(css: 'a[href="#system/integration/cti"]')
  20. switch(
  21. css: '.content.active .js-switch',
  22. type: 'on'
  23. )
  24. watch_for(
  25. css: 'a[href="#cti"]',
  26. timeout: 4,
  27. )
  28. click(css: 'a[href="#cti"]')
  29. call_counter = @browser.find_elements(css: '.js-phoneMenuItem .counter')
  30. .first&.text.to_i
  31. # simulate cti callbacks
  32. url = URI.join(browser_url, "api/v1/cti/#{ENV['CTI_TOKEN']}")
  33. params = {
  34. direction: 'in',
  35. from: '491715000002',
  36. to: '4930600000000',
  37. callId: "4991155921769858278-#{id}",
  38. cause: 'busy'
  39. }
  40. Net::HTTP.post_form(url, params.merge(event: 'newCall'))
  41. Net::HTTP.post_form(url, params.merge(event: 'hangup'))
  42. watch_for(
  43. css: '.js-phoneMenuItem .counter',
  44. value: (call_counter + 1).to_s,
  45. timeout: 4,
  46. )
  47. check(css: '.content.active .table-checkbox input')
  48. watch_for_disappear(
  49. css: '.js-phoneMenuItem .counter',
  50. timeout: 6,
  51. )
  52. click(css: 'a[href="#manage"]')
  53. click(css: 'a[href="#system/integration"]')
  54. click(css: 'a[href="#system/integration/cti"]')
  55. switch(
  56. css: '.content.active .js-switch',
  57. type: 'off'
  58. )
  59. end
  60. # Regression test for #2018
  61. def test_e164_numbers_displayed_in_prettified_format
  62. id = rand(99_999_999)
  63. @browser = browser_instance
  64. login(
  65. username: 'master@example.com',
  66. password: 'test',
  67. url: browser_url,
  68. )
  69. click(css: 'a[href="#manage"]')
  70. click(css: 'a[href="#system/integration"]')
  71. click(css: 'a[href="#system/integration/cti"]')
  72. switch(
  73. css: '.content.active .js-switch',
  74. type: 'on'
  75. )
  76. watch_for(
  77. css: 'a[href="#cti"]'
  78. )
  79. click(css: 'a[href="#cti"]')
  80. # simulate cti callbacks...
  81. url = URI.join(browser_url, "api/v1/cti/#{ENV['CTI_TOKEN']}")
  82. # ...for private network number
  83. params = {
  84. direction: 'in',
  85. from: '007',
  86. to: '008',
  87. callId: "4991155921769858278-#{id}",
  88. cause: 'busy'
  89. }
  90. Net::HTTP.post_form(url, params.merge(event: 'newCall'))
  91. Net::HTTP.post_form(url, params.merge(event: 'hangup'))
  92. # ...for e164 number
  93. params = {
  94. direction: 'in',
  95. from: '4930609854180',
  96. to: '4930609811111',
  97. callId: "4991155921769858278-#{id.next}",
  98. cause: 'busy'
  99. }
  100. Net::HTTP.post_form(url, params.merge(event: 'newCall'))
  101. Net::HTTP.post_form(url, params.merge(event: 'hangup'))
  102. # view caller log
  103. click(css: 'a[href="#cti"]')
  104. # assertion: private network numbers appear verbatim
  105. watch_for(
  106. css: '.content.active .js-callerLog',
  107. value: '007',
  108. timeout: 3,
  109. )
  110. match(
  111. css: '.content.active .js-callerLog',
  112. value: '008',
  113. )
  114. # assertion: E164 numbers appear prettified
  115. match(
  116. css: '.content.active .js-callerLog',
  117. value: '+49 30 609854180',
  118. )
  119. match(
  120. css: '.content.active .js-callerLog',
  121. value: '+49 30 609811111',
  122. )
  123. end
  124. end