integration_cti_test.rb 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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(css: 'a[href="#cti"]')
  25. click(css: 'a[href="#cti"]')
  26. call_counter = @browser.find_elements(css: '.js-phoneMenuItem .counter')
  27. .first&.text.to_i
  28. # simulate cti callbacks
  29. url = URI.join(browser_url, "api/v1/cti/#{ENV['CTI_TOKEN']}")
  30. params = {
  31. direction: 'in',
  32. from: '491715000002',
  33. to: '4930600000000',
  34. callId: "4991155921769858278-#{id}",
  35. cause: 'busy'
  36. }
  37. Net::HTTP.post_form(url, params.merge(event: 'newCall'))
  38. Net::HTTP.post_form(url, params.merge(event: 'hangup'))
  39. watch_for(
  40. css: '.js-phoneMenuItem .counter',
  41. value: (call_counter + 1).to_s
  42. )
  43. click(css: '.content.active .table-checkbox label', all: true)
  44. watch_for_disappear(
  45. css: '.js-phoneMenuItem .counter'
  46. )
  47. click(css: 'a[href="#manage"]')
  48. click(css: 'a[href="#system/integration"]')
  49. click(css: 'a[href="#system/integration/cti"]')
  50. switch(
  51. css: '.content.active .js-switch',
  52. type: 'off'
  53. )
  54. end
  55. # Regression test for #2018
  56. def test_e164_numbers_displayed_in_prettified_format
  57. id = rand(99_999_999)
  58. @browser = browser_instance
  59. login(
  60. username: 'master@example.com',
  61. password: 'test',
  62. url: browser_url,
  63. )
  64. click(css: 'a[href="#manage"]')
  65. click(css: 'a[href="#system/integration"]')
  66. click(css: 'a[href="#system/integration/cti"]')
  67. switch(
  68. css: '.content.active .js-switch',
  69. type: 'on'
  70. )
  71. watch_for(
  72. css: 'a[href="#cti"]'
  73. )
  74. click(css: 'a[href="#cti"]')
  75. # simulate cti callbacks...
  76. url = URI.join(browser_url, "api/v1/cti/#{ENV['CTI_TOKEN']}")
  77. # ...for private network number
  78. params = {
  79. direction: 'in',
  80. from: '007',
  81. to: '008',
  82. callId: "4991155921769858278-#{id}",
  83. cause: 'busy'
  84. }
  85. Net::HTTP.post_form(url, params.merge(event: 'newCall'))
  86. Net::HTTP.post_form(url, params.merge(event: 'hangup'))
  87. # ...for e164 number
  88. params = {
  89. direction: 'in',
  90. from: '4930609854180',
  91. to: '4930609811111',
  92. callId: "4991155921769858278-#{id.next}",
  93. cause: 'busy'
  94. }
  95. Net::HTTP.post_form(url, params.merge(event: 'newCall'))
  96. Net::HTTP.post_form(url, params.merge(event: 'hangup'))
  97. # view caller log
  98. click(css: 'a[href="#cti"]')
  99. # assertion: private network numbers appear verbatim
  100. match(
  101. css: '.js-callerLog',
  102. value: '007',
  103. )
  104. match(
  105. css: '.js-callerLog',
  106. value: '008',
  107. )
  108. # assertion: E164 numbers appear prettified
  109. match(
  110. css: '.js-callerLog',
  111. value: '+49 30 609854180',
  112. )
  113. match(
  114. css: '.js-callerLog',
  115. value: '+49 30 609811111',
  116. )
  117. end
  118. end